diff options
author | James Booth <boothj5@gmail.com> | 2016-05-23 23:53:44 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-05-23 23:53:44 +0100 |
commit | 6559263b2fed1edc6b004dc3e50697600e450b9b (patch) | |
tree | 7b17f7d326ada6abb958e362fd76c8b4abc019f7 | |
parent | 0edd4309257a8372761f44cbd576b027d1b9766c (diff) | |
download | profani-tty-6559263b2fed1edc6b004dc3e50697600e450b9b.tar.gz |
Option to bookmark room invites
issue #813
-rw-r--r-- | src/command/cmd_ac.c | 5 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 6 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 14 | ||||
-rw-r--r-- | src/config/preferences.c | 6 | ||||
-rw-r--r-- | src/config/preferences.h | 1 | ||||
-rw-r--r-- | src/event/server_events.c | 8 | ||||
-rw-r--r-- | src/ui/console.c | 8 | ||||
-rw-r--r-- | src/xmpp/bookmark.c | 18 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 1 | ||||
-rw-r--r-- | tests/unittests/xmpp/stub_xmpp.c | 5 |
10 files changed, 68 insertions, 4 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 4ecbdae3..e43bcdb1 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -517,6 +517,7 @@ cmd_ac_init(void) autocomplete_add(bookmark_ac, "update"); autocomplete_add(bookmark_ac, "remove"); autocomplete_add(bookmark_ac, "join"); + autocomplete_add(bookmark_ac, "invites"); bookmark_property_ac = autocomplete_new(); autocomplete_add(bookmark_property_ac, "nick"); @@ -1599,6 +1600,10 @@ _bookmark_autocomplete(ProfWin *window, const char *const input) if (found) { return found; } + found = autocomplete_param_with_func(input, "/bookmark invites", prefs_autocomplete_boolean_choice); + if (found) { + return found; + } found = autocomplete_param_with_ac(input, "/bookmark", bookmark_ac, TRUE); return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 9669f4b6..415dc7fc 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -807,7 +807,8 @@ static struct cmd_t command_defs[] = "/bookmark add <room> [nick <nick>] [password <password>] [autojoin on|off]", "/bookmark update <room> [nick <nick>] [password <password>] [autojoin on|off]", "/bookmark remove <room>", - "/bookmark join <room>") + "/bookmark join <room>", + "/bookmark invites on|off") CMD_DESC( "Manage bookmarks and join bookmarked rooms. " "In a chat room, no arguments will bookmark the current room, setting autojoin to \"on\".") @@ -819,7 +820,8 @@ static struct cmd_t command_defs[] = { "nick <nick>", "Nickname used in the chat room." }, { "password <password>", "Password if required, may be stored in plaintext on your server." }, { "autojoin on|off", "Whether to join the room automatically on login." }, - { "join <room>", "Join room using the properties associated with the bookmark." }) + { "join <room>", "Join room using the properties associated with the bookmark." }, + { "invites on|off", "Whether or not to bookmark accepted room invites, defaults to 'on'."}) CMD_NOEXAMPLES }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 03a7e8e5..544a356a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -4337,7 +4337,19 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) return TRUE; } - if (strcmp(cmd, "list") == 0) { + if (strcmp(cmd, "invites") == 0) { + if (g_strcmp0(args[1], "on") == 0) { + prefs_set_boolean(PREF_BOOKMARK_INVITE, TRUE); + cons_show("Auto bookmarking accepted invites enabled."); + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_boolean(PREF_BOOKMARK_INVITE, FALSE); + cons_show("Auto bookmarking accepted invites disabled."); + } else { + cons_bad_cmd_usage(command); + cons_show(""); + } + return TRUE; + } else if (strcmp(cmd, "list") == 0) { const GList *bookmarks = bookmark_get_list(); cons_show_bookmarks(bookmarks); } else { diff --git a/src/config/preferences.c b/src/config/preferences.c index 5d3d0512..9381d014 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -57,6 +57,7 @@ #define PREF_GROUP_ALIAS "alias" #define PREF_GROUP_OTR "otr" #define PREF_GROUP_PGP "pgp" +#define PREF_GROUP_MUC "muc" #define INPBLOCK_DEFAULT 1000 @@ -1286,6 +1287,8 @@ _get_group(preference_t pref) return PREF_GROUP_OTR; case PREF_PGP_LOG: return PREF_GROUP_PGP; + case PREF_BOOKMARK_INVITE: + return PREF_GROUP_MUC; default: return NULL; } @@ -1484,6 +1487,8 @@ _get_key(preference_t pref) return "console.private"; case PREF_CONSOLE_CHAT: return "console.chat"; + case PREF_BOOKMARK_INVITE: + return "bookmark.invite"; default: return NULL; } @@ -1530,6 +1535,7 @@ _get_default_boolean(preference_t pref) case PREF_LASTACTIVITY: case PREF_NOTIFY_MENTION_WHOLE_WORD: case PREF_TRAY_READ: + case PREF_BOOKMARK_INVITE: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index 5e4b28ef..a7b84dfe 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -140,6 +140,7 @@ typedef enum { PREF_CONSOLE_MUC, PREF_CONSOLE_PRIVATE, PREF_CONSOLE_CHAT, + PREF_BOOKMARK_INVITE, } preference_t; typedef struct prof_alias_t { diff --git a/src/event/server_events.c b/src/event/server_events.c index 5a04a885..57c82696 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -793,7 +793,13 @@ sv_ev_muc_self_online(const char *const room, const char *const nick, gboolean c iq_room_info_request(room, FALSE); - muc_invites_remove(room); + if (muc_invites_contain(room)) { + if (prefs_get_boolean(PREF_BOOKMARK_INVITE) && !bookmark_exists(room)) { + bookmark_add(room, nick, muc_invite_password(room), "on"); + } + muc_invites_remove(room); + } + muc_roster_set_complete(room); // show roster if occupants list disabled by default diff --git a/src/ui/console.c b/src/ui/console.c index a5ff3a76..ebbddd70 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -717,6 +717,14 @@ cons_show_bookmarks(const GList *list) list = g_list_next(list); } } + + cons_show(""); + if (prefs_get_boolean(PREF_BOOKMARK_INVITE)) { + cons_show("Automatic invite bookmarking (/bookmark invites): ON"); + } else { + cons_show("Automatic invite bookmarking (/bookmark invites): OFF"); + } + cons_alert(); } diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 0f88a129..8c859a92 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -240,6 +240,24 @@ bookmark_autocomplete_reset(void) } } +gboolean +bookmark_exists(const char *const room) +{ + GSList *bookmarks = autocomplete_create_list(bookmark_ac); + GSList *curr = bookmarks; + while (curr) { + if (strcmp(curr->data, room) == 0) { + g_slist_free_full(bookmarks, g_free); + return TRUE; + } else { + curr = g_slist_next(curr); + } + } + g_slist_free_full(bookmarks, g_free); + + return FALSE; +} + static int _bookmark_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 65d2cbad..890df2f3 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -184,6 +184,7 @@ gboolean bookmark_join(const char *jid); const GList* bookmark_get_list(void); char* bookmark_find(const char *const search_str); void bookmark_autocomplete_reset(void); +gboolean bookmark_exists(const char *const room); void roster_send_name_change(const char *const barejid, const char *const new_name, GSList *groups); void roster_send_add_to_group(const char *const group, PContact contact); diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c index 0fb9d828..6efcb783 100644 --- a/tests/unittests/xmpp/stub_xmpp.c +++ b/tests/unittests/xmpp/stub_xmpp.c @@ -254,6 +254,11 @@ void roster_send_name_change(const char * const barejid, const char * const new_ check_expected(groups); } +gboolean bookmark_exists(const char *const room) +{ + return FALSE; +} + void roster_send_add_to_group(const char * const group, PContact contact) {} void roster_send_remove_from_group(const char * const group, PContact contact) {} |