mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added presence notifications
Turned off roster request on connect
This commit is contained in:
parent
b512f3b8ff
commit
02ba1dafb6
59
jabber.c
59
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,
|
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata);
|
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);
|
static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata);
|
||||||
|
|
||||||
void jabber_init(int disable_tls)
|
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_stanza_t* pres;
|
||||||
xmpp_handler_add(conn, _jabber_message_handler, NULL, "message", NULL, ctx);
|
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_id_handler_add(conn, _roster_handler, "roster", ctx);
|
||||||
xmpp_timed_handler_add(conn, _ping_timed_handler, PING_INTERVAL, 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_stanza_set_name(pres, "presence");
|
||||||
xmpp_send(conn, pres);
|
xmpp_send(conn, pres);
|
||||||
xmpp_stanza_release(pres);
|
xmpp_stanza_release(pres);
|
||||||
jabber_roster_request();
|
|
||||||
jabber_conn.conn_status = JABBER_CONNECTED;
|
jabber_conn.conn_status = JABBER_CONNECTED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -278,3 +281,57 @@ static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
<presence to="james.booth@framework" from="stephen.rank@framework/framework.corelogic.local">
|
||||||
|
<show>away</show>
|
||||||
|
<status>I'm not here right now</status>
|
||||||
|
<c hash="sha-1" xmlns="http://jabber.org/protocol/caps"
|
||||||
|
ver="I22W7CegORwdbnu0ZiQwGpxr0Go=" node="http://pidgin.im/"/>
|
||||||
|
<x xmlns="vcard-temp:x:update"><photo/></x>
|
||||||
|
</presence>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
27
windows.c
27
windows.c
@ -51,6 +51,7 @@ void gui_init(void)
|
|||||||
init_pair(4, COLOR_CYAN, COLOR_BLUE);
|
init_pair(4, COLOR_CYAN, COLOR_BLUE);
|
||||||
init_pair(5, COLOR_CYAN, COLOR_BLACK);
|
init_pair(5, COLOR_CYAN, COLOR_BLACK);
|
||||||
init_pair(6, COLOR_RED, COLOR_BLACK);
|
init_pair(6, COLOR_RED, COLOR_BLACK);
|
||||||
|
init_pair(7, COLOR_MAGENTA, COLOR_BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
@ -203,6 +204,32 @@ void cons_bad_message(void)
|
|||||||
cons_show("Usage: /msg user@host message");
|
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)
|
void win_handle_switch(int *ch)
|
||||||
{
|
{
|
||||||
if (*ch == KEY_F(1)) {
|
if (*ch == KEY_F(1)) {
|
||||||
|
@ -66,6 +66,8 @@ void cons_show(char *cmd);
|
|||||||
void cons_good_show(char *cmd);
|
void cons_good_show(char *cmd);
|
||||||
void cons_bad_show(char *cmd);
|
void cons_bad_show(char *cmd);
|
||||||
void cons_highlight_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
|
// status bar actions
|
||||||
void status_bar_refresh(void);
|
void status_bar_refresh(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user