1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Autogenerate room name with UUID for /join with no args

This commit is contained in:
James Booth 2015-04-11 23:37:52 +01:00
parent f18759192c
commit a2ccd89646
7 changed files with 32 additions and 28 deletions

View File

@ -146,6 +146,9 @@ AS_IF([test "x$PLATFORM" != xosx],
AC_SUBST(AM_LDFLAGS)], AC_SUBST(AM_LDFLAGS)],
[AC_MSG_ERROR([libreadline is required for profanity])])]) [AC_MSG_ERROR([libreadline is required for profanity])])])
AC_CHECK_LIB([uuid], [uuid_generate], [],
[AC_MSG_ERROR([libuuid is required for profanity])])
AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"])
### Check for desktop notification support ### Check for desktop notification support

View File

@ -321,20 +321,21 @@ static struct cmd_t command_defs[] =
NULL } } }, NULL } } },
{ "/join", { "/join",
cmd_join, parse_args, 1, 5, NULL, cmd_join, parse_args, 0, 5, NULL,
{ "/join room[@server] [nick value] [password value]", "Join a chat room.", { "/join [room] [nick value] [password value]", "Join a chat room.",
{ "/join room[@server] [nick value] [password value]", { "/join [room] [nick value] [password value]",
"-------------------------------------------------", "-----------------------------------------",
"Join a chat room at the conference server.", "Join a chat room at the conference server.",
"", "",
"room : Bare room JID, the chat server is determined by the 'muc.service' account property, 'conference.<domainpart>' by default.", "room : Bare room JID (the chat server is determined by the 'muc.service' account property) or full room jid."
"room@server : Full room JID.",
"nick value : Nickname to use in the room", "nick value : Nickname to use in the room",
"password value : Password if the room requires it.", "password value : Password if the room requires it.",
"", "",
"If no room is supplied, a generated name will be used with the format private-chat-[UUID].",
"If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID.", "If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID.",
"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",
"Example: /join jdev@conference.jabber.org", "Example: /join jdev@conference.jabber.org",
"Example: /join jdev@conference.jabber.org nick mynick", "Example: /join jdev@conference.jabber.org nick mynick",
"Example: /join private@conference.jabber.org nick mynick password mypassword", "Example: /join private@conference.jabber.org nick mynick password mypassword",

View File

@ -38,6 +38,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <uuid/uuid.h>
#include <glib.h> #include <glib.h>
#include "chat_session.h" #include "chat_session.h"
@ -2070,8 +2071,24 @@ cmd_join(gchar **args, struct cmd_help_t help)
} }
if (args[0] == NULL) { if (args[0] == NULL) {
cons_show("Usage: %s", help.usage); uuid_t uuid;
cons_show(""); uuid_generate(uuid);
char *uuid_str = malloc(sizeof(char) * 37);
uuid_unparse_lower(uuid, uuid_str);
char *account_name = jabber_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
GString *room_str = g_string_new("");
g_string_append_printf(room_str, "private-chat-%s@%s", uuid_str, account->muc_service);
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);
free(uuid_str);
account_free(account);
return TRUE; return TRUE;
} }

View File

@ -342,7 +342,9 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
char *password = NULL; char *password = NULL;
xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD); xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD);
password = xmpp_stanza_get_text(password_st); if (password_st) {
password = xmpp_stanza_get_text(password_st);
}
handle_room_invite(INVITE_MEDIATED, invitor, room, reason, password); handle_room_invite(INVITE_MEDIATED, invitor, room, reason, password);
jid_destroy(jidp); jid_destroy(jidp);

View File

@ -50,23 +50,6 @@ void cmd_join_shows_message_when_undefined(void **state)
test_with_connection_status(JABBER_UNDEFINED); test_with_connection_status(JABBER_UNDEFINED);
} }
void cmd_join_shows_usage_when_no_args(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { NULL };
will_return(jabber_get_connection_status, JABBER_CONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_join(args, *help);
assert_true(result);
free(help);
}
void cmd_join_shows_error_message_when_invalid_room_jid(void **state) void cmd_join_shows_error_message_when_invalid_room_jid(void **state)
{ {
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));

View File

@ -2,7 +2,6 @@ void cmd_join_shows_message_when_disconnecting(void **state);
void cmd_join_shows_message_when_connecting(void **state); void cmd_join_shows_message_when_connecting(void **state);
void cmd_join_shows_message_when_disconnected(void **state); void cmd_join_shows_message_when_disconnected(void **state);
void cmd_join_shows_message_when_undefined(void **state); void cmd_join_shows_message_when_undefined(void **state);
void cmd_join_shows_usage_when_no_args(void **state);
void cmd_join_shows_error_message_when_invalid_room_jid(void **state); void cmd_join_shows_error_message_when_invalid_room_jid(void **state);
void cmd_join_uses_account_mucservice_when_no_service_specified(void **state); void cmd_join_uses_account_mucservice_when_no_service_specified(void **state);
void cmd_join_uses_supplied_nick(void **state); void cmd_join_uses_supplied_nick(void **state);

View File

@ -563,7 +563,6 @@ int main(int argc, char* argv[]) {
unit_test(cmd_join_shows_message_when_connecting), unit_test(cmd_join_shows_message_when_connecting),
unit_test(cmd_join_shows_message_when_disconnected), unit_test(cmd_join_shows_message_when_disconnected),
unit_test(cmd_join_shows_message_when_undefined), unit_test(cmd_join_shows_message_when_undefined),
unit_test(cmd_join_shows_usage_when_no_args),
unit_test(cmd_join_shows_error_message_when_invalid_room_jid), unit_test(cmd_join_shows_error_message_when_invalid_room_jid),
unit_test(cmd_join_uses_account_mucservice_when_no_service_specified), unit_test(cmd_join_uses_account_mucservice_when_no_service_specified),
unit_test(cmd_join_uses_supplied_nick), unit_test(cmd_join_uses_supplied_nick),