diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chat_session.c | 48 | ||||
-rw-r--r-- | src/chat_session.h | 2 | ||||
-rw-r--r-- | src/server_events.c | 2 | ||||
-rw-r--r-- | src/xmpp/message.c | 6 |
4 files changed, 49 insertions, 9 deletions
diff --git a/src/chat_session.c b/src/chat_session.c index 67104fa6..eae3f577 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -62,7 +62,6 @@ typedef struct chat_session_t { chat_state_t state; GTimer *active_timer; gboolean sent; - gboolean includes_message; } ChatSession; static GHashTable *sessions; @@ -81,7 +80,6 @@ _chat_session_new(const char * const barejid, const char * const resource, gbool new_session->state = CHAT_STATE_STARTED; new_session->active_timer = g_timer_new(); new_session->sent = FALSE; - new_session->includes_message = FALSE; return new_session; } @@ -173,7 +171,6 @@ chat_session_on_incoming_message(const char * const barejid, const char * const } g_hash_table_remove(sessions, session); session = _chat_session_new(barejid, resource, send_states); - session->includes_message = TRUE; g_hash_table_insert(sessions, strdup(barejid), session); // session exists for resource, update state @@ -185,7 +182,6 @@ chat_session_on_incoming_message(const char * const barejid, const char * const g_string_append(log_msg, session->resource); } session->send_states = send_states; - session->includes_message = TRUE; } if (send_states) { g_string_append(log_msg, ", chat states supported"); @@ -212,7 +208,6 @@ chat_session_on_message_send(const char * const barejid) session->state = CHAT_STATE_ACTIVE; g_timer_start(session->active_timer); session->sent = TRUE; - session->includes_message = TRUE; } void @@ -221,7 +216,7 @@ chat_session_on_window_close(const char * const barejid) ChatSession *session = g_hash_table_lookup(sessions, barejid); if (session) { - if (prefs_get_boolean(PREF_STATES) && session->send_states && session->includes_message) { + if (prefs_get_boolean(PREF_STATES) && session->send_states) { GString *jid = g_string_new(session->barejid); if (session->resource) { g_string_append(jid, "/"); @@ -243,6 +238,45 @@ chat_session_on_window_close(const char * const barejid) } void +chat_session_on_offline(const char * const barejid, const char * const resource) +{ + if (!resource) { + return; + } + + ChatSession *session = g_hash_table_lookup(sessions, barejid); + + if (session && (g_strcmp0(session->resource, resource) == 0)) { + GString *log_msg = g_string_new("Removing chat session for "); + g_string_append(log_msg, barejid); + if (session->resource) { + g_string_append(log_msg, "/"); + g_string_append(log_msg, session->resource); + } + log_debug(log_msg->str); + g_string_free(log_msg, TRUE); + g_hash_table_remove(sessions, barejid); + } +} + +void +chat_session_on_gone(const char * const barejid) +{ + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (session) { + GString *log_msg = g_string_new("Removing chat session for "); + g_string_append(log_msg, barejid); + if (session->resource) { + g_string_append(log_msg, "/"); + g_string_append(log_msg, session->resource); + } + log_debug(log_msg->str); + g_string_free(log_msg, TRUE); + g_hash_table_remove(sessions, barejid); + } +} + +void chat_session_on_activity(const char * const barejid) { ChatSession *session = g_hash_table_lookup(sessions, barejid); @@ -312,7 +346,7 @@ chat_session_on_inactivity(const char * const barejid) g_string_append(jid, session->resource); } if (session->state == CHAT_STATE_GONE) { - if (prefs_get_boolean(PREF_STATES) && session->send_states && session->includes_message) { + if (prefs_get_boolean(PREF_STATES) && session->send_states) { message_send_gone(jid->str); } session->sent = TRUE; diff --git a/src/chat_session.h b/src/chat_session.h index 441f9096..dbffad9f 100644 --- a/src/chat_session.h +++ b/src/chat_session.h @@ -47,7 +47,9 @@ gboolean chat_session_send_states(const char * const barejid); void chat_session_on_message_send(const char * const barejid); void chat_session_on_window_close(const char * const barejid); void chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean send_states); +void chat_session_on_offline(const char * const barejid, const char * const resource); void chat_session_on_cancel(const char * const jid); +void chat_session_on_gone(const char * const barejid); void chat_session_on_activity(const char * const barejid); void chat_session_on_inactivity(const char * const barejid); diff --git a/src/server_events.c b/src/server_events.c index 86838ad1..edd58724 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -393,6 +393,7 @@ handle_typing(char *from) void handle_gone(const char * const from) { + chat_session_on_gone(from); ui_recipient_gone(from); } @@ -463,6 +464,7 @@ handle_contact_offline(char *barejid, char *resource, char *status) } rosterwin_roster(); + chat_session_on_offline(barejid, resource); } void diff --git a/src/xmpp/message.c b/src/xmpp/message.c index c3cbc14f..e436dbc1 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -472,7 +472,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } // create or update chat session - chat_session_on_incoming_message(jid->barejid, jid->resourcepart, recipient_supports); + if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ACTIVE) != NULL) { + chat_session_on_incoming_message(jid->barejid, jid->resourcepart, recipient_supports); + } // determine if the notifications happened whilst offline GTimeVal tv_stamp; @@ -488,7 +490,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // do something } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) { // do something - } else { // handle <active/> + } else { // <active/> // do something } } |