From bd3f1d1575830aa4236ea1a3585c9b3c33b32be9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Nov 2012 22:49:01 +0000 Subject: [PATCH] Show message when own nickname changed in chat rooms --- src/jabber.c | 19 +++++++++++++------ src/profanity.c | 8 ++++++++ src/profanity.h | 2 ++ src/room_chat.c | 25 +++++++++++++++++++++++++ src/room_chat.h | 2 ++ src/ui.h | 1 + src/windows.c | 14 ++++++++++++++ 7 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/jabber.c b/src/jabber.c index fc0b7d2f..037f03d9 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -275,8 +275,6 @@ jabber_change_room_nick(const char * const room, const char * const nick) xmpp_send(jabber_conn.conn, presence); xmpp_stanza_release(presence); - room_change_nick(room, nick); - free(full_room_jid); } @@ -711,14 +709,23 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza) // handle self presence if (stanza_is_muc_self_presence(stanza)) { char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); + gboolean nick_change = stanza_is_room_nick_change(stanza); - // left room - if (type != NULL) { - if (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0) { + if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) { + + // leave room if not self nick change + if (nick_change) { + room_set_pending_nick_change(room); + } else { prof_handle_leave_room(room); } - // roster received + // handle self nick change + } else if (room_is_pending_nick_change(room)) { + room_change_nick(room, nick); + prof_handle_room_nick_change(room, nick); + + // handle roster complete } else { prof_handle_room_roster_complete(room); } diff --git a/src/profanity.c b/src/profanity.c index 4ce7b855..21dcb5da 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -310,6 +310,14 @@ prof_handle_room_member_nick_change(const char * const room, win_page_off(); } +void +prof_handle_room_nick_change(const char * const room, + const char * const nick) +{ + win_show_room_nick_change(room, nick); + win_page_off(); +} + static void _create_config_directory(void) { diff --git a/src/profanity.h b/src/profanity.h index 670a0f20..62d73a3f 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -54,5 +54,7 @@ void prof_handle_room_member_offline(const char * const room, void prof_handle_leave_room(const char * const room); void prof_handle_room_member_nick_change(const char * const room, const char * const old_nick, const char * const nick); +void prof_handle_room_nick_change(const char * const room, + const char * const nick); #endif diff --git a/src/room_chat.c b/src/room_chat.c index a81914aa..b72bff83 100644 --- a/src/room_chat.c +++ b/src/room_chat.c @@ -30,6 +30,7 @@ typedef struct _muc_room_t { char *room; char *nick; + gboolean pending_nick_change; GHashTable *roster; GHashTable *nick_changes; gboolean roster_received; @@ -55,10 +56,33 @@ room_join(const char * const room, const char * const nick) new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); new_room->roster_received = FALSE; + new_room->pending_nick_change = FALSE; g_hash_table_insert(rooms, strdup(room), new_room); } +void +room_set_pending_nick_change(const char * const room) +{ + muc_room *chat_room = g_hash_table_lookup(rooms, room); + + if (chat_room != NULL) { + chat_room->pending_nick_change = TRUE; + } +} + +gboolean +room_is_pending_nick_change(const char * const room) +{ + muc_room *chat_room = g_hash_table_lookup(rooms, room); + + if (chat_room != NULL) { + return chat_room->pending_nick_change; + } else { + return FALSE; + } +} + void room_change_nick(const char * const room, const char * const nick) { @@ -67,6 +91,7 @@ room_change_nick(const char * const room, const char * const nick) if (chat_room != NULL) { free(chat_room->nick); chat_room->nick = strdup(nick); + chat_room->pending_nick_change = FALSE; } } diff --git a/src/room_chat.h b/src/room_chat.h index da68e1da..b0bb8db5 100644 --- a/src/room_chat.h +++ b/src/room_chat.h @@ -47,5 +47,7 @@ gboolean room_get_roster_received(const char * const room); void room_remove_from_roster(const char * const room, const char * const nick); char * room_create_full_room_jid(const char * const room, const char * const nick); +void room_set_pending_nick_change(const char * const room); +gboolean room_is_pending_nick_change(const char * const room); #endif diff --git a/src/ui.h b/src/ui.h index f397debb..54658eca 100644 --- a/src/ui.h +++ b/src/ui.h @@ -133,6 +133,7 @@ void win_show_wins(void); int win_in_private_chat(void); void win_show_room_member_nick_change(const char * const room, const char * const old_nick, const char * const nick); +void win_show_room_nick_change(const char * const room, const char * const nick); // console window actions void cons_about(void); diff --git a/src/windows.c b/src/windows.c index 5f05305b..eeefaf29 100644 --- a/src/windows.c +++ b/src/windows.c @@ -735,7 +735,21 @@ win_show_room_member_nick_change(const char * const room, if (win_index == _curr_prof_win) dirty = TRUE; +} +void +win_show_room_nick_change(const char * const room, const char * const nick) +{ + int win_index = _find_prof_win_index(room); + WINDOW *win = _wins[win_index].win; + + _win_show_time(win); + wattron(win, COLOUR_ONLINE); + wprintw(win, "** You are now known as %s\n", nick); + wattroff(win, COLOUR_ONLINE); + + if (win_index == _curr_prof_win) + dirty = TRUE; } void