diff --git a/jabber.c b/jabber.c index 41bd9a16..dc2b1f18 100644 --- a/jabber.c +++ b/jabber.c @@ -67,6 +67,9 @@ static int _jabber_message_handler(xmpp_conn_t * const conn, static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _jabber_presence_handler(xmpp_conn_t * const conn, + xmpp_stanza_t * const stanza, void * const userdata); + static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata); void jabber_init(int disable_tls) @@ -199,6 +202,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn, xmpp_stanza_t* pres; xmpp_handler_add(conn, _jabber_message_handler, NULL, "message", NULL, ctx); + xmpp_handler_add(conn, _jabber_presence_handler, NULL, "presence", NULL, ctx); xmpp_id_handler_add(conn, _roster_handler, "roster", ctx); xmpp_timed_handler_add(conn, _ping_timed_handler, PING_INTERVAL, ctx); @@ -206,7 +210,6 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn, xmpp_stanza_set_name(pres, "presence"); xmpp_send(conn, pres); xmpp_stanza_release(pres); - jabber_roster_request(); jabber_conn.conn_status = JABBER_CONNECTED; } else { @@ -278,3 +281,57 @@ static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata) return 1; } + +/* + + + away + I'm not here right now + + + + + Lack of attribute means online. + +*/ +static int _jabber_presence_handler(xmpp_conn_t * const conn, + xmpp_stanza_t * const stanza, void * const userdata) +{ + char *from = xmpp_stanza_get_attribute(stanza, "from"); + char *short_from = strtok(from, "@"); + char *type = xmpp_stanza_get_attribute(stanza, "type"); + + + if (type == NULL) { // online + xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, "show"); + if (show != NULL) { + char *show_str = xmpp_stanza_get_text(show); + xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, "status"); + + if (status != NULL) { + char *status_str = xmpp_stanza_get_text(status); + + if (show_str != NULL) + cons_show_contact_online(short_from, show_str, status_str); + } + } + } else { // offline + xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, "show"); + if (show != NULL) { + char *show_str = xmpp_stanza_get_text(show); + xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, "status"); + + if (status != NULL) { + char *status_str = xmpp_stanza_get_text(status); + + if (show_str != NULL) + cons_show_contact_offline(short_from, show_str, status_str); + } + } + } + + return 1; +} + + diff --git a/windows.c b/windows.c index c7a6fcd1..f8144a39 100644 --- a/windows.c +++ b/windows.c @@ -51,6 +51,7 @@ void gui_init(void) init_pair(4, COLOR_CYAN, COLOR_BLUE); init_pair(5, COLOR_CYAN, COLOR_BLACK); init_pair(6, COLOR_RED, COLOR_BLACK); + init_pair(7, COLOR_MAGENTA, COLOR_BLACK); } refresh(); @@ -203,6 +204,32 @@ void cons_bad_message(void) cons_show("Usage: /msg user@host message"); } +void cons_show_contact_online(char *from, char *show, char *status) +{ + _win_show_time(0); + wattron(_wins[0].win, COLOR_PAIR(2)); + + if (status != NULL) + wprintw(_wins[0].win, "+ %s is %s, \"%s\"\n", from, show, status); + else + wprintw(_wins[0].win, "+ %s is %s\n", from, show); + + wattroff(_wins[0].win, COLOR_PAIR(2)); +} + +void cons_show_contact_offline(char *from, char *show, char *status) +{ + _win_show_time(0); + wattron(_wins[0].win, COLOR_PAIR(7)); + + if (status != NULL) + wprintw(_wins[0].win, "- %s is %s, \"%s\"\n", from, show, status); + else + wprintw(_wins[0].win, "- %s is %s\n", from, show); + + wattroff(_wins[0].win, COLOR_PAIR(7)); +} + void win_handle_switch(int *ch) { if (*ch == KEY_F(1)) { diff --git a/windows.h b/windows.h index 1a59d79e..010f8003 100644 --- a/windows.h +++ b/windows.h @@ -66,6 +66,8 @@ void cons_show(char *cmd); void cons_good_show(char *cmd); void cons_bad_show(char *cmd); void cons_highlight_show(char *cmd); +void cons_show_contact_online(char *from, char *show, char *status); +void cons_show_contact_offline(char *from, char *show, char *status); // status bar actions void status_bar_refresh(void);