1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Refactored sending chat states

This commit is contained in:
James Booth 2012-11-06 23:03:05 +00:00
parent 92ae93de33
commit 8beca3cbf7

View File

@ -53,6 +53,7 @@ static void _xmpp_file_logger(void * const userdata,
static xmpp_log_t * _xmpp_get_file_logger(); static xmpp_log_t * _xmpp_get_file_logger();
static void _jabber_roster_request(void); static void _jabber_roster_request(void);
void _jabber_send_state(const char * const recipient, const char * const state);
// XMPP event handlers // XMPP event handlers
static void _connection_handler(xmpp_conn_t * const conn, static void _connection_handler(xmpp_conn_t * const conn,
@ -207,88 +208,28 @@ jabber_send_groupchat(const char * const msg, const char * const recipient)
free(encoded_xml); free(encoded_xml);
} }
void
jabber_send_inactive(const char * const recipient)
{
xmpp_stanza_t *message, *inactive;
message = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(message, "message");
xmpp_stanza_set_type(message, "chat");
xmpp_stanza_set_attribute(message, "to", recipient);
inactive = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(inactive, "inactive");
xmpp_stanza_set_ns(inactive, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(message, inactive);
xmpp_send(jabber_conn.conn, message);
xmpp_stanza_release(message);
chat_session_set_sent(recipient);
}
void void
jabber_send_composing(const char * const recipient) jabber_send_composing(const char * const recipient)
{ {
xmpp_stanza_t *message, *composing; _jabber_send_state(recipient, "composing");
message = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(message, "message");
xmpp_stanza_set_type(message, "chat");
xmpp_stanza_set_attribute(message, "to", recipient);
composing = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(composing, "composing");
xmpp_stanza_set_ns(composing, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(message, composing);
xmpp_send(jabber_conn.conn, message);
xmpp_stanza_release(message);
chat_session_set_sent(recipient);
} }
void void
jabber_send_paused(const char * const recipient) jabber_send_paused(const char * const recipient)
{ {
xmpp_stanza_t *message, *paused; _jabber_send_state(recipient, "paused");
}
message = xmpp_stanza_new(jabber_conn.ctx); void
xmpp_stanza_set_name(message, "message"); jabber_send_inactive(const char * const recipient)
xmpp_stanza_set_type(message, "chat"); {
xmpp_stanza_set_attribute(message, "to", recipient); _jabber_send_state(recipient, "inactive");
paused = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(paused, "paused");
xmpp_stanza_set_ns(paused, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(message, paused);
xmpp_send(jabber_conn.conn, message);
xmpp_stanza_release(message);
chat_session_set_sent(recipient);
} }
void void
jabber_send_gone(const char * const recipient) jabber_send_gone(const char * const recipient)
{ {
xmpp_stanza_t *message, *gone; _jabber_send_state(recipient, "gone");
message = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(message, "message");
xmpp_stanza_set_type(message, "chat");
xmpp_stanza_set_attribute(message, "to", recipient);
gone = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(gone, "gone");
xmpp_stanza_set_ns(gone, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(message, gone);
xmpp_send(jabber_conn.conn, message);
xmpp_stanza_release(message);
chat_session_set_sent(recipient);
} }
void void
@ -768,3 +709,23 @@ _xmpp_get_file_logger()
return file_log; return file_log;
} }
void
_jabber_send_state(const char * const recipient, const char * const state)
{
xmpp_stanza_t *message, *chat_state;
message = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(message, "message");
xmpp_stanza_set_type(message, "chat");
xmpp_stanza_set_attribute(message, "to", recipient);
chat_state = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(chat_state, state);
xmpp_stanza_set_ns(chat_state, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(message, chat_state);
xmpp_send(jabber_conn.conn, message);
xmpp_stanza_release(message);
chat_session_set_sent(recipient);
}