1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Guess conference server if not supplied when joining room (/join)

"@conference.<domain-part>" will be appended to the /join argument where
<domain-part> is the domainpart of the users jid. E.g. the user
"user@server.org" typing "/join chatroom" is equivalent to "/join
chatroom@conference.server.org"
This commit is contained in:
James Booth 2013-04-10 22:47:01 +01:00
parent f4041f049c
commit 202bc6b427

View File

@ -324,16 +324,18 @@ static struct cmd_t main_commands[] =
{ "/join", { "/join",
_cmd_join, parse_args_with_freetext, 1, 2, _cmd_join, parse_args_with_freetext, 1, 2,
{ "/join room [nick]", "Join a chat room.", { "/join room[@server] [nick]", "Join a chat room.",
{ "/join room [nick]", { "/join room[@server] [nick]",
"-----------------", "--------------------------",
"Join a chat room at the conference server.", "Join a chat room at the conference server.",
"If nick is specified you will join with this nickname.", "If nick is specified you will join with this nickname.",
"Otherwise the 'localpart' of your JID (before the @) will be used.", "Otherwise the 'localpart' of your JID (before the @) will be used.",
"If no server is supplied, it will default to 'conference.<domain-part>'",
"If the room doesn't exist, and the server allows it, a new one will be created.", "If the room doesn't exist, and the server allows it, a new one will be created.",
"", "",
"Example : /join jdev@conference.jabber.org", "Example : /join jdev@conference.jabber.org",
"Example : /join jdev@conference.jabber.org mynick", "Example : /join jdev@conference.jabber.org mynick",
"Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)",
NULL } } }, NULL } } },
{ "/rooms", { "/rooms",
@ -2078,16 +2080,32 @@ _cmd_join(gchar **args, struct cmd_help_t help)
return TRUE; return TRUE;
} }
char *room = args[0];
char *nick = NULL;
int num_args = g_strv_length(args); int num_args = g_strv_length(args);
char *room = NULL;
char *nick = NULL;
Jid *room_arg = jid_create(args[0]);
GString *room_str = g_string_new("");
Jid *my_jid = jid_create(jabber_get_jid());
// full room jid supplied (room@server)
if (room_arg->localpart != NULL) {
room = args[0];
// server not supplied (room), guess conference.<users-domain-part>
} else {
g_string_append(room_str, args[0]);
g_string_append(room_str, "@conference.");
g_string_append(room_str, strdup(my_jid->domainpart));
room = room_str->str;
}
// nick supplied
if (num_args == 2) { if (num_args == 2) {
nick = args[1]; nick = args[1];
// use localpart for nick
} else { } else {
Jid *jid = jid_create(jabber_get_jid()); nick = my_jid->localpart;
nick = strdup(jid->localpart);
jid_destroy(jid);
} }
Jid *room_jid = jid_create_from_bare_and_resource(room, nick); Jid *room_jid = jid_create_from_bare_and_resource(room, nick);
@ -2097,6 +2115,10 @@ _cmd_join(gchar **args, struct cmd_help_t help)
} }
win_join_chat(room_jid); win_join_chat(room_jid);
jid_destroy(room_jid);
jid_destroy(my_jid);
g_string_free(room_str, TRUE);
return TRUE; return TRUE;
} }