about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/message.c12
-rw-r--r--src/xmpp/xmpp.h13
2 files changed, 19 insertions, 6 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index d482f258..81928d90 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -110,6 +110,7 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
         _handle_error(stanza);
     }
 
+    // if muc
     if (g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
         _handle_groupchat(stanza);
     }
@@ -195,7 +196,7 @@ message_init(void)
     message->enc = PROF_MSG_ENC_NONE;
     message->timestamp = NULL;
     message->trusted = true;
-    message->mucuser = false;
+    message->type = PROF_MSG_TYPE_UNINITIALIZED;
 
     return message;
 }
@@ -831,6 +832,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
 
     ProfMessage *message = message_init();
     message->jid = jid;
+    message->type = PROF_MSG_TYPE_MUC;
 
     if (id) {
         message->id = strdup(id);
@@ -977,7 +979,7 @@ _handle_muc_private_message(xmpp_stanza_t *const stanza)
 {
     // standard chat message, use jid without resource
     ProfMessage *message = message_init();
-    message->mucuser = TRUE;
+    message->type = PROF_MSG_TYPE_MUCPM;
 
     const gchar *from = xmpp_stanza_get_from(stanza);
     message->jid = jid_create(from);
@@ -1062,11 +1064,12 @@ _handle_carbons(xmpp_stanza_t *const stanza)
     }
 
     ProfMessage *message = message_init();
+    message->type = PROF_MSG_TYPE_CHAT;
 
     // check whether message was a MUC PM
     xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(message_stanza, STANZA_NS_MUC_USER);
     if (mucuser) {
-        message->mucuser = TRUE;
+        message->type = PROF_MSG_TYPE_MUCPM;
     }
 
     // id
@@ -1181,6 +1184,7 @@ _handle_chat(xmpp_stanza_t *const stanza)
     // standard chat message, use jid without resource
     ProfMessage *message = message_init();
     message->jid = jid;
+    message->type = PROF_MSG_TYPE_CHAT;
 
     // message stanza id
     const char *id = xmpp_stanza_get_id(stanza);
@@ -1197,7 +1201,7 @@ _handle_chat(xmpp_stanza_t *const stanza)
     }
 
     if (mucuser) {
-        message->mucuser = TRUE;
+        message->type = PROF_MSG_TYPE_MUCPM;
     }
 
     message->timestamp = stanza_get_delay(stanza);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 02d62d01..e6f5c13e 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -126,7 +126,16 @@ typedef enum {
     PROF_MSG_ENC_OMEMO
 } prof_enc_t;
 
-// TODO: ProfMessage needs a 'type' field like we have in sql db. then we can know whether each message is a chat, muc, mucpm
+typedef enum {
+    PROF_MSG_TYPE_UNINITIALIZED,
+    // regular 1:1 chat
+    PROF_MSG_TYPE_CHAT,
+    // groupchats to whole group
+    PROF_MSG_TYPE_MUC,
+    // groupchat private message
+    PROF_MSG_TYPE_MUCPM
+} prof_msg_type_t;
+
 typedef struct prof_message_t {
    Jid *jid;
    char *id;
@@ -143,7 +152,7 @@ typedef struct prof_message_t {
    GDateTime *timestamp;
    prof_enc_t enc;
    gboolean trusted;
-   gboolean mucuser;
+   prof_msg_type_t type;
 } ProfMessage;
 
 void session_init(void);