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

@@ -137,16 +137,16 @@ jabber_process_events(void)
void
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_msg2 = str_replace(coded_msg, "<", "&lt;");
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
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);
xmpp_stanza_set_name(reply, "message");
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);
xmpp_stanza_set_text(text, coded_msg3);
xmpp_stanza_add_child(reply, active);
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(body, text);
xmpp_stanza_add_child(reply, body);