about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-07-03 16:17:18 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-03 16:17:18 +0200
commitc66d3c6389042ffa99c69ca3c52f609a694c2bf1 (patch)
tree0b362dfb404ba017dae50c35af3c48dfcaa8eca5 /src
parent14f33e54f66e7b23ddd67e91a13b628066da2a48 (diff)
downloadprofani-tty-c66d3c6389042ffa99c69ca3c52f609a694c2bf1.tar.gz
message.c: Put XEP-0085 code in helper function
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/message.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 8a6f647b..fd0bb978 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -124,6 +124,28 @@ _handle_headline(xmpp_stanza_t *const stanza)
     }
 }
 
+static void
+_handle_chat_states(xmpp_stanza_t *const stanza, Jid *const jid)
+{
+    gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
+    gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
+    gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL;
+    gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL;
+    if (gone) {
+        sv_ev_gone(jid->barejid, jid->resourcepart);
+    } else if (typing) {
+        sv_ev_typing(jid->barejid, jid->resourcepart);
+    } else if (paused) {
+        sv_ev_paused(jid->barejid, jid->resourcepart);
+    } else if (inactive) {
+        sv_ev_inactive(jid->barejid, jid->resourcepart);
+    } else if (stanza_contains_chat_state(stanza)) {
+        sv_ev_activity(jid->barejid, jid->resourcepart, TRUE);
+    } else {
+        sv_ev_activity(jid->barejid, jid->resourcepart, FALSE);
+    }
+}
+
 static int
 _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
 {
@@ -1360,25 +1382,10 @@ _handle_chat(xmpp_stanza_t *const stanza, gboolean is_mam)
         _receipt_request_handler(stanza);
     }
 
-    // handle chat sessions and states
+    // 0085 works only with resource
     if (jid->resourcepart) {
-        gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
-        gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
-        gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL;
-        gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL;
-        if (gone) {
-            sv_ev_gone(jid->barejid, jid->resourcepart);
-        } else if (typing) {
-            sv_ev_typing(jid->barejid, jid->resourcepart);
-        } else if (paused) {
-            sv_ev_paused(jid->barejid, jid->resourcepart);
-        } else if (inactive) {
-            sv_ev_inactive(jid->barejid, jid->resourcepart);
-        } else if (stanza_contains_chat_state(stanza)) {
-            sv_ev_activity(jid->barejid, jid->resourcepart, TRUE);
-        } else {
-            sv_ev_activity(jid->barejid, jid->resourcepart, FALSE);
-        }
+        // XEP-0085: Chat State Notifications
+        _handle_chat_states(stanza, jid);
     }
 
     message_free(message);