about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-10 22:03:40 +0000
committerJames Booth <boothj5@gmail.com>2015-01-10 22:03:40 +0000
commit76bd2ec13f5ffc21ddf91eebf3cb2e6dafe3ad75 (patch)
tree1cb60e775ca539479e373181910018908a9daa0e /src/xmpp
parent965e82b35057414f93c75eb038c2402e019a6777 (diff)
downloadprofani-tty-76bd2ec13f5ffc21ddf91eebf3cb2e6dafe3ad75.tar.gz
Send active chat state, handle composing and gone from recipients
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/message.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 0d88603a..69c320ea 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -88,11 +88,19 @@ message_send_chat(const char * const barejid, const char * const msg)
 
     ChatSession *session = chat_session_get(barejid);
     if (session) {
+        char *state = NULL;
+        if (prefs_get_boolean(PREF_STATES) && session->send_states) {
+            state = STANZA_NAME_ACTIVE;
+        }
         Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
-        message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, NULL);
+        message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state);
         jid_destroy(jidp);
     } else {
-        message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, NULL);
+        char *state = NULL;
+        if (prefs_get_boolean(PREF_STATES)) {
+            state = STANZA_NAME_ACTIVE;
+        }
+        message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state);
     }
 
     xmpp_send(conn, message);
@@ -461,36 +469,24 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
         GTimeVal tv_stamp;
         gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
 
-        // handle chat sessions
+        // handle chat sessions and states
         if (!delayed && jid->resourcepart) {
             gboolean recipient_gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
             if (recipient_gone) {
-                chat_session_remove(jid->barejid);
+                handle_gone(jid->barejid);
             } else {
-                chat_session_on_recipient_activity(jid->barejid, jid->resourcepart);
+                gboolean send_states = FALSE;
+                if (stanza_contains_chat_state(stanza)) {
+                    send_states = TRUE;
+                    gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
+                    if (typing) {
+                        handle_typing(jid->barejid);
+                    }
+                }
+                chat_session_on_recipient_activity(jid->barejid, jid->resourcepart, send_states);
             }
         }
 
-//            // determine chatstate support of recipient
-//            if (stanza_contains_chat_state(stanza)) {
-//                chat_session_on_incoming_message(jid->barejid, jid->resourcepart, TRUE);
-//            } else {
-//                chat_session_on_incoming_message(jid->barejid, jid->resourcepart, FALSE);
-//            }
-//
-//            if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
-//                handle_typing(jid->barejid);
-//            } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) {
-//                handle_gone(jid->barejid);
-//            } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) {
-//                // do something
-//            } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) {
-//                // do something
-//            } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ACTIVE) != NULL) {
-//                // do something
-//            }
-//        }
-
         // check for and deal with message
         xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
         if (body != NULL) {