1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Allow message with status updates

This commit is contained in:
James Booth 2012-05-28 23:40:11 +01:00
parent 240f7badb0
commit 70310bb5af
4 changed files with 56 additions and 21 deletions

View File

@ -51,7 +51,7 @@ static gboolean _cmd_chat(const char * const inp);
static gboolean _cmd_xa(const char * const inp); static gboolean _cmd_xa(const char * const inp);
static gboolean _cmd_default(const char * const inp); static gboolean _cmd_default(const char * const inp);
static void _update_presence(const jabber_presence_t presence, static void _update_presence(const jabber_presence_t presence,
const char * const show); const char * const show, const char * const inp);
gboolean process_input(char *inp) gboolean process_input(char *inp)
{ {
@ -269,31 +269,31 @@ static gboolean _cmd_set_flash(const char * const inp)
static gboolean _cmd_away(const char * const inp) static gboolean _cmd_away(const char * const inp)
{ {
_update_presence(PRESENCE_AWAY, "away"); _update_presence(PRESENCE_AWAY, "away", inp);
return TRUE; return TRUE;
} }
static gboolean _cmd_online(const char * const inp) static gboolean _cmd_online(const char * const inp)
{ {
_update_presence(PRESENCE_ONLINE, "online"); _update_presence(PRESENCE_ONLINE, "online", inp);
return TRUE; return TRUE;
} }
static gboolean _cmd_dnd(const char * const inp) static gboolean _cmd_dnd(const char * const inp)
{ {
_update_presence(PRESENCE_DND, "dnd"); _update_presence(PRESENCE_DND, "dnd", inp);
return TRUE; return TRUE;
} }
static gboolean _cmd_chat(const char * const inp) static gboolean _cmd_chat(const char * const inp)
{ {
_update_presence(PRESENCE_CHAT, "chat"); _update_presence(PRESENCE_CHAT, "chat", inp);
return TRUE; return TRUE;
} }
static gboolean _cmd_xa(const char * const inp) static gboolean _cmd_xa(const char * const inp)
{ {
_update_presence(PRESENCE_XA, "xa"); _update_presence(PRESENCE_XA, "xa", inp);
return TRUE; return TRUE;
} }
@ -312,17 +312,32 @@ static gboolean _cmd_default(const char * const inp)
} }
static void _update_presence(const jabber_presence_t presence, static void _update_presence(const jabber_presence_t presence,
const char * const show) const char * const show, const char * const inp)
{ {
char *msg;
if (strlen(inp) > strlen(show) + 2) {
msg = strndup(inp+(strlen(show) + 2), strlen(inp)-(strlen(show) + 2));
} else {
msg = NULL;
}
jabber_conn_status_t conn_status = jabber_connection_status(); jabber_conn_status_t conn_status = jabber_connection_status();
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
} else { } else {
jabber_update_presence(presence); jabber_update_presence(presence, msg);
title_bar_set_status(presence); title_bar_set_status(presence);
char str[16 + strlen(show) + 1]; if (msg != NULL) {
sprintf(str, "Status set to \"%s\"", show); char str[14 + strlen(show) + 3 + strlen(msg) + 2];
sprintf(str, "Status set to %s, \"%s\"", show, msg);
cons_show(str);
free(msg);
} else {
char str[14 + strlen(show) + 1];
sprintf(str, "Status set to %s", show);
cons_show(str); cons_show(str);
} }
} }
}

View File

@ -180,7 +180,7 @@ void jabber_roster_request(void)
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
} }
void jabber_update_presence(jabber_presence_t status) void jabber_update_presence(jabber_presence_t status, const char * const msg)
{ {
jabber_conn.presence = status; jabber_conn.presence = status;
@ -211,6 +211,19 @@ void jabber_update_presence(jabber_presence_t status)
xmpp_stanza_release(show); xmpp_stanza_release(show);
} }
if (msg != NULL) {
xmpp_stanza_t *status = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(status, "status");
xmpp_stanza_t *text = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_text(text, msg);
xmpp_stanza_add_child(status, text);
xmpp_stanza_add_child(pres, status);
xmpp_stanza_release(text);
xmpp_stanza_release(status);
}
xmpp_send(jabber_conn.conn, pres); xmpp_send(jabber_conn.conn, pres);
xmpp_stanza_release(pres); xmpp_stanza_release(pres);
} }

View File

@ -35,6 +35,6 @@ void jabber_roster_request(void);
void jabber_process_events(void); void jabber_process_events(void);
void jabber_send(const char * const msg, const char * const recipient); void jabber_send(const char * const msg, const char * const recipient);
const char * jabber_get_jid(void); const char * jabber_get_jid(void);
void jabber_update_presence(jabber_presence_t status); void jabber_update_presence(jabber_presence_t status, const char * const msg);
#endif #endif

View File

@ -263,22 +263,28 @@ void win_disconnected(void)
void cons_help(void) void cons_help(void)
{ {
cons_show(""); cons_show("");
cons_show("Commands:"); cons_show("Basic Commands:");
cons_show(""); cons_show("");
cons_show("/help : This help."); cons_show("/help : This help.");
cons_show("/connect user@host : Login to jabber."); cons_show("/connect user@host : Login to jabber.");
cons_show("/msg user@host mesg : Send mesg to user."); cons_show("/msg user@host mesg : Send mesg to user.");
cons_show("/close : Close a chat window.");
cons_show("/who : Find out who is online."); cons_show("/who : Find out who is online.");
cons_show("/ros : List all contacts."); cons_show("/ros : List all contacts.");
cons_show("/quit : Quit Profanity.");
cons_show("");
cons_show("Settings:");
cons_show("");
cons_show("/beep <on/off> : Enable/disable sound notification"); cons_show("/beep <on/off> : Enable/disable sound notification");
cons_show("/flash <on/off> : Enable/disable screen flash notification"); cons_show("/flash <on/off> : Enable/disable screen flash notification");
cons_show("/close : Close a chat window."); cons_show("");
cons_show("/quit : Quit Profanity."); cons_show("Status changes (msg is optional):");
cons_show("/away : Set status to away."); cons_show("");
cons_show("/online : Set status to online."); cons_show("/away <msg> : Set status to away.");
cons_show("/dnd : Set status to dnd (do not disturb)."); cons_show("/online <msg> : Set status to online.");
cons_show("/chat : Set status to chat (available for chat)."); cons_show("/dnd <msg> : Set status to dnd (do not disturb).");
cons_show("/xa : Set status to xa (extended away)."); cons_show("/chat <msg> : Set status to chat (available for chat).");
cons_show("/xa <msg> : Set status to xa (extended away).");
cons_show(""); cons_show("");
cons_show("Keys:"); cons_show("Keys:");
cons_show(""); cons_show("");
@ -288,6 +294,7 @@ void cons_help(void)
cons_show("LEFT, RIGHT : Edit current input."); cons_show("LEFT, RIGHT : Edit current input.");
cons_show("TAB : Autocomplete recipient."); cons_show("TAB : Autocomplete recipient.");
cons_show("PAGE UP, PAGE DOWN : Page the chat window."); cons_show("PAGE UP, PAGE DOWN : Page the chat window.");
cons_show("");
if (_curr_prof_win == 0) if (_curr_prof_win == 0)
dirty = TRUE; dirty = TRUE;