| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-08-31 20:42:37 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-09-01 15:04:15 UTC |
| parent | 7273f767aa1875b9a7d91376c25e48765c1e514c |
| borogove/Client.hx | +10 | -1 |
| test/TestClient.hx | +40 | -0 |
diff --git a/borogove/Client.hx b/borogove/Client.hx index 9beb5bf..777c2b8 100644 --- a/borogove/Client.hx +++ b/borogove/Client.hx @@ -542,7 +542,16 @@ class Client extends EventEmitter { persistence.storeReaction(accountId(), update).then((stored) -> if (stored != null) notifyMessageHandlers(stored, ReactionEvent)); if (newChat != null) this.trigger("chats/update", [newChat]); case ModerateMessageStanza(action): - moderateMessage(action).then((stored) -> if (stored != null) notifyMessageHandlers(stored, CorrectionEvent)); + moderateMessage(action).then((stored) -> if (stored != null) { + final chat = getChat(stored.chatId()); + if (chat != null) { + if (stored.canReplace(chat.lastMessage)) { + chat.setLastMessage(stored); + this.trigger("chats/update", [chat]); + } + } + notifyMessageHandlers(stored, CorrectionEvent); + }); if (newChat != null) this.trigger("chats/update", [newChat]); case ErrorMessageStanza(localId, stanza): persistence.updateMessageStatus( diff --git a/test/TestClient.hx b/test/TestClient.hx index a1e323c..c02ca3b 100644 --- a/test/TestClient.hx +++ b/test/TestClient.hx @@ -290,6 +290,46 @@ class TestClient extends utest.Test { }); } + public function testChatsUpdateOnModerate(async: Async) { + final persistence = new MessageMockPersistence(); + final client = new Client("test@example.com", persistence); + final chatId = "room@example.com"; + final serverId = "msg1"; + + final chat = new borogove.Chat.Channel(client, client.stream, persistence, chatId); + client.chats.push(chat); + + final builder = new ChatMessageBuilder(); + builder.serverId = serverId; + builder.from = JID.parse(chatId + "/alice"); + builder.replyTo = [builder.from]; + builder.to = JID.parse("test@example.com"); + builder.senderId = "alice@example.com"; + builder.text = "hello"; + builder.timestamp = "2023-01-01T00:00:00Z"; + builder.sortId = "1"; + builder.direction = MessageReceived; + final originalMessage = builder.build(); + chat.setLastMessage(originalMessage); + + persistence.storeMessages(client.accountId(), [originalMessage]).then((_) -> { + Assert.isNull(chat.lastMessage.moderationReason()); + + client.addChatsUpdatedListener(chats -> { + final c = chats.find(x -> x.chatId == chatId); + Assert.notNull(c?.lastMessage); + Assert.equals("Spam", c.lastMessage.moderationReason()); + async.done(); + }); + + final moderateStanza = new Stanza("message", { xmlns: "jabber:client", from: chatId, type: "groupchat" }) + .tag("apply-to", { xmlns: "urn:xmpp:fasten:0", id: serverId }) + .tag("moderated", { xmlns: "urn:xmpp:message-moderate:0", by: "mod@example.com" }) + .textTag("reason", "Spam"); + client.stream.onStanza(moderateStanza); + }); + } + public function testDecryptionFailurePreservesLocalMessage(async: Async) { final persistence = new MessageMockPersistence(); final client = new Client("test@example.com", persistence);