From be2fb1c809c73ccf607fb5bbc6e42578edecd450 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Nov 2012 03:30:27 +0000 Subject: [PATCH] Handle subject from room --- src/jabber.c | 19 +++++++++++++++++-- src/profanity.c | 7 +++++++ src/profanity.h | 2 ++ src/room_chat.c | 17 +++++++++++++++++ src/room_chat.h | 1 + src/stanza.h | 1 + src/ui.h | 2 ++ src/windows.c | 26 ++++++++++++++++++++++++++ 8 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/jabber.c b/src/jabber.c index 7e62a5a8..f390a8ba 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -338,8 +338,22 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza) { char *room = NULL; char *nick = NULL; - + char *message = NULL; + xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); gchar *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + + // handle subject + if (subject != NULL) { + message = xmpp_stanza_get_text(subject); + if (message != NULL) { + room = room_get_room_for_full_jid(room_jid); + prof_handle_room_subject(room, message); + } + + return 1; + } + + // room jid not of form room/nick if (!room_parse_room_jid(room_jid, &room, &nick)) { log_error("Could not parse room jid: %s", room_jid); g_free(room); @@ -348,6 +362,7 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza) return 1; } + // room not active in profanity if (!room_is_active(room_jid)) { log_error("Message recieved for inactive groupchat: %s", room_jid); g_free(room); @@ -356,9 +371,9 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza) return 1; } - char *message = NULL; xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); + if (body != NULL) { message = xmpp_stanza_get_text(body); } diff --git a/src/profanity.c b/src/profanity.c index f7df4f03..2d1561e2 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -199,6 +199,13 @@ prof_handle_room_message(const char * const room_jid, const char * const nick, win_page_off(); } +void +prof_handle_room_subject(const char * const room_jid, const char * const subject) +{ + win_show_room_subject(room_jid, subject); + win_page_off(); +} + void prof_handle_room_roster_complete(const char * const room) { diff --git a/src/profanity.h b/src/profanity.h index 5e9755f4..baf2a6b9 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -40,6 +40,8 @@ void prof_handle_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message); void prof_handle_room_message(const char * const room_jid, const char * const nick, const char * const message); +void prof_handle_room_subject(const char * const room_jid, + const char * const subject); void prof_handle_room_roster_complete(const char * const room); void prof_handle_room_member_online(const char * const room, const char * const nick, const char * const show, const char * const status); diff --git a/src/room_chat.c b/src/room_chat.c index 6dc0f32c..72a4b38e 100644 --- a/src/room_chat.c +++ b/src/room_chat.c @@ -97,6 +97,23 @@ room_get_nick_for_room(const char * const jid) } } +char * +room_get_room_for_full_jid(const char * const jid) +{ + char **tokens = g_strsplit(jid, "/", 0); + char *room; + + if (tokens == NULL || tokens[0] == NULL) { + return NULL; + } else { + room = strdup(tokens[0]); + + g_strfreev(tokens); + + return room; + } +} + gboolean room_parse_room_jid(const char * const room_jid, char **room, char **nick) { diff --git a/src/room_chat.h b/src/room_chat.h index d62383c9..7641fa33 100644 --- a/src/room_chat.h +++ b/src/room_chat.h @@ -29,6 +29,7 @@ void room_join(const char * const jid, const char * const nick); void room_leave(const char * const jid); gboolean room_is_active(const char * const jid); char * room_get_nick_for_room(const char * const jid); +char * room_get_room_for_full_jid(const char * const jid); gboolean room_parse_room_jid(const char * const room_jid, char **room, char **nick); void room_add_to_roster(const char * const jid, const char * const nick); diff --git a/src/stanza.h b/src/stanza.h index 5acb6aee..150ec857 100644 --- a/src/stanza.h +++ b/src/stanza.h @@ -43,6 +43,7 @@ #define STANZA_NAME_ERROR "error" #define STANZA_NAME_PING "ping" #define STANZA_NAME_TEXT "text" +#define STANZA_NAME_SUBJECT "subject" #define STANZA_TYPE_CHAT "chat" #define STANZA_TYPE_GROUPCHAT "groupchat" diff --git a/src/ui.h b/src/ui.h index 5a447f35..26598be8 100644 --- a/src/ui.h +++ b/src/ui.h @@ -113,6 +113,8 @@ void win_show_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message); void win_show_room_message(const char * const room_jid, const char * const nick, const char * const message); +void win_show_room_subject(const char * const room_jid, + const char * const subject); void win_show_room_member_offline(const char * const room, const char * const nick); void win_show_room_member_online(const char * const room, const char * const nick); diff --git a/src/windows.c b/src/windows.c index c3c6486c..b05e2fbc 100644 --- a/src/windows.c +++ b/src/windows.c @@ -563,9 +563,13 @@ win_show_room_roster(const char * const room) GList *roster = room_get_roster(room); if ((roster == NULL) || (g_list_length(roster) == 0)) { + wattron(win, COLOUR_INC); wprintw(win, "You are alone!\n"); + wattroff(win, COLOUR_INC); } else { + wattron(win, COLOUR_INC); wprintw(win, "Room occupants:\n"); + wattroff(win, COLOUR_INC); wattron(win, COLOUR_ONLINE); while (roster != NULL) { @@ -683,6 +687,28 @@ win_show_room_message(const char * const room_jid, const char * const nick, } } +void +win_show_room_subject(const char * const room_jid, const char * const subject) +{ + int win_index = _find_prof_win_index(room_jid); + WINDOW *win = _wins[win_index].win; + + wattron(win, COLOUR_INC); + wprintw(win, "Room subject: "); + wattroff(win, COLOUR_INC); + wprintw(win, "%s\n", subject); + + // currently in groupchat window + if (win_index == _curr_prof_win) { + status_bar_active(win_index); + dirty = TRUE; + + // not currenlty on groupchat window + } else { + status_bar_new(win_index); + } +} + void win_show(const char * const msg) {