diff --git a/command.c b/command.c index 19f982cd..ab868016 100644 --- a/command.c +++ b/command.c @@ -46,6 +46,9 @@ static gboolean _cmd_set_beep(const char * const inp); static gboolean _cmd_set_flash(const char * const inp); static gboolean _cmd_away(const char * const inp); static gboolean _cmd_online(const char * const inp); +static gboolean _cmd_dnd(const char * const inp); +static gboolean _cmd_chat(const char * const inp); +static gboolean _cmd_xa(const char * const inp); static gboolean _cmd_default(const char * const inp); gboolean process_input(char *inp) @@ -106,6 +109,12 @@ static gboolean _handle_command(const char * const command, const char * const i result = _cmd_away(inp); } else if (strcmp(command, "/online") == 0) { result = _cmd_online(inp); + } else if (strcmp(command, "/dnd") == 0) { + result = _cmd_dnd(inp); + } else if (strcmp(command, "/chat") == 0) { + result = _cmd_chat(inp); + } else if (strcmp(command, "/xa") == 0) { + result = _cmd_xa(inp); } else { result = _cmd_default(inp); } @@ -286,6 +295,51 @@ static gboolean _cmd_online(const char * const inp) return TRUE; } +static gboolean _cmd_dnd(const char * const inp) +{ + jabber_conn_status_t conn_status = jabber_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + } else { + jabber_update_presence(PRESENCE_DND); + title_bar_set_status(PRESENCE_DND); + cons_show("Status set to \"dnd\""); + } + + return TRUE; +} + +static gboolean _cmd_chat(const char * const inp) +{ + jabber_conn_status_t conn_status = jabber_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + } else { + jabber_update_presence(PRESENCE_CHAT); + title_bar_set_status(PRESENCE_CHAT); + cons_show("Status set to \"chat\""); + } + + return TRUE; +} + +static gboolean _cmd_xa(const char * const inp) +{ + jabber_conn_status_t conn_status = jabber_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + } else { + jabber_update_presence(PRESENCE_XA); + title_bar_set_status(PRESENCE_XA); + cons_show("Status set to \"xa\""); + } + + return TRUE; +} + static gboolean _cmd_default(const char * const inp) { if (win_in_chat()) { diff --git a/common.h b/common.h index ee87da27..21f55bd0 100644 --- a/common.h +++ b/common.h @@ -35,7 +35,10 @@ typedef enum { typedef enum { PRESENCE_OFFLINE, PRESENCE_ONLINE, - PRESENCE_AWAY + PRESENCE_AWAY, + PRESENCE_DND, + PRESENCE_CHAT, + PRESENCE_XA } jabber_presence_t; #if !GLIB_CHECK_VERSION(2,28,0) diff --git a/jabber.c b/jabber.c index 731b1f35..3dc5a18c 100644 --- a/jabber.c +++ b/jabber.c @@ -189,11 +189,22 @@ void jabber_update_presence(jabber_presence_t status) pres = xmpp_stanza_new(jabber_conn.ctx); xmpp_stanza_set_name(pres, "presence"); - if (status == PRESENCE_AWAY) { + if (status != PRESENCE_ONLINE) { show = xmpp_stanza_new(jabber_conn.ctx); xmpp_stanza_set_name(show, "show"); xmpp_stanza_t *text = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_text(text, "away"); + + if (status == PRESENCE_AWAY) + xmpp_stanza_set_text(text, "away"); + else if (status == PRESENCE_DND) + xmpp_stanza_set_text(text, "dnd"); + else if (status == PRESENCE_CHAT) + xmpp_stanza_set_text(text, "chat"); + else if (status == PRESENCE_XA) + xmpp_stanza_set_text(text, "xa"); + else + xmpp_stanza_set_text(text, "online"); + xmpp_stanza_add_child(show, text); xmpp_stanza_add_child(pres, show); xmpp_stanza_release(text); diff --git a/title_bar.c b/title_bar.c index c487801a..b7eea10f 100644 --- a/title_bar.c +++ b/title_bar.c @@ -104,6 +104,12 @@ static void _title_bar_draw_status() mvwprintw(title_bar, 0, cols - 13, " ...online "); } else if (current_status == PRESENCE_AWAY) { mvwprintw(title_bar, 0, cols - 13, " .....away "); + } else if (current_status == PRESENCE_DND) { + mvwprintw(title_bar, 0, cols - 13, " ......dnd "); + } else if (current_status == PRESENCE_CHAT) { + mvwprintw(title_bar, 0, cols - 13, " .....chat "); + } else if (current_status == PRESENCE_XA) { + mvwprintw(title_bar, 0, cols - 13, " .......xa "); } else { mvwprintw(title_bar, 0, cols - 13, " ..offline "); }