From 2f6361a57856afc022d9f06e6b7bd7d66b69459b Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 5 Nov 2012 21:36:32 +0000 Subject: [PATCH] Handle room presence notifications --- src/command.c | 2 +- src/jabber.c | 7 ++++++- src/room_chat.c | 14 ++++++++++++++ src/room_chat.h | 1 + src/ui.h | 4 ++++ src/windows.c | 27 +++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index e3ecdceb..35fe72bb 100644 --- a/src/command.c +++ b/src/command.c @@ -1014,8 +1014,8 @@ _cmd_join(const char * const inp, struct cmd_help_t help) strcpy(jid_cpy, jid); nick = strdup(strtok(jid_cpy, "@")); } - jabber_join(room_jid, nick); + win_join_chat(room_jid, nick); } } diff --git a/src/jabber.c b/src/jabber.c index 07d601fb..776a31fd 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -605,7 +605,12 @@ _presence_handler(xmpp_conn_t * const conn, char *from = xmpp_stanza_get_attribute(stanza, "from"); if (room_jid_is_room_chat(from)) { - cons_show("CHAT ROOM PRESENCE RECIEVED"); + char **tokens = g_strsplit(from, "/", 0); + char *room_jid = tokens[0]; + char *nick = tokens[1]; + if (strcmp(room_get_nick_for_room(room_jid), nick) != 0) { + win_show_chat_room_member(room_jid, nick); + } } else { char *short_from = strtok(from, "/"); char *type = xmpp_stanza_get_attribute(stanza, "type"); diff --git a/src/room_chat.c b/src/room_chat.c index ffaf9faf..710cc8cb 100644 --- a/src/room_chat.c +++ b/src/room_chat.c @@ -58,3 +58,17 @@ room_jid_is_room_chat(const char * const jid) } +char * +room_get_nick_for_room(const char * const jid) +{ + GSList *current = rooms; + while (current != NULL) { + muc_room *room = current->data; + if (strcmp(jid, room->jid) == 0) { + return room->nick; + } + current = g_slist_next(current); + } + + return NULL; +} diff --git a/src/room_chat.h b/src/room_chat.h index 1593cbe8..a6ceb4a0 100644 --- a/src/room_chat.h +++ b/src/room_chat.h @@ -24,3 +24,4 @@ void room_join(const char * const jid, const char * const nick); gboolean room_jid_is_room_chat(const char * const jid); +char * room_get_nick_for_room(const char * const jid); diff --git a/src/ui.h b/src/ui.h index 2c60428d..c8e44cee 100644 --- a/src/ui.h +++ b/src/ui.h @@ -103,6 +103,10 @@ void win_show(const char * const msg); void win_bad_show(const char * const msg); void win_remind(void); +void win_join_chat(const char * const room_jid, const char * const nick); +void win_show_chat_room_member(const char * const room_jid, + const char * const nick); + // console window actions void cons_about(void); void cons_help(void); diff --git a/src/windows.c b/src/windows.c index cda57fa8..a4308454 100644 --- a/src/windows.c +++ b/src/windows.c @@ -470,6 +470,33 @@ win_show_outgoing_msg(const char * const from, const char * const to, _win_switch_if_active(win_index); } +void +win_join_chat(const char * const room_jid, const char * const nick) +{ + int win_index = _find_prof_win_index(room_jid); + + // create new window + if (win_index == NUM_WINS) { + win_index = _new_prof_win(room_jid); + } + + _win_switch_if_active(win_index); +} + +void +win_show_chat_room_member(const char * const room_jid, const char * const nick) +{ + int win_index = _find_prof_win_index(room_jid); + WINDOW *win = _wins[win_index].win; + + wattron(win, COLOUR_ONLINE); + wprintw(win, "%s\n", nick); + wattroff(win, COLOUR_ONLINE); + + if (win_index == _curr_prof_win) + dirty = TRUE; +} + void win_show(const char * const msg) {