From 4c7396e77d94a1b5d2f25ed38d2dbc82dc79623d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Jan 2018 18:49:07 +0000 Subject: [PATCH] Allow hiding room server in roster --- src/command/cmd_ac.c | 16 ++++++++++++++++ src/command/cmd_defs.c | 4 ++++ src/command/cmd_funcs.c | 24 ++++++++++++++++++++++++ src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/rosterwin.c | 9 ++++++++- 7 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 5eabd026..8e53bb10 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -143,6 +143,7 @@ static Autocomplete roster_presence_ac; static Autocomplete roster_char_ac; static Autocomplete roster_remove_all_ac; static Autocomplete roster_room_ac; +static Autocomplete roster_room_show_ac; static Autocomplete roster_room_position_ac; static Autocomplete roster_room_by_ac; static Autocomplete roster_room_order_ac; @@ -469,6 +470,11 @@ cmd_ac_init(void) autocomplete_add(roster_room_ac, "order"); autocomplete_add(roster_room_ac, "unread"); autocomplete_add(roster_room_ac, "private"); + autocomplete_add(roster_room_ac, "show"); + autocomplete_add(roster_room_ac, "hide"); + + roster_room_show_ac = autocomplete_new(); + autocomplete_add(roster_room_show_ac, "server"); roster_room_by_ac = autocomplete_new(); autocomplete_add(roster_room_by_ac, "service"); @@ -979,6 +985,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(roster_count_ac); autocomplete_reset(roster_order_ac); autocomplete_reset(roster_room_ac); + autocomplete_reset(roster_room_show_ac); autocomplete_reset(roster_room_by_ac); autocomplete_reset(roster_unread_ac); autocomplete_reset(roster_room_position_ac); @@ -1098,6 +1105,7 @@ cmd_ac_uninit(void) autocomplete_free(roster_count_ac); autocomplete_free(roster_order_ac); autocomplete_free(roster_room_ac); + autocomplete_free(roster_room_show_ac); autocomplete_free(roster_room_by_ac); autocomplete_free(roster_unread_ac); autocomplete_free(roster_room_position_ac); @@ -1550,6 +1558,14 @@ _roster_autocomplete(ProfWin *window, const char *const input, gboolean previous if (result) { return result; } + result = autocomplete_param_with_ac(input, "/roster room show", roster_room_show_ac, TRUE, previous); + if (result) { + return result; + } + result = autocomplete_param_with_ac(input, "/roster room hide", roster_room_show_ac, TRUE, previous); + if (result) { + return result; + } result = autocomplete_param_with_func(input, "/roster count zero", prefs_autocomplete_boolean_choice, previous); if (result) { return result; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 7685dfb9..fa7e50d0 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -287,6 +287,8 @@ static struct cmd_t command_defs[] = "/roster room by service|none", "/roster room order name|unread", "/roster room unread before|after|off", + "/roster room show server", + "/roster room hide server", "/roster private room|group|off", "/roster private char |none", "/roster header char |none", @@ -352,6 +354,8 @@ static struct cmd_t command_defs[] = { "room unread before", "Show unread message count before room." }, { "room unread after", "Show unread message count after room." }, { "room unread off", "Do not show unread message count for rooms." }, + { "room show server", "Show the conference server with room JIDs." }, + { "room hide server", "Do not show the conference server with room JIDs." }, { "private room", "Show room private chats with the room." }, { "private group", "Show room private chats as a separate roster group." }, { "private off", "Do not show room private chats." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index e211cc24..509e19ee 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -2869,6 +2869,30 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) cons_bad_cmd_usage(command); return TRUE; } + } else if (g_strcmp0(args[1], "show") == 0) { + if (g_strcmp0(args[2], "server") == 0) { + cons_show("Roster room server enabled."); + prefs_set_boolean(PREF_ROSTER_ROOMS_SERVER, TRUE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[1], "hide") == 0) { + if (g_strcmp0(args[2], "server") == 0) { + cons_show("Roster room server disabled."); + prefs_set_boolean(PREF_ROSTER_ROOMS_SERVER, FALSE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } } else { cons_bad_cmd_usage(command); return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index ba2ebf17..7d5d62e7 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1560,6 +1560,7 @@ _get_group(preference_t pref) case PREF_ROSTER_ROOMS_BY: case PREF_ROSTER_ROOMS_ORDER: case PREF_ROSTER_ROOMS_UNREAD: + case PREF_ROSTER_ROOMS_SERVER: case PREF_ROSTER_PRIVATE: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: @@ -1791,6 +1792,8 @@ _get_key(preference_t pref) return "roster.rooms.order"; case PREF_ROSTER_ROOMS_UNREAD: return "roster.rooms.unread"; + case PREF_ROSTER_ROOMS_SERVER: + return "roster.rooms.server"; case PREF_ROSTER_PRIVATE: return "roster.private"; case PREF_RESOURCE_TITLE: diff --git a/src/config/preferences.h b/src/config/preferences.h index 6d236977..e8f26e52 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -84,6 +84,7 @@ typedef enum { PREF_ROSTER_ROOMS_BY, PREF_ROSTER_ROOMS_ORDER, PREF_ROSTER_ROOMS_UNREAD, + PREF_ROSTER_ROOMS_SERVER, PREF_ROSTER_PRIVATE, PREF_MUC_PRIVILEGES, PREF_PRESENCE, diff --git a/src/config/theme.c b/src/config/theme.c index dc8dafcf..6eee3753 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -427,6 +427,7 @@ _load_preferences(void) _set_string_preference("roster.unread", PREF_ROSTER_UNREAD); _set_string_preference("roster.rooms.order", PREF_ROSTER_ROOMS_ORDER); _set_string_preference("roster.rooms.unread", PREF_ROSTER_ROOMS_UNREAD); + _set_string_preference("roster.rooms.server", PREF_ROSTER_ROOMS_SERVER); _set_string_preference("roster.rooms.pos", PREF_ROSTER_ROOMS_POS); _set_string_preference("roster.rooms.by", PREF_ROSTER_ROOMS_BY); _set_string_preference("roster.private", PREF_ROSTER_PRIVATE); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index c30a880b..3a38109d 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -762,7 +762,14 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin) g_string_append(msg, jidp->localpart); jid_destroy(jidp); } else { - g_string_append(msg, mucwin->roomjid); + gboolean show_server = prefs_get_boolean(PREF_ROSTER_ROOMS_SERVER); + if (show_server) { + g_string_append(msg, mucwin->roomjid); + } else { + Jid *jidp = jid_create(mucwin->roomjid); + g_string_append(msg, jidp->localpart); + jid_destroy(jidp); + } } prefs_free_string(roombypref); if ((g_strcmp0(unreadpos, "after") == 0) && mucwin->unread > 0) {