From 6b6ed6a93eab0809d32a95cc7e879b5378bf7678 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 12 Oct 2014 02:10:46 +0100 Subject: [PATCH] Show role/affiliation on room join and on change --- TODO_ROLES | 2 -- src/server_events.c | 16 +++++++++++++--- src/ui/core.c | 28 ++++++++++++++++++++++++++++ src/ui/ui.h | 2 ++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/TODO_ROLES b/TODO_ROLES index 74cda2ee..57b564b6 100644 --- a/TODO_ROLES +++ b/TODO_ROLES @@ -1,4 +1,2 @@ -Show role/affiliation on join -Show role/affiliation on update Check all commands from private conversations Test all freetext args diff --git a/src/server_events.c b/src/server_events.c index 5b4f2571..0ff5514e 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -677,6 +677,10 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea const char * const status) { muc_roster_add(room, nick, jid, role, affiliation, show, status); + char *old_role = muc_role_str(room); + char *old_affiliation = muc_affiliation_str(room); + muc_set_role(room, role); + muc_set_affiliation(room, affiliation); // handle self nick change if (muc_nick_change_pending(room)) { @@ -718,10 +722,16 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea muc_set_requires_config(room, TRUE); ui_room_requires_config(room); } - } - muc_set_role(room, role); - muc_set_affiliation(room, affiliation); + // check for change in role/affiliation + } else { + if (g_strcmp0(role, old_role) != 0) { + ui_room_role_change(room, role); + } + if (g_strcmp0(affiliation, old_affiliation) != 0) { + ui_room_affiliation_change(room, affiliation); + } + } ui_muc_roster(room); } diff --git a/src/ui/core.c b/src/ui/core.c index 016a61e7..24461ad3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1370,6 +1370,18 @@ _ui_room_join(const char * const room, gboolean focus) window = wins_new(room, WIN_MUC); } + 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); + } + win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", ""); + num = wins_get_num(window); if (focus) { @@ -1382,6 +1394,20 @@ _ui_room_join(const char * const room, gboolean focus) } } +static void +_ui_room_role_change(const char * const room, const char * const role) +{ + ProfWin *window = wins_get_by_recipient(room); + win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Your role has been changed to: %s", role); +} + +static void +_ui_room_affiliation_change(const char * const room, const char * const affiliation) +{ + ProfWin *window = wins_get_by_recipient(room); + win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Your affiliation has been changed to: %s", affiliation); +} + static void _ui_handle_room_info_error(const char * const room, const char * const error) { @@ -3102,5 +3128,7 @@ ui_init_module(void) ui_muc_roster = _ui_muc_roster; ui_room_show_occupants = _ui_room_show_occupants; ui_room_hide_occupants = _ui_room_hide_occupants; + ui_room_role_change = _ui_room_role_change; + ui_room_affiliation_change = _ui_room_affiliation_change; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 46e8fb4e..9781d1b6 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -130,6 +130,8 @@ void (*ui_recipient_gone)(const char * const barejid); void (*ui_outgoing_msg)(const char * const from, const char * const to, const char * const message); void (*ui_room_join)(const char * const room, gboolean focus); +void (*ui_room_role_change)(const char * const room, const char * const role); +void (*ui_room_affiliation_change)(const char * const room, const char * const affiliation); void (*ui_room_roster)(const char * const room, GList *roster, const char * const presence); void (*ui_room_history)(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message);