diff options
author | James Booth <boothj5@gmail.com> | 2012-02-28 01:10:46 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-02-28 01:10:46 +0000 |
commit | 509888c419cf0abb03df83277ebf7085e0427a0d (patch) | |
tree | eb7c53fd25696b0801cbb10fbdcaabe969b5b090 | |
parent | c447e050811f41af28c60683e2fef674c8184bda (diff) | |
download | profani-tty-509888c419cf0abb03df83277ebf7085e0427a0d.tar.gz |
Presence notifications sent to chat windows
-rw-r--r-- | jabber.c | 4 | ||||
-rw-r--r-- | windows.c | 66 | ||||
-rw-r--r-- | windows.h | 2 |
3 files changed, 71 insertions, 1 deletions
diff --git a/jabber.c b/jabber.c index bd42459b..65e80005 100644 --- a/jabber.c +++ b/jabber.c @@ -288,7 +288,7 @@ 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 *short_from = strtok(from, "/"); char *type = xmpp_stanza_get_attribute(stanza, "type"); char *show_str, *status_str; @@ -307,8 +307,10 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn, if (type == NULL) { // online cons_show_contact_online(short_from, show_str, status_str); + win_show_contact_online(short_from, show_str, status_str); } else { // offline cons_show_contact_offline(short_from, show_str, status_str); + win_show_contact_offline(short_from, show_str, status_str); } return 1; diff --git a/windows.c b/windows.c index ed4e705f..fe4af54f 100644 --- a/windows.c +++ b/windows.c @@ -125,6 +125,66 @@ void win_show_outgoing_msg(char *from, char *to, char *message) status_bar_active(win); } +void win_show_contact_online(char *from, char *show, char *status) +{ + // find the chat window for recipient + int i; + for (i = 1; i < 10; i++) + if (strcmp(_wins[i].from, from) == 0) + break; + + // if we found a window + if (i != 10) { + _win_show_time(i); + wattron(_wins[i].win, COLOR_PAIR(2)); + wattron(_wins[i].win, A_BOLD); + + wprintw(_wins[i].win, "++ %s", from); + + if (show != NULL) + wprintw(_wins[i].win, " is %s", show); + else + wprintw(_wins[i].win, " is online"); + + if (status != NULL) + wprintw(_wins[i].win, ", \"%s\"", status); + + wprintw(_wins[i].win, "\n"); + + wattroff(_wins[i].win, COLOR_PAIR(2)); + wattroff(_wins[i].win, A_BOLD); + } +} + +void win_show_contact_offline(char *from, char *show, char *status) +{ + // find the chat window for recipient + int i; + for (i = 1; i < 10; i++) + if (strcmp(_wins[i].from, from) == 0) + break; + + // if we found a window + if (i != 10) { + _win_show_time(i); + wattron(_wins[i].win, COLOR_PAIR(5)); + + wprintw(_wins[i].win, "-- %s", from); + + if (show != NULL) + wprintw(_wins[i].win, " is %s", show); + else + wprintw(_wins[i].win, " is offline"); + + if (status != NULL) + wprintw(_wins[i].win, ", \"%s\"", status); + + wprintw(_wins[i].win, "\n"); + + wattroff(_wins[i].win, COLOR_PAIR(5)); + } +} + void cons_help(void) { _win_show_time(0); @@ -210,6 +270,9 @@ void cons_show_contact_online(char *from, char *show, char *status) if (show != NULL) wprintw(_wins[0].win, " is %s", show); + else + wprintw(_wins[0].win, " is online"); + if (status != NULL) wprintw(_wins[0].win, ", \"%s\"", status); @@ -228,6 +291,9 @@ void cons_show_contact_offline(char *from, char *show, char *status) if (show != NULL) wprintw(_wins[0].win, " is %s", show); + else + wprintw(_wins[0].win, " is offline"); + if (status != NULL) wprintw(_wins[0].win, ", \"%s\"", status); diff --git a/windows.h b/windows.h index 010f8003..d68b238c 100644 --- a/windows.h +++ b/windows.h @@ -54,6 +54,8 @@ char *win_get_recipient(void); void win_show_incomming_msg(char *from, char *message); void win_show_outgoing_msg(char *from, char *to, char *message); void win_handle_switch(int *ch); +void win_show_contact_online(char *from, char *show, char *status); +void win_show_contact_offline(char *from, char *show, char *status); // console window actions void cons_help(void); |