1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Create chat session on send if none exists

This commit is contained in:
James Booth 2012-10-30 01:50:39 +00:00
parent d339004f55
commit bee708c9d2
3 changed files with 25 additions and 5 deletions

View File

@ -52,6 +52,18 @@ chat_sessions_clear(void)
g_hash_table_remove_all(sessions); g_hash_table_remove_all(sessions);
} }
gboolean
chat_session_exists(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
if (session != NULL) {
return TRUE;
} else {
return FALSE;
}
}
void void
chat_session_start(const char * const recipient, gboolean recipient_supports) chat_session_start(const char * const recipient, gboolean recipient_supports)
{ {

View File

@ -31,6 +31,7 @@ void chat_sessions_init(void);
void chat_sessions_clear(void); void chat_sessions_clear(void);
void chat_session_start(const char * const recipient, void chat_session_start(const char * const recipient,
gboolean recipient_supports); gboolean recipient_supports);
gboolean chat_session_exists(const char * const recipient);
void chat_session_end(const char * const recipient); void chat_session_end(const char * const recipient);
gboolean chat_session_recipient_supports(const char * const recipient); gboolean chat_session_recipient_supports(const char * const recipient);

View File

@ -137,16 +137,16 @@ jabber_process_events(void)
void void
jabber_send(const char * const msg, const char * const recipient) jabber_send(const char * const msg, const char * const recipient)
{ {
if (!chat_session_exists(recipient)) {
chat_session_start(recipient, TRUE);
}
char *coded_msg = str_replace(msg, "&", "&"); char *coded_msg = str_replace(msg, "&", "&");
char *coded_msg2 = str_replace(coded_msg, "<", "&lt;"); char *coded_msg2 = str_replace(coded_msg, "<", "&lt;");
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;"); char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
xmpp_stanza_t *reply, *body, *text, *active; xmpp_stanza_t *reply, *body, *text, *active;
active = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(active, "active");
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates");
reply = xmpp_stanza_new(jabber_conn.ctx); reply = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(reply, "message"); xmpp_stanza_set_name(reply, "message");
xmpp_stanza_set_type(reply, "chat"); xmpp_stanza_set_type(reply, "chat");
@ -157,7 +157,14 @@ jabber_send(const char * const msg, const char * const recipient)
text = xmpp_stanza_new(jabber_conn.ctx); text = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_text(text, coded_msg3); xmpp_stanza_set_text(text, coded_msg3);
if (chat_session_recipient_supports(recipient)) {
active = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(active, "active");
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(reply, active); xmpp_stanza_add_child(reply, active);
}
xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(body, text);
xmpp_stanza_add_child(reply, body); xmpp_stanza_add_child(reply, body);