about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/event/server_events.c22
-rw-r--r--src/xmpp/connection.c17
-rw-r--r--src/xmpp/connection.h2
3 files changed, 29 insertions, 12 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 0417f35d..b875c22e 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -49,6 +49,7 @@
 #include "event/common.h"
 #include "plugins/plugins.h"
 #include "ui/window_list.h"
+#include "xmpp/connection.h"
 #include "xmpp/muc.h"
 #include "xmpp/chat_session.h"
 #include "xmpp/roster_list.h"
@@ -294,8 +295,25 @@ sv_ev_room_message(ProfMessage *message)
 
     char *mynick = muc_nick(mucwin->roomjid);
 
-    // only log messages from others. we log our own via mucwin_outgoing_msg()
-    if (g_strcmp0(mynick, message->jid->resourcepart) != 0) {
+    // messages from ourselves
+    if (g_strcmp0(mynick, message->jid->resourcepart) == 0) {
+        // test if message was sent from this client
+        // we check the </origin-id> for this we calculate a hash into it so we can detect
+        // whether this client sent it. See connection_create_stanza_id()
+        gsize tmp_len;
+        char *tmp = (char*)g_base64_decode(message->id, &tmp_len);
+        if (tmp_len > 10) {
+            // log if not from this client
+            if (g_strcmp0(&tmp[10], connection_get_profanity_identifier()) != 0) {
+                if (message->enc == PROF_MSG_ENC_OMEMO) {
+                    groupchat_log_omemo_msg_in(message->jid->barejid, message->jid->resourcepart, (char*)tmp);
+                } else {
+                    groupchat_log_msg_in(message->jid->barejid, message->jid->resourcepart, message->plain);
+                }
+            }
+        }
+    // messages from others
+    } else {
         if (message->enc == PROF_MSG_ENC_OMEMO) {
             groupchat_log_omemo_msg_in(message->jid->barejid, message->jid->resourcepart, message->plain);
         } else {
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 2d2408c5..cfa9db21 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -458,24 +458,17 @@ connection_free_uuid(char *uuid)
 char*
 connection_create_stanza_id(void)
 {
-    unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE);
     char *msgid = get_random_string(10);
 
-    assert(digest != NULL);
     assert(msgid != NULL);
 
     GString *signature = g_string_new("");
-    g_string_printf(signature, "%s%s", prof_identifier, msgid);
-    xmpp_sha1_digest((unsigned char*)signature->str, strlen(signature->str), digest);
-    g_string_free(signature, TRUE);
+    g_string_printf(signature, "%s%s", msgid, prof_identifier);
 
-    GString *id = g_string_new("");
-    g_string_printf(id, "%s%s", digest, msgid);
+    char *b64 = g_base64_encode((unsigned char*)signature->str, signature->len);
+    g_string_free(signature, TRUE);
 
-    char *b64 = g_base64_encode((unsigned char*)id->str, XMPP_SHA1_DIGEST_SIZE);
-    g_string_free(id, TRUE);
     assert(b64 != NULL);
-    free(digest);
 
     return b64;
 }
@@ -687,3 +680,7 @@ static void _calculate_identifier(const char *barejid)
 
     prof_identifier = b64;
 }
+
+char *connection_get_profanity_identifier(void) {
+    return prof_identifier;
+}
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index 3f15df82..157b252c 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -64,4 +64,6 @@ void connection_remove_available_resource(const char *const resource);
 
 char* connection_create_stanza_id(void);
 
+char *connection_get_profanity_identifier(void);
+
 #endif