Added offline handler for chat sessions

This commit is contained in:
James Booth
2015-01-06 23:19:56 +00:00
parent 36790dc26b
commit 95ad564372
9 changed files with 122 additions and 11 deletions

View File

@@ -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, "/");
@@ -242,6 +237,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)
{
@@ -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;

View File

@@ -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);

View File

@@ -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

View File

@@ -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
}
}