From c1a97362328c0507bf6d8ba1dbdec4ac2c29644a Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 5 Nov 2019 22:06:19 +0100 Subject: [PATCH] Merge /invite, /invites and /decline commands `/invite ` became `/invite send . `/invites` became `/invite list`. `/decline` became `/invite decline`. Accept is still done via `/join`. Regards https://github.com/profanity-im/profanity/issues/1116 --- src/command/cmd_ac.c | 46 +++++++++++++++++++++----- src/command/cmd_defs.c | 50 +++++++++------------------- src/command/cmd_funcs.c | 72 ++++++++++++++++++----------------------- src/command/cmd_funcs.h | 2 -- src/ui/console.c | 2 +- 5 files changed, 86 insertions(+), 86 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index a3b0625f..a63a3ee8 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -108,6 +108,7 @@ static char* _presence_autocomplete(ProfWin *window, const char *const input, gb static char* _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _clear_autocomplete(ProfWin *window, const char *const input, gboolean previous); +static char* _invite_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous); @@ -222,6 +223,7 @@ static Autocomplete statusbar_chat_ac; static Autocomplete statusbar_room_ac; static Autocomplete statusbar_show_ac; static Autocomplete clear_ac; +static Autocomplete invite_ac; void cmd_ac_init(void) @@ -858,6 +860,11 @@ cmd_ac_init(void) autocomplete_add(statusbar_ac, "chat"); autocomplete_add(statusbar_ac, "room"); + invite_ac = autocomplete_new(); + autocomplete_add(invite_ac, "send"); + autocomplete_add(invite_ac, "list"); + autocomplete_add(invite_ac, "decline"); + statusbar_self_ac = autocomplete_new(); autocomplete_add(statusbar_self_ac, "user"); autocomplete_add(statusbar_self_ac, "barejid"); @@ -1173,6 +1180,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(statusbar_room_ac); autocomplete_reset(statusbar_show_ac); autocomplete_reset(clear_ac); + autocomplete_reset(invite_ac); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1313,6 +1321,7 @@ cmd_ac_uninit(void) autocomplete_free(statusbar_room_ac); autocomplete_free(statusbar_show_ac); autocomplete_free(clear_ac); + autocomplete_free(invite_ac); } static void @@ -1495,14 +1504,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ } } - if (conn_status == JABBER_CONNECTED) { - result = autocomplete_param_with_func(input, "/invite", roster_contact_autocomplete, previous); - if (result) { - return result; - } - } - - gchar *invite_choices[] = { "/decline", "/join" }; + gchar *invite_choices[] = { "/join" }; for (i = 0; i < ARRAY_SIZE(invite_choices); i++) { result = autocomplete_param_with_func(input, invite_choices[i], muc_invites_find, previous); if (result) { @@ -1566,6 +1568,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ g_hash_table_insert(ac_funcs, "/rooms", _rooms_autocomplete); g_hash_table_insert(ac_funcs, "/statusbar", _statusbar_autocomplete); g_hash_table_insert(ac_funcs, "/clear", _clear_autocomplete); + g_hash_table_insert(ac_funcs, "/invite", _invite_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -3477,3 +3480,30 @@ _clear_autocomplete(ProfWin *window, const char *const input, gboolean previous) return NULL; } + +static char* +_invite_autocomplete(ProfWin *window, const char *const input, gboolean previous) +{ + char *result = NULL; + + result = autocomplete_param_with_ac(input, "/invite", invite_ac, TRUE, previous); + if (result) { + return result; + } + + jabber_conn_status_t conn_status = connection_get_status(); + + if (conn_status == JABBER_CONNECTED) { + result = autocomplete_param_with_func(input, "/invite send", roster_contact_autocomplete, previous); + if (result) { + return result; + } + + result = autocomplete_param_with_func(input, "/invite decline", muc_invites_find, previous); + if (result) { + return result; + } + } + + return NULL; +} diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index f10b5b33..dfc3328b 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -577,48 +577,28 @@ static struct cmd_t command_defs[] = }, { "/invite", - parse_args_with_freetext, 1, 2, NULL, + parse_args_with_freetext, 1, 3, NULL, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_invite) CMD_TAGS( CMD_TAG_GROUPCHAT) CMD_SYN( - "/invite []") + "/invite send []", + "/invite list", + "/invite decline") CMD_DESC( - "Send an invite to a contact for the current chat room.") + "Manage room invites. " + "Send an invite to a contact for the current chat room. " + "List received invites. " + "Decline them using /invite decline and accept them using /join.") CMD_ARGS( - { "", "The contact you wish to invite." }, - { "", "An optional message to send with the invite." }) - CMD_NOEXAMPLES - }, - - { "/invites", - parse_args_with_freetext, 0, 0, NULL, - CMD_NOSUBFUNCS - CMD_MAINFUNC(cmd_invites) - CMD_TAGS( - CMD_TAG_GROUPCHAT) - CMD_SYN( - "/invites") - CMD_DESC( - "Show all rooms that you have been invited to, and not accepted or declined.") - CMD_NOARGS - CMD_NOEXAMPLES - }, - - { "/decline", - parse_args_with_freetext, 1, 1, NULL, - CMD_NOSUBFUNCS - CMD_MAINFUNC(cmd_decline) - CMD_TAGS( - CMD_TAG_GROUPCHAT) - CMD_SYN( - "/decline ") - CMD_DESC( - "Decline a chat room invitation.") - CMD_ARGS( - { "", "The room for the invite you wish to decline." }) - CMD_NOEXAMPLES + { "send []", "The contact you wish to invite. And an optional message." }, + { "list", "Show all rooms that you have been invited to, and not accepted or declined."}, + { "decline ", "Decline a chat room invitation."}) + CMD_EXAMPLES( + "/invite send gustavo@pollos.tx", + "/invite decline profanity@rooms.dismail.de" + "/invite list") }, { "/room", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 3a8ae2de..e8c99901 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -3660,8 +3660,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args) gboolean cmd_invite(ProfWin *window, const char *const command, gchar **args) { - char *contact = args[0]; - char *reason = args[1]; jabber_conn_status_t conn_status = connection_get_status(); if (conn_status != JABBER_CONNECTED) { @@ -3669,47 +3667,41 @@ cmd_invite(ProfWin *window, const char *const command, gchar **args) return TRUE; } - if (window->type != WIN_MUC) { - cons_show("You must be in a chat room to send an invite."); - return TRUE; - } + if (g_strcmp0(args[0], "send") == 0) { + char *contact = args[1]; + char *reason = args[2]; - char *usr_jid = roster_barejid_from_name(contact); - if (usr_jid == NULL) { - usr_jid = contact; - } + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room to send an invite."); + return TRUE; + } - ProfMucWin *mucwin = (ProfMucWin*)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - message_send_invite(mucwin->roomjid, usr_jid, reason); - if (reason) { - cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", - contact, mucwin->roomjid, reason); - } else { - cons_show("Room invite sent, contact: %s, room: %s.", - contact, mucwin->roomjid); - } + char *usr_jid = roster_barejid_from_name(contact); + if (usr_jid == NULL) { + usr_jid = contact; + } - return TRUE; -} - -gboolean -cmd_invites(ProfWin *window, const char *const command, gchar **args) -{ - GList *invites = muc_invites(); - cons_show_room_invites(invites); - g_list_free_full(invites, g_free); - return TRUE; -} - -gboolean -cmd_decline(ProfWin *window, const char *const command, gchar **args) -{ - if (!muc_invites_contain(args[0])) { - cons_show("No such invite exists."); - } else { - muc_invites_remove(args[0]); - cons_show("Declined invite to %s.", args[0]); + ProfMucWin *mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + message_send_invite(mucwin->roomjid, usr_jid, reason); + if (reason) { + cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", + contact, mucwin->roomjid, reason); + } else { + cons_show("Room invite sent, contact: %s, room: %s.", + contact, mucwin->roomjid); + } + } else if (g_strcmp0(args[0], "list") == 0) { + GList *invites = muc_invites(); + cons_show_room_invites(invites); + g_list_free_full(invites, g_free); + } else if (g_strcmp0(args[0], "decline") == 0) { + if (!muc_invites_contain(args[1])) { + cons_show("No such invite exists."); + } else { + muc_invites_remove(args[1]); + cons_show("Declined invite to %s.", args[1]); + } } return TRUE; diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 9e845657..9b564aca 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -86,7 +86,6 @@ gboolean cmd_chlog(ProfWin *window, const char *const command, gchar **args); gboolean cmd_clear(ProfWin *window, const char *const command, gchar **args); gboolean cmd_close(ProfWin *window, const char *const command, gchar **args); gboolean cmd_connect(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_decline(ProfWin *window, const char *const command, gchar **args); gboolean cmd_disco(ProfWin *window, const char *const command, gchar **args); gboolean cmd_sendfile(ProfWin *window, const char *const command, gchar **args); gboolean cmd_lastactivity(ProfWin *window, const char *const command, gchar **args); @@ -104,7 +103,6 @@ gboolean cmd_receipts(ProfWin *window, const char *const command, gchar **args); gboolean cmd_info(ProfWin *window, const char *const command, gchar **args); gboolean cmd_intype(ProfWin *window, const char *const command, gchar **args); gboolean cmd_invite(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_invites(ProfWin *window, const char *const command, gchar **args); gboolean cmd_join(ProfWin *window, const char *const command, gchar **args); gboolean cmd_leave(ProfWin *window, const char *const command, gchar **args); gboolean cmd_log(ProfWin *window, const char *const command, gchar **args); diff --git a/src/ui/console.c b/src/ui/console.c index 198b61a4..22dd35f1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -830,7 +830,7 @@ cons_show_room_invite(const char *const invitor, const char * const room, const } cons_show("Use '/join %s' to accept the invitation", room); - cons_show("Use '/decline %s' to decline the invitation", room); + cons_show("Use '/invite decline %s' to decline the invitation", room); if (prefs_get_boolean(PREF_NOTIFY_INVITE)) { notify_invite(display_from, room, reason);