diff options
Diffstat (limited to 'src/jabber.c')
-rw-r--r-- | src/jabber.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/jabber.c b/src/jabber.c index 8c9c9ba0..23f7f444 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -25,6 +25,7 @@ #include <strophe.h> +#include "chat_session.h" #include "common.h" #include "contact_list.h" #include "jabber.h" @@ -136,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, "<", "<"); char *coded_msg3 = str_replace(coded_msg2, ">", ">"); 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"); @@ -156,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); @@ -244,6 +252,7 @@ jabber_get_jid(void) void jabber_free_resources(void) { + chat_sessions_clear(); xmpp_conn_release(jabber_conn.conn); xmpp_ctx_free(jabber_conn.ctx); xmpp_shutdown(); @@ -335,6 +344,7 @@ _connection_handler(xmpp_conn_t * const conn, if (status == XMPP_CONN_CONNECT) { const char *jid = xmpp_conn_get_jid(conn); prof_handle_login_success(jid); + chat_sessions_init(); xmpp_handler_add(conn, _message_handler, NULL, "message", NULL, ctx); xmpp_handler_add(conn, _presence_handler, NULL, "presence", NULL, ctx); |