[network/ruqola] src/core: Validate that we reset attachment/reaction

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 0ca1772e87cc89f915c67cd76ca2becc349c3f89 by Laurent Montel.
Committed on 28/07/2026 at 19:11.
Pushed by mlaurent into branch 'master'.

Validate that we reset attachment/reaction

M  +52   -0    src/core/autotests/messagetest.cpp
M  +2    -0    src/core/autotests/messagetest.h
M  +5    -0    src/core/messages/message.cpp

https://invent.kde.org/network/ruqola/-/commit/0ca1772e87cc89f915c67cd76ca2becc349c3f89

diff --git a/src/core/autotests/messagetest.cpp b/src/core/autotests/messagetest.cpp
index 910828ba2b..ea423465a4 100644
--- a/src/core/autotests/messagetest.cpp
+++ b/src/core/autotests/messagetest.cpp
@@ -8,6 +8,7 @@
 #include "messages/message.h"
 #include "ruqola_autotest_helper.h"
 #include <QCborValue>
+#include <QJsonArray>
 #include <QJsonDocument>
 #include <QJsonObject>
 #include <QTest>
@@ -841,4 +842,55 @@ void MessageTest::shouldUpdateJsonMessage()
     QVERIFY(compareMessage);
 }
 
+void MessageTest::shouldClearStaleDependentDataOnUpdate()
+{
+    Message message;
+
+    QJsonObject initial;
+    initial.insert("_id"_L1, "msg-id"_L1);
+    initial.insert("rid"_L1, "room-id"_L1);
+    initial.insert("msg"_L1, "initial"_L1);
+    initial.insert("t"_L1, "room_changed_topic"_L1);
+
+    QJsonObject user;
+    user.insert("username"_L1, "alice"_L1);
+    user.insert("name"_L1, "Alice"_L1);
+    user.insert("_id"_L1, "alice-id"_L1);
+    initial.insert("u"_L1, user);
+
+    QJsonArray attachments;
+    QJsonObject attachment;
+    attachment.insert("text"_L1, "attachment text"_L1);
+    attachments.append(attachment);
+    initial.insert("attachments"_L1, attachments);
+
+    QJsonObject reactions;
+    QJsonObject smileReaction;
+    QJsonArray usernames;
+    usernames.append("alice"_L1);
+    smileReaction.insert("usernames"_L1, usernames);
+    reactions.insert(":smile:"_L1, smileReaction);
+    initial.insert("reactions"_L1, reactions);
+
+    message.parseMessage(initial, false, nullptr);
+
+    QVERIFY(message.attachments());
+    QVERIFY(message.reactions());
+    QCOMPARE(message.systemMessageType(), SystemMessageTypeUtil::SystemMessageType::RoomTopicChanged);
+    QCOMPARE(message.messageType(), Message::MessageType::System);
+
+    QJsonObject updated;
+    updated.insert("_id"_L1, "msg-id"_L1);
+    updated.insert("rid"_L1, "room-id"_L1);
+    updated.insert("msg"_L1, "updated"_L1);
+    updated.insert("u"_L1, user);
+
+    message.parseMessage(updated, false, nullptr);
+
+    QVERIFY(!message.attachments());
+    QVERIFY(!message.reactions());
+    QCOMPARE(message.systemMessageType(), SystemMessageTypeUtil::SystemMessageType::Unknown);
+    QCOMPARE(message.messageType(), Message::MessageType::NormalText);
+}
+
 #include "moc_messagetest.cpp"
diff --git a/src/core/autotests/messagetest.h b/src/core/autotests/messagetest.h
index c5d10adb4e..ff97e2769a 100644
--- a/src/core/autotests/messagetest.h
+++ b/src/core/autotests/messagetest.h
@@ -27,4 +27,6 @@ private Q_SLOTS:
 
     void shouldUpdateJsonMessage_data();
     void shouldUpdateJsonMessage();
+
+    void shouldClearStaleDependentDataOnUpdate();
 };
diff --git a/src/core/messages/message.cpp b/src/core/messages/message.cpp
index 0be4523c39..9cd1c9c48e 100644
--- a/src/core/messages/message.cpp
+++ b/src/core/messages/message.cpp
@@ -108,6 +108,7 @@ void Message::parseMessage(const QJsonObject &o, bool restApi, EmojiManager *emo
             mMessageType = MessageType::System;
         }
     } else {
+        mSystemMessageType = SystemMessageTypeUtil::SystemMessageType::Unknown;
         mMessageType = Message::MessageType::NormalText;
     }
     parseBlocks(o.value("blocks"_L1).toArray());
@@ -129,6 +130,8 @@ void Message::parseReactions(const QJsonObject &reacts, EmojiManager *emojiManag
             mReactions.reset(new Reactions);
         }
         mReactions->parseReactions(reacts, emojiManager);
+    } else {
+        mReactions.reset();
     }
 }
 
@@ -619,6 +622,8 @@ void Message::parseAttachment(const QJsonArray &attachments)
         if (mAttachments->isEmpty()) {
             mAttachments.reset();
         }
+    } else {
+        mAttachments.reset();
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.