1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Show message when own nickname changed in chat rooms

This commit is contained in:
James Booth 2012-11-18 22:49:01 +00:00
parent c6b07533c9
commit bd3f1d1575
7 changed files with 65 additions and 6 deletions

View File

@ -275,8 +275,6 @@ jabber_change_room_nick(const char * const room, const char * const nick)
xmpp_send(jabber_conn.conn, presence); xmpp_send(jabber_conn.conn, presence);
xmpp_stanza_release(presence); xmpp_stanza_release(presence);
room_change_nick(room, nick);
free(full_room_jid); free(full_room_jid);
} }
@ -711,14 +709,23 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza)
// handle self presence // handle self presence
if (stanza_is_muc_self_presence(stanza)) { if (stanza_is_muc_self_presence(stanza)) {
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
gboolean nick_change = stanza_is_room_nick_change(stanza);
// left room if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) {
if (type != NULL) {
if (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); 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 { } else {
prof_handle_room_roster_complete(room); prof_handle_room_roster_complete(room);
} }

View File

@ -310,6 +310,14 @@ prof_handle_room_member_nick_change(const char * const room,
win_page_off(); 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 static void
_create_config_directory(void) _create_config_directory(void)
{ {

View File

@ -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_leave_room(const char * const room);
void prof_handle_room_member_nick_change(const char * const room, void prof_handle_room_member_nick_change(const char * const room,
const char * const old_nick, const char * const nick); const char * const old_nick, const char * const nick);
void prof_handle_room_nick_change(const char * const room,
const char * const nick);
#endif #endif

View File

@ -30,6 +30,7 @@
typedef struct _muc_room_t { typedef struct _muc_room_t {
char *room; char *room;
char *nick; char *nick;
gboolean pending_nick_change;
GHashTable *roster; GHashTable *roster;
GHashTable *nick_changes; GHashTable *nick_changes;
gboolean roster_received; 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, new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, g_free); g_free, g_free);
new_room->roster_received = FALSE; new_room->roster_received = FALSE;
new_room->pending_nick_change = FALSE;
g_hash_table_insert(rooms, strdup(room), new_room); 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 void
room_change_nick(const char * const room, const char * const nick) 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) { if (chat_room != NULL) {
free(chat_room->nick); free(chat_room->nick);
chat_room->nick = strdup(nick); chat_room->nick = strdup(nick);
chat_room->pending_nick_change = FALSE;
} }
} }

View File

@ -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); void room_remove_from_roster(const char * const room, const char * const nick);
char * room_create_full_room_jid(const char * const room, char * room_create_full_room_jid(const char * const room,
const char * const nick); 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 #endif

View File

@ -133,6 +133,7 @@ void win_show_wins(void);
int win_in_private_chat(void); int win_in_private_chat(void);
void win_show_room_member_nick_change(const char * const room, void win_show_room_member_nick_change(const char * const room,
const char * const old_nick, const char * const nick); 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 // console window actions
void cons_about(void); void cons_about(void);

View File

@ -735,7 +735,21 @@ win_show_room_member_nick_change(const char * const room,
if (win_index == _curr_prof_win) if (win_index == _curr_prof_win)
dirty = TRUE; 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 void