about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-04-06 18:37:39 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-04-06 19:15:02 +0200
commit3524a53c7c61783f021111755a5617b56bfaa234 (patch)
treeef21198b90e30f2db5b073fab8cff2b728f54e27
parent5862e5b159bae4fdf75388067a0a9ae6869a255e (diff)
downloadprofani-tty-3524a53c7c61783f021111755a5617b56bfaa234.tar.gz
Add type field to ProfMessage
The mucuser boolean is not now needed anymore.
-rw-r--r--src/event/server_events.c2
-rw-r--r--src/log.c14
-rw-r--r--src/xmpp/message.c12
-rw-r--r--src/xmpp/xmpp.h13
4 files changed, 27 insertions, 14 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index d1223082..e75db88e 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -445,7 +445,7 @@ sv_ev_outgoing_carbon(ProfMessage *message)
     chat_state_active(chatwin->state);
 
     if (message->plain) {
-        if (message->mucuser) {
+        if (message->type == PROF_MSG_TYPE_MUCPM) {
             // MUC PM, should have resource (nick) in filename
             chat_log_msg_out(message->jid->barejid, message->plain, message->jid->resourcepart);
         } else {
diff --git a/src/log.c b/src/log.c
index e35fb460..ae8f1542 100644
--- a/src/log.c
+++ b/src/log.c
@@ -356,13 +356,13 @@ chat_log_otr_msg_in(ProfMessage *message)
         Jid *jidp = jid_create(jid);
         char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
         if (message->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) {
-            if (message->mucuser) {
+            if (message->type == PROF_MSG_TYPE_MUCPM) {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
             } else {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
             }
         } else if (strcmp(pref_otr_log, "redact") == 0) {
-            if (message->mucuser) {
+            if (message->type == PROF_MSG_TYPE_MUCPM) {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
             } else {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
@@ -381,13 +381,13 @@ chat_log_pgp_msg_in(ProfMessage *message)
         Jid *jidp = jid_create(jid);
         char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
         if (strcmp(pref_pgp_log, "on") == 0) {
-            if (message->mucuser) {
+            if (message->type == PROF_MSG_TYPE_MUCPM) {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
             } else {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
             }
         } else if (strcmp(pref_pgp_log, "redact") == 0) {
-            if (message->mucuser) {
+            if (message->type == PROF_MSG_TYPE_MUCPM) {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
             } else {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
@@ -406,13 +406,13 @@ chat_log_omemo_msg_in(ProfMessage *message)
         Jid *jidp = jid_create(jid);
         char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
         if (strcmp(pref_omemo_log, "on") == 0) {
-            if (message->mucuser) {
+            if (message->type == PROF_MSG_TYPE_MUCPM) {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
             } else {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
             }
         } else if (strcmp(pref_omemo_log, "redact") == 0) {
-            if (message->mucuser) {
+            if (message->type == PROF_MSG_TYPE_MUCPM) {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
             } else {
                 _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
@@ -430,7 +430,7 @@ chat_log_msg_in(ProfMessage *message)
         const char *jid = connection_get_fulljid();
         Jid *jidp = jid_create(jid);
 
-        if (message->mucuser) {
+        if (message->type == PROF_MSG_TYPE_MUCPM) {
             _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
         } else {
             _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
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);