From fc049c9eefd740fdc2a9a271150cbcca5d7b2022 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 18 Oct 2014 20:22:34 +0100 Subject: [PATCH] Added /privileges command to set UI option for showing roles/affiliations in rooms --- TODO_045 | 2 - src/command/command.c | 13 +++- src/command/commands.c | 14 +++- src/command/commands.h | 1 + src/config/preferences.c | 4 ++ src/config/preferences.h | 1 + src/server_events.c | 40 ++++++----- src/ui/console.c | 11 +++ src/ui/core.c | 147 +++++++++++++++++++++++++-------------- src/ui/ui.h | 2 + 10 files changed, 160 insertions(+), 75 deletions(-) diff --git a/TODO_045 b/TODO_045 index 7ad18298..0603bfe9 100644 --- a/TODO_045 +++ b/TODO_045 @@ -1,5 +1,3 @@ -Dont show success message for affiliation/role changes for user changing them -Add config option to not show role/affilation messages and changes Check all commands from private conversations Test all freetext args Make form editing commands less verbose diff --git a/src/command/command.c b/src/command/command.c index 1954e927..03dc6e01 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -547,6 +547,17 @@ static struct cmd_t command_defs[] = "Logout of any current session, and quit Profanity.", NULL } } }, + { "/privileges", + cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, + { "/privileges on|off", "Show occupant privileges in chat rooms.", + { "/privileges on|off", + "---------------------------", + "If enabled:", + "The room roster will be broken down my role.", + "An occupants role and affiliation will be shown when they join a room.", + "Changes to occupant privileges will be shown in the chat room.", + NULL } } }, + { "/beep", cmd_beep, parse_args, 1, 1, &cons_beep_setting, { "/beep on|off", "Terminal beep on new messages.", @@ -1697,7 +1708,7 @@ _cmd_complete_parameters(char *input, int *size) // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", "/titlebar", - "/vercheck" }; + "/vercheck", "/privileges" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, size, boolean_choices[i], diff --git a/src/command/commands.c b/src/command/commands.c index ecd8a7de..ea789192 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -590,7 +590,7 @@ cmd_help(gchar **args, struct cmd_help_t help) } else if (strcmp(args[0], "groupchat") == 0) { gchar *filter[] = { "/close", "/clear", "/decline", "/grlog", "/invite", "/invites", "/join", "/leave", "/notify", "/msg", - "/rooms", "/tiny", "/who", "/nick" }; + "/rooms", "/tiny", "/who", "/nick", "/privileges" }; _cmd_show_filtered_help("Groupchat commands", filter, ARRAY_SIZE(filter)); } else if (strcmp(args[0], "presence") == 0) { @@ -612,7 +612,7 @@ cmd_help(gchar **args, struct cmd_help_t help) "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", "/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme", - "/titlebar", "/vercheck" }; + "/titlebar", "/vercheck", "/privileges" }; _cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter)); } else if (strcmp(args[0], "navigation") == 0) { @@ -2878,6 +2878,16 @@ cmd_leave(gchar **args, struct cmd_help_t help) return TRUE; } +gboolean +cmd_privileges(gchar **args, struct cmd_help_t help) +{ + gboolean result = _cmd_set_boolean_preference(args[0], help, "MUC privileges", PREF_MUC_PRIVILEGES); + + ui_redraw_all_room_rosters(); + + return result; +} + gboolean cmd_beep(gchar **args, struct cmd_help_t help) { diff --git a/src/command/commands.h b/src/command/commands.h index 757a09cc..ed393f8a 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -131,5 +131,6 @@ gboolean cmd_ban(gchar **args, struct cmd_help_t help); gboolean cmd_subject(gchar **args, struct cmd_help_t help); gboolean cmd_affiliation(gchar **args, struct cmd_help_t help); gboolean cmd_role(gchar **args, struct cmd_help_t help); +gboolean cmd_privileges(gchar **args, struct cmd_help_t help); #endif \ No newline at end of file diff --git a/src/config/preferences.c b/src/config/preferences.c index c80b580f..cad30cfb 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -436,6 +436,7 @@ _get_group(preference_t pref) case PREF_STATUSES_CONSOLE: case PREF_STATUSES_CHAT: case PREF_STATUSES_MUC: + case PREF_MUC_PRIVILEGES: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -496,6 +497,8 @@ _get_key(preference_t pref) return "mouse"; case PREF_OCCUPANTS: return "occupants"; + case PREF_MUC_PRIVILEGES: + return "privileges"; case PREF_STATUSES: return "statuses"; case PREF_STATUSES_CONSOLE: @@ -570,6 +573,7 @@ _get_default_boolean(preference_t pref) case PREF_NOTIFY_TYPING_CURRENT: case PREF_SPLASH: case PREF_OCCUPANTS: + case PREF_MUC_PRIVILEGES: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index 2acb7c2e..528d9661 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -58,6 +58,7 @@ typedef enum { PREF_HISTORY, PREF_MOUSE, PREF_OCCUPANTS, + PREF_MUC_PRIVILEGES, PREF_STATUSES, PREF_STATUSES_CONSOLE, PREF_STATUSES_CHAT, diff --git a/src/server_events.c b/src/server_events.c index de02aa6d..a15ebaf4 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -707,17 +707,19 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea // check for change in role/affiliation } else { - // both changed - if ((g_strcmp0(role, old_role) != 0) && (g_strcmp0(affiliation, old_affiliation) != 0)) { - ui_room_role_and_affiliation_change(room, role, affiliation, actor, reason); + if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { + // both changed + if ((g_strcmp0(role, old_role) != 0) && (g_strcmp0(affiliation, old_affiliation) != 0)) { + ui_room_role_and_affiliation_change(room, role, affiliation, actor, reason); - // role changed - } else if (g_strcmp0(role, old_role) != 0) { - ui_room_role_change(room, role, actor, reason); + // role changed + } else if (g_strcmp0(role, old_role) != 0) { + ui_room_role_change(room, role, actor, reason); - // affiliation changed - } else if (g_strcmp0(affiliation, old_affiliation) != 0) { - ui_room_affiliation_change(room, affiliation, actor, reason); + // affiliation changed + } else if (g_strcmp0(affiliation, old_affiliation) != 0) { + ui_room_affiliation_change(room, affiliation, actor, reason); + } } } @@ -776,17 +778,19 @@ handle_muc_occupant_online(const char * const room, const char * const nick, con // presence unchanged, check for role/affiliation change } else { - // both changed - if ((g_strcmp0(role, old_role) != 0) && (g_strcmp0(affiliation, old_affiliation) != 0)) { - ui_room_occupant_role_and_affiliation_change(room, nick, role, affiliation, actor, reason); + if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { + // both changed + if ((g_strcmp0(role, old_role) != 0) && (g_strcmp0(affiliation, old_affiliation) != 0)) { + ui_room_occupant_role_and_affiliation_change(room, nick, role, affiliation, actor, reason); - // role changed - } else if (g_strcmp0(role, old_role) != 0) { - ui_room_occupant_role_change(room, nick, role, actor, reason); + // role changed + } else if (g_strcmp0(role, old_role) != 0) { + ui_room_occupant_role_change(room, nick, role, actor, reason); - // affiliation changed - } else if (g_strcmp0(affiliation, old_affiliation) != 0) { - ui_room_occupant_affiliation_change(room, nick, affiliation, actor, reason); + // affiliation changed + } else if (g_strcmp0(affiliation, old_affiliation) != 0) { + ui_room_occupant_affiliation_change(room, nick, affiliation, actor, reason); + } } ui_muc_roster(room); } diff --git a/src/ui/console.c b/src/ui/console.c index d12edae8..73aa9710 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -821,6 +821,15 @@ _cons_theme_setting(void) prefs_free_string(theme); } +static void +_cons_privileges_setting(void) +{ + if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) + cons_show("MUC privileges (/privileges) : ON"); + else + cons_show("MUC privileges (/privileges) : OFF"); +} + static void _cons_beep_setting(void) { @@ -926,6 +935,7 @@ _cons_show_ui_prefs(void) cons_mouse_setting(); cons_statuses_setting(); cons_occupants_setting(); + cons_privileges_setting(); cons_titlebar_setting(); cons_alert(); @@ -1518,6 +1528,7 @@ console_init_module(void) cons_show_account_list = _cons_show_account_list; cons_show_account = _cons_show_account; cons_theme_setting = _cons_theme_setting; + cons_privileges_setting = _cons_privileges_setting; cons_beep_setting = _cons_beep_setting; cons_flash_setting = _cons_flash_setting; cons_splash_setting = _cons_splash_setting; diff --git a/src/ui/core.c b/src/ui/core.c index 5868f5e6..12cc2055 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -670,6 +670,26 @@ _ui_close_read_wins(void) return count; } +static void +_ui_redraw_all_room_rosters(void) +{ + GList *win_nums = wins_get_nums(); + GList *curr = win_nums; + + while (curr != NULL) { + int num = GPOINTER_TO_INT(curr->data); + ProfWin *window = wins_get_by_num(num); + if (window->type == WIN_MUC && window->subwin) { + char *room = window->from; + ui_muc_roster(room); + } + curr = g_list_next(curr); + } + + g_list_free(curr); + g_list_free(win_nums); +} + static gboolean _ui_win_has_unsaved_form(int num) { @@ -1305,14 +1325,16 @@ _ui_room_join(const char * const room, gboolean focus) } char *nick = muc_nick(room); - char *role = muc_role_str(room); - char *affiliation = muc_affiliation_str(room); win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "-> You have joined the room as %s", nick); - if (role) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", role: %s", role); - } - if (affiliation) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", affiliation: %s", affiliation); + if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { + char *role = muc_role_str(room); + char *affiliation = muc_affiliation_str(room); + if (role) { + win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", role: %s", role); + } + if (affiliation) { + win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", affiliation: %s", affiliation); + } } win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", ""); @@ -1593,11 +1615,13 @@ _ui_room_member_online(const char * const room, const char * const nick, const c log_error("Received online presence for room participant %s, but no window open for %s.", nick, room); } else { win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ONLINE, "", "-> %s has joined the room", nick); - if (role) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", role: %s", role); - } - if (affiliation) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", affiliation: %s", affiliation); + if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { + if (role) { + win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", role: %s", role); + } + if (affiliation) { + win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", affiliation: %s", affiliation); + } } win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", ""); } @@ -2763,49 +2787,67 @@ _ui_muc_roster(const char * const room) if (roster) { werase(window->subwin); - wattron(window->subwin, COLOUR_ROOMINFO); - wprintw(window->subwin, " -Moderators\n"); - wattroff(window->subwin, COLOUR_ROOMINFO); - GList *roster_curr = roster; - while (roster_curr) { - Occupant *occupant = roster_curr->data; - if (occupant->role == MUC_ROLE_MODERATOR) { - wprintw(window->subwin, " "); - const char *presence_str = string_from_resource_presence(occupant->presence); - int presence_colour = win_presence_colour(presence_str); - wattron(window->subwin, presence_colour); - wprintw(window->subwin, occupant->nick); - wattroff(window->subwin, presence_colour); - wprintw(window->subwin, "\n"); + if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { + wattron(window->subwin, COLOUR_ROOMINFO); + wprintw(window->subwin, " -Moderators\n"); + wattroff(window->subwin, COLOUR_ROOMINFO); + GList *roster_curr = roster; + while (roster_curr) { + Occupant *occupant = roster_curr->data; + if (occupant->role == MUC_ROLE_MODERATOR) { + wprintw(window->subwin, " "); + const char *presence_str = string_from_resource_presence(occupant->presence); + int presence_colour = win_presence_colour(presence_str); + wattron(window->subwin, presence_colour); + wprintw(window->subwin, occupant->nick); + wattroff(window->subwin, presence_colour); + wprintw(window->subwin, "\n"); + } + roster_curr = g_list_next(roster_curr); } - roster_curr = g_list_next(roster_curr); - } - wattron(window->subwin, COLOUR_ROOMINFO); - wprintw(window->subwin, " -Participants\n"); - wattroff(window->subwin, COLOUR_ROOMINFO); - roster_curr = roster; - while (roster_curr) { - Occupant *occupant = roster_curr->data; - if (occupant->role == MUC_ROLE_PARTICIPANT) { - wprintw(window->subwin, " "); - const char *presence_str = string_from_resource_presence(occupant->presence); - int presence_colour = win_presence_colour(presence_str); - wattron(window->subwin, presence_colour); - wprintw(window->subwin, occupant->nick); - wattroff(window->subwin, presence_colour); - wprintw(window->subwin, "\n"); + wattron(window->subwin, COLOUR_ROOMINFO); + wprintw(window->subwin, " -Participants\n"); + wattroff(window->subwin, COLOUR_ROOMINFO); + roster_curr = roster; + while (roster_curr) { + Occupant *occupant = roster_curr->data; + if (occupant->role == MUC_ROLE_PARTICIPANT) { + wprintw(window->subwin, " "); + const char *presence_str = string_from_resource_presence(occupant->presence); + int presence_colour = win_presence_colour(presence_str); + wattron(window->subwin, presence_colour); + wprintw(window->subwin, occupant->nick); + wattroff(window->subwin, presence_colour); + wprintw(window->subwin, "\n"); + } + roster_curr = g_list_next(roster_curr); } - roster_curr = g_list_next(roster_curr); - } - wattron(window->subwin, COLOUR_ROOMINFO); - wprintw(window->subwin, " -Visitors\n"); - wattroff(window->subwin, COLOUR_ROOMINFO); - roster_curr = roster; - while (roster_curr) { - Occupant *occupant = roster_curr->data; - if (occupant->role == MUC_ROLE_VISITOR) { + wattron(window->subwin, COLOUR_ROOMINFO); + wprintw(window->subwin, " -Visitors\n"); + wattroff(window->subwin, COLOUR_ROOMINFO); + roster_curr = roster; + while (roster_curr) { + Occupant *occupant = roster_curr->data; + if (occupant->role == MUC_ROLE_VISITOR) { + wprintw(window->subwin, " "); + const char *presence_str = string_from_resource_presence(occupant->presence); + int presence_colour = win_presence_colour(presence_str); + wattron(window->subwin, presence_colour); + wprintw(window->subwin, occupant->nick); + wattroff(window->subwin, presence_colour); + wprintw(window->subwin, "\n"); + } + roster_curr = g_list_next(roster_curr); + } + } else { + wattron(window->subwin, COLOUR_ROOMINFO); + wprintw(window->subwin, " -Occupants\n"); + wattroff(window->subwin, COLOUR_ROOMINFO); + GList *roster_curr = roster; + while (roster_curr) { + Occupant *occupant = roster_curr->data; wprintw(window->subwin, " "); const char *presence_str = string_from_resource_presence(occupant->presence); int presence_colour = win_presence_colour(presence_str); @@ -2813,8 +2855,8 @@ _ui_muc_roster(const char * const room) wprintw(window->subwin, occupant->nick); wattroff(window->subwin, presence_colour); wprintw(window->subwin, "\n"); + roster_curr = g_list_next(roster_curr); } - roster_curr = g_list_next(roster_curr); } } } @@ -3137,5 +3179,6 @@ ui_init_module(void) ui_room_occupant_role_change = _ui_room_occupant_role_change; ui_room_occupant_affiliation_change = _ui_room_occupant_affiliation_change; ui_room_occupant_role_and_affiliation_change = _ui_room_occupant_role_and_affiliation_change; + ui_redraw_all_room_rosters = _ui_redraw_all_room_rosters; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 4048b3a5..eb610801 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -209,6 +209,7 @@ void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag); void (*ui_show_form_help)(ProfWin *window, DataForm *form); void (*ui_show_form_field_help)(ProfWin *window, DataForm *form, char *tag); void (*ui_show_lines)(ProfWin *window, const gchar** lines); +void (*ui_redraw_all_room_rosters)(void); // contact status functions void (*ui_status_room)(const char * const contact); @@ -292,6 +293,7 @@ void (*cons_show_received_subs)(void); void (*cons_show_sent_subs)(void); void (*cons_alert)(void); void (*cons_theme_setting)(void); +void (*cons_privileges_setting)(void); void (*cons_beep_setting)(void); void (*cons_flash_setting)(void); void (*cons_splash_setting)(void);