From 2af418fd8da7bce971f84b98be945f8d5a858f9d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 15 Mar 2014 22:25:15 +0000 Subject: [PATCH] Command '/statuses muc' now allows 'all', 'online' and 'none' settings --- src/command/command.c | 40 +++++++++++++++------------------------ src/command/commands.c | 32 +++++++++++++++---------------- src/config/preferences.c | 3 +-- src/server_events.c | 20 ++++++++++++++------ src/ui/console.c | 13 ++++--------- tests/test_cmd_statuses.c | 39 ++++++++++++++++++++++++++++---------- tests/test_cmd_statuses.h | 5 +++-- tests/test_preferences.c | 7 ++++--- tests/test_preferences.h | 2 +- tests/testsuite.c | 9 ++++++--- 10 files changed, 92 insertions(+), 78 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index c3f87516..a9bab0ef 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -780,21 +780,11 @@ static struct cmd_t command_defs[] = { "/statuses console|chat|muc setting", "----------------------------------", "Configure how presence changes are displayed in various windows.", - "Settings for the console:", - " all - Show all presence changes in the console", - " online - Show only when contacts log in/out.", - " none - Don't show any presence changes in the console.", - "Settings for chat windows:", - " all - Show all presence changes in the contact's chat window if one is open.", - " online - Show only when contacts log in/out.", - " none - Don't show any presence changes in the chat windows.", - "Settings for chat room windows:", - " on - Show presence changes in chat rooms.", - " off - Do not show presence changes in chat rooms.", - "The defaults are:", - " console - all", - " chat - all", - " muc - on", + "Settings:", + " all - Show all presence changes.", + " online - Show only online/offline changes.", + " none - Don't show any presence changes.", + "The default is 'all' for all windows.", NULL } } }, { "/away", @@ -879,7 +869,7 @@ static Autocomplete otr_ac; static Autocomplete otr_log_ac; static Autocomplete connect_property_ac; static Autocomplete statuses_ac; -static Autocomplete statuses_cons_chat_ac; +static Autocomplete statuses_setting_ac; static Autocomplete alias_ac; static Autocomplete aliases_ac; static Autocomplete join_property_ac; @@ -1080,10 +1070,10 @@ cmd_init(void) autocomplete_add(statuses_ac, "chat"); autocomplete_add(statuses_ac, "muc"); - statuses_cons_chat_ac = autocomplete_new(); - autocomplete_add(statuses_cons_chat_ac, "all"); - autocomplete_add(statuses_cons_chat_ac, "online"); - autocomplete_add(statuses_cons_chat_ac, "none"); + statuses_setting_ac = autocomplete_new(); + autocomplete_add(statuses_setting_ac, "all"); + autocomplete_add(statuses_setting_ac, "online"); + autocomplete_add(statuses_setting_ac, "none"); alias_ac = autocomplete_new(); autocomplete_add(alias_ac, "add"); @@ -1124,7 +1114,7 @@ cmd_uninit(void) autocomplete_free(otr_log_ac); autocomplete_free(connect_property_ac); autocomplete_free(statuses_ac); - autocomplete_free(statuses_cons_chat_ac); + autocomplete_free(statuses_setting_ac); autocomplete_free(alias_ac); autocomplete_free(aliases_ac); autocomplete_free(join_property_ac); @@ -1247,7 +1237,7 @@ cmd_reset_autocomplete() autocomplete_reset(otr_log_ac); autocomplete_reset(connect_property_ac); autocomplete_reset(statuses_ac); - autocomplete_reset(statuses_cons_chat_ac); + autocomplete_reset(statuses_setting_ac); autocomplete_reset(alias_ac); autocomplete_reset(aliases_ac); autocomplete_reset(join_property_ac); @@ -1790,17 +1780,17 @@ _statuses_autocomplete(char *input, int *size) { char *result = NULL; - result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_cons_chat_ac); + result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_setting_ac); if (result != NULL) { return result; } - result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_cons_chat_ac); + result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_setting_ac); if (result != NULL) { return result; } - result = autocomplete_param_with_func(input, size, "/statuses muc", prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_ac(input, size, "/statuses muc", statuses_setting_ac); if (result != NULL) { return result; } diff --git a/src/command/commands.c b/src/command/commands.c index e63d9893..c7a8e0d5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2424,23 +2424,14 @@ cmd_statuses(gchar **args, struct cmd_help_t help) strcmp(args[0], "chat") != 0 && strcmp(args[0], "muc") != 0) { cons_show("Usage: %s", help.usage); + return TRUE; } - if (strcmp(args[0], "console") == 0 || strcmp(args[0], "chat") == 0) { - if (strcmp(args[1], "all") != 0 && - strcmp(args[1], "online") != 0 && - strcmp(args[1], "none") != 0) { - cons_show("Usage: %s", help.usage); - return TRUE; - } - - } - - if (strcmp(args[0], "muc") == 0) { - if (strcmp(args[1], "on") != 0 && strcmp(args[1], "off") != 0) { - cons_show("Usage: %s", help.usage); - return TRUE; - } + if (strcmp(args[1], "all") != 0 && + strcmp(args[1], "online") != 0 && + strcmp(args[1], "none") != 0) { + cons_show("Usage: %s", help.usage); + return TRUE; } if (strcmp(args[0], "console") == 0) { @@ -2466,9 +2457,16 @@ cmd_statuses(gchar **args, struct cmd_help_t help) } if (strcmp(args[0], "muc") == 0) { - _cmd_set_boolean_preference(args[1], help, - "Chat room presence updates", PREF_STATUSES_MUC); + prefs_set_string(PREF_STATUSES_MUC, args[1]); + if (strcmp(args[1], "all") == 0) { + cons_show("All presence updates will appear in chat room windows."); + } else if (strcmp(args[1], "online") == 0) { + cons_show("Only join/leave presence updates will appear in chat room windows."); + } else { + cons_show("Presence updates will not appear in chat room windows."); + } } + return TRUE; } diff --git a/src/config/preferences.c b/src/config/preferences.c index 8744acdf..02bb0833 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -477,8 +477,6 @@ _get_default_boolean(preference_t pref) case PREF_STATUSES: case PREF_AUTOAWAY_CHECK: case PREF_OTR_WARN: - case PREF_STATUSES_MUC: - return TRUE; default: return FALSE; } @@ -495,6 +493,7 @@ _get_default_string(preference_t pref) return "redact"; case PREF_STATUSES_CONSOLE: case PREF_STATUSES_CHAT: + case PREF_STATUSES_MUC: return "all"; default: return NULL; diff --git a/src/server_events.c b/src/server_events.c index 012291f0..01da55c7 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -427,8 +427,8 @@ handle_room_member_presence(const char * const room, gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str); if (updated) { - gboolean show_muc = prefs_get_boolean(PREF_STATUSES_MUC); - if (show_muc) { + char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC); + if (g_strcmp0(muc_status_pref, "all") == 0) { ui_room_member_presence(room, nick, show, status); ui_current_page_off(); } @@ -441,8 +441,12 @@ handle_room_member_online(const char * const room, const char * const nick, const char * const caps_str) { muc_add_to_roster(room, nick, show, status, caps_str); - ui_room_member_online(room, nick, show, status); - ui_current_page_off(); + + char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC); + if (g_strcmp0(muc_status_pref, "none") != 0) { + ui_room_member_online(room, nick, show, status); + ui_current_page_off(); + } } void @@ -450,8 +454,12 @@ handle_room_member_offline(const char * const room, const char * const nick, const char * const show, const char * const status) { muc_remove_from_roster(room, nick); - ui_room_member_offline(room, nick); - ui_current_page_off(); + + char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC); + if (g_strcmp0(muc_status_pref, "none") != 0) { + ui_room_member_offline(room, nick); + ui_current_page_off(); + } } void diff --git a/src/ui/console.c b/src/ui/console.c index 1308003e..8a777204 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -992,16 +992,11 @@ _cons_statuses_setting(void) { char *console = prefs_get_string(PREF_STATUSES_CONSOLE); char *chat = prefs_get_string(PREF_STATUSES_CHAT); - gboolean muc = prefs_get_boolean(PREF_STATUSES_MUC); + char *muc = prefs_get_string(PREF_STATUSES_MUC); - cons_show("Console statuses (/statuses) : %s", console); - cons_show("Chat win statuses (/statuses) : %s", chat); - - if (muc) { - cons_show("MUC statuses (/statuses) : ON"); - } else { - cons_show("MUC statuses (/statuses) : OFF"); - } + cons_show("Console statuses (/statuses) : %s", console); + cons_show("Chat win statuses (/statuses) : %s", chat); + cons_show("Chat room statuses (/statuses) : %s", muc); } static void diff --git a/tests/test_cmd_statuses.c b/tests/test_cmd_statuses.c index 04380724..f15dd820 100644 --- a/tests/test_cmd_statuses.c +++ b/tests/test_cmd_statuses.c @@ -181,36 +181,55 @@ void cmd_statuses_chat_sets_none(void **state) free(help); } -void cmd_statuses_muc_sets_on(void **state) +void cmd_statuses_muc_sets_all(void **state) { mock_cons_show(); CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "muc", "on", NULL }; + gchar *args[] = { "muc", "all", NULL }; - expect_cons_show("Chat room presence updates enabled."); + expect_cons_show("All presence updates will appear in chat room windows."); gboolean result = cmd_statuses(args, *help); - gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); + char *setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); - assert_true(setting); + assert_string_equal("all", setting); assert_true(result); free(help); } -void cmd_statuses_muc_sets_off(void **state) +void cmd_statuses_muc_sets_online(void **state) { mock_cons_show(); CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "muc", "off", NULL }; + gchar *args[] = { "muc", "online", NULL }; - expect_cons_show("Chat room presence updates disabled."); + expect_cons_show("Only join/leave presence updates will appear in chat room windows."); gboolean result = cmd_statuses(args, *help); - gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); - assert_false(setting); + char *setting = prefs_get_string(PREF_STATUSES_MUC); + assert_non_null(setting); + assert_string_equal("online", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_muc_sets_none(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "muc", "none", NULL }; + + expect_cons_show("Presence updates will not appear in chat room windows."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_MUC); + assert_non_null(setting); + assert_string_equal("none", setting); assert_true(result); free(help); diff --git a/tests/test_cmd_statuses.h b/tests/test_cmd_statuses.h index 69f935f0..306a6fc7 100644 --- a/tests/test_cmd_statuses.h +++ b/tests/test_cmd_statuses.h @@ -8,5 +8,6 @@ void cmd_statuses_console_sets_none(void **state); void cmd_statuses_chat_sets_all(void **state); void cmd_statuses_chat_sets_online(void **state); void cmd_statuses_chat_sets_none(void **state); -void cmd_statuses_muc_sets_on(void **state); -void cmd_statuses_muc_sets_off(void **state); +void cmd_statuses_muc_sets_all(void **state); +void cmd_statuses_muc_sets_online(void **state); +void cmd_statuses_muc_sets_none(void **state); diff --git a/tests/test_preferences.c b/tests/test_preferences.c index 41e254cc..c4bcbf77 100644 --- a/tests/test_preferences.c +++ b/tests/test_preferences.c @@ -24,9 +24,10 @@ void statuses_chat_defaults_to_all(void **state) assert_string_equal("all", setting); } -void statuses_muc_defaults_to_on(void **state) +void statuses_muc_defaults_to_all(void **state) { - gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); + char *setting = prefs_get_string(PREF_STATUSES_MUC); - assert_true(setting); + assert_non_null(setting); + assert_string_equal("all", setting); } diff --git a/tests/test_preferences.h b/tests/test_preferences.h index 577226b7..5bf79a6a 100644 --- a/tests/test_preferences.h +++ b/tests/test_preferences.h @@ -1,3 +1,3 @@ void statuses_console_defaults_to_all(void **state); void statuses_chat_defaults_to_all(void **state); -void statuses_muc_defaults_to_on(void **state); +void statuses_muc_defaults_to_all(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 0c2101f3..63d8fd2d 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -331,10 +331,13 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(cmd_statuses_chat_sets_none, load_preferences, close_preferences), - unit_test_setup_teardown(cmd_statuses_muc_sets_on, + unit_test_setup_teardown(cmd_statuses_muc_sets_all, load_preferences, close_preferences), - unit_test_setup_teardown(cmd_statuses_muc_sets_off, + unit_test_setup_teardown(cmd_statuses_muc_sets_online, + load_preferences, + close_preferences), + unit_test_setup_teardown(cmd_statuses_muc_sets_none, load_preferences, close_preferences), @@ -344,7 +347,7 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(statuses_chat_defaults_to_all, load_preferences, close_preferences), - unit_test_setup_teardown(statuses_muc_defaults_to_on, + unit_test_setup_teardown(statuses_muc_defaults_to_all, load_preferences, close_preferences),