Use server features for account muc service

issue #878
This commit is contained in:
James Booth
2016-11-20 02:09:34 +00:00
parent 44979ac754
commit 609d05366c
14 changed files with 133 additions and 112 deletions

View File

@@ -360,6 +360,7 @@ cmd_ac_init(void)
autocomplete_add(account_clear_ac, "pgpkeyid");
autocomplete_add(account_clear_ac, "startscript");
autocomplete_add(account_clear_ac, "theme");
autocomplete_add(account_clear_ac, "muc");
account_default_ac = autocomplete_new();
autocomplete_add(account_default_ac, "set");

View File

@@ -1989,7 +1989,8 @@ static struct cmd_t command_defs[] =
"/account clear <account> port",
"/account clear <account> otr",
"/account clear <account> pgpkeyid",
"/account clear <account> startscript")
"/account clear <account> startscript",
"/account clean <account> muc")
CMD_DESC(
"Commands for creating and managing accounts. "
"Calling with no arguments will display information for the current account.")
@@ -2012,7 +2013,7 @@ static struct cmd_t command_defs[] =
{ "set <account> resource <resource>", "The resource to be used for this account, defaults to 'profanity'." },
{ "set <account> password <password>", "Password for the account, note this is currently stored in plaintext if set." },
{ "set <account> eval_password <command>", "Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring." },
{ "set <account> muc <service>", "The default MUC chat service to use, defaults to 'conference.<domainpart>' where the domain part is from the account JID." },
{ "set <account> muc <service>", "The default MUC chat service to use, defaults to the servers disco info response." },
{ "set <account> nick <nick>", "The default nickname to use when joining chat rooms." },
{ "set <account> otr <policy>", "Override global OTR policy for this account, see /otr." },
{ "set <account> pgpkeyid <pgpkeyid>", "Set the ID of the PGP key for this account, see /pgp." },
@@ -2028,7 +2029,8 @@ static struct cmd_t command_defs[] =
{ "clear <account> otr", "Remove the OTR policy setting for this account." },
{ "clear <account> pgpkeyid", "Remove pgpkeyid associated with this account." },
{ "clear <account> startscript", "Remove startscript associated with this account." },
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." })
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." },
{ "clear <account> muc", "Remove the default MUC service setting."})
CMD_EXAMPLES(
"/account add me",
"/account set me jid me@chatty",

View File

@@ -959,6 +959,10 @@ cmd_account_clear(ProfWin *window, const char *const command, gchar **args)
accounts_clear_theme(account_name);
cons_show("Removed theme for account %s", account_name);
cons_show("");
} else if (strcmp(property, "muc") == 0) {
accounts_clear_muc(account_name);
cons_show("Removed MUC service for account %s", account_name);
cons_show("");
} else {
cons_show("Invalid property: %s", property);
cons_show("");
@@ -3426,17 +3430,20 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
if (args[0] == NULL) {
char *account_name = session_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
if (account->muc_service) {
GString *room_str = g_string_new("");
char *uuid = connection_create_uuid();
g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service);
connection_free_uuid(uuid);
GString *room_str = g_string_new("");
char *uuid = connection_create_uuid();
g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service);
connection_free_uuid(uuid);
presence_join_room(room_str->str, account->muc_nick, NULL);
muc_join(room_str->str, account->muc_nick, NULL, FALSE);
presence_join_room(room_str->str, account->muc_nick, NULL);
muc_join(room_str->str, account->muc_nick, NULL, FALSE);
g_string_free(room_str, TRUE);
account_free(account);
g_string_free(room_str, TRUE);
account_free(account);
} else {
cons_show("Account MUC service property not found.");
}
return TRUE;
}
@@ -3451,7 +3458,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
char *room = NULL;
char *nick = NULL;
char *passwd = NULL;
GString *room_str = g_string_new("");
char *account_name = session_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
@@ -3460,11 +3466,18 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
room = args[0];
// server not supplied (room), use account preference
} else {
} else if (account->muc_service) {
GString *room_str = g_string_new("");
g_string_append(room_str, args[0]);
g_string_append(room_str, "@");
g_string_append(room_str, account->muc_service);
room = room_str->str;
g_string_free(room_str, FALSE);
// no account preference
} else {
cons_show("Account MUC service property not found.");
return TRUE;
}
// Additional args supplied
@@ -3502,7 +3515,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
}
jid_destroy(room_arg);
g_string_free(room_str, TRUE);
account_free(account);
return TRUE;
@@ -4307,14 +4319,19 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
if (args[0] == NULL) {
ProfAccount *account = accounts_get_account(session_get_account_name());
iq_room_list_request(account->muc_service);
account_free(account);
} else {
if (args[0]) {
iq_room_list_request(args[0]);
return TRUE;
}
ProfAccount *account = accounts_get_account(session_get_account_name());
if (account->muc_service) {
iq_room_list_request(account->muc_service);
} else {
cons_show("Account MUC service property not found.");
}
account_free(account);
return TRUE;
}