mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Allow message with status updates
This commit is contained in:
parent
240f7badb0
commit
70310bb5af
37
command.c
37
command.c
@ -51,7 +51,7 @@ static gboolean _cmd_chat(const char * const inp);
|
||||
static gboolean _cmd_xa(const char * const inp);
|
||||
static gboolean _cmd_default(const char * const inp);
|
||||
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)
|
||||
{
|
||||
@ -269,31 +269,31 @@ static gboolean _cmd_set_flash(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;
|
||||
}
|
||||
|
||||
static gboolean _cmd_online(const char * const inp)
|
||||
{
|
||||
_update_presence(PRESENCE_ONLINE, "online");
|
||||
_update_presence(PRESENCE_ONLINE, "online", inp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean _cmd_dnd(const char * const inp)
|
||||
{
|
||||
_update_presence(PRESENCE_DND, "dnd");
|
||||
_update_presence(PRESENCE_DND, "dnd", inp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean _cmd_chat(const char * const inp)
|
||||
{
|
||||
_update_presence(PRESENCE_CHAT, "chat");
|
||||
_update_presence(PRESENCE_CHAT, "chat", inp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean _cmd_xa(const char * const inp)
|
||||
{
|
||||
_update_presence(PRESENCE_XA, "xa");
|
||||
_update_presence(PRESENCE_XA, "xa", inp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -312,17 +312,32 @@ static gboolean _cmd_default(const char * const inp)
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
} else {
|
||||
jabber_update_presence(presence);
|
||||
jabber_update_presence(presence, msg);
|
||||
title_bar_set_status(presence);
|
||||
char str[16 + strlen(show) + 1];
|
||||
sprintf(str, "Status set to \"%s\"", show);
|
||||
cons_show(str);
|
||||
if (msg != NULL) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
15
jabber.c
15
jabber.c
@ -180,7 +180,7 @@ void jabber_roster_request(void)
|
||||
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;
|
||||
|
||||
@ -211,6 +211,19 @@ void jabber_update_presence(jabber_presence_t status)
|
||||
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_stanza_release(pres);
|
||||
}
|
||||
|
2
jabber.h
2
jabber.h
@ -35,6 +35,6 @@ void jabber_roster_request(void);
|
||||
void jabber_process_events(void);
|
||||
void jabber_send(const char * const msg, const char * const recipient);
|
||||
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
|
||||
|
23
windows.c
23
windows.c
@ -263,22 +263,28 @@ void win_disconnected(void)
|
||||
void cons_help(void)
|
||||
{
|
||||
cons_show("");
|
||||
cons_show("Commands:");
|
||||
cons_show("Basic Commands:");
|
||||
cons_show("");
|
||||
cons_show("/help : This help.");
|
||||
cons_show("/connect user@host : Login to jabber.");
|
||||
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("/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("/flash <on/off> : Enable/disable screen flash notification");
|
||||
cons_show("/close : Close a chat window.");
|
||||
cons_show("/quit : Quit Profanity.");
|
||||
cons_show("/away : Set status to away.");
|
||||
cons_show("/online : Set status to online.");
|
||||
cons_show("/dnd : Set status to dnd (do not disturb).");
|
||||
cons_show("/chat : Set status to chat (available for chat).");
|
||||
cons_show("/xa : Set status to xa (extended away).");
|
||||
cons_show("");
|
||||
cons_show("Status changes (msg is optional):");
|
||||
cons_show("");
|
||||
cons_show("/away <msg> : Set status to away.");
|
||||
cons_show("/online <msg> : Set status to online.");
|
||||
cons_show("/dnd <msg> : Set status to dnd (do not disturb).");
|
||||
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("Keys:");
|
||||
cons_show("");
|
||||
@ -288,6 +294,7 @@ void cons_help(void)
|
||||
cons_show("LEFT, RIGHT : Edit current input.");
|
||||
cons_show("TAB : Autocomplete recipient.");
|
||||
cons_show("PAGE UP, PAGE DOWN : Page the chat window.");
|
||||
cons_show("");
|
||||
|
||||
if (_curr_prof_win == 0)
|
||||
dirty = TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user