| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-11-09 16:24:50 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-11-16 14:55:03 UTC |
| parent | 7493f4a286724ee9f8862f38a1c7d9668454d237 |
| borogove/Chat.hx | +3 | -3 |
| test/TestChat.hx | +51 | -0 |
diff --git a/borogove/Chat.hx b/borogove/Chat.hx index e503318..7c5610b 100644 --- a/borogove/Chat.hx +++ b/borogove/Chat.hx @@ -1400,16 +1400,16 @@ class DirectChat extends Chat { if (e2eePreference == Default) e2eePreference = client.outgoingE2EEPreference[0]; #if NO_OMEMO if (e2eePreference != NoE2EE) throw "Selected E2EE preference unsupported"; - return Promise.resolve(stanza); + return Promise.resolve(clone); #else switch (e2eePreference) { case OMEMO: // As written this falls back to NoE2EE if allowed - return client.omemo.encryptMessage([JID.parse(counterpart)], stanza).then((encryptedStanza) -> { + return client.omemo.encryptMessage([JID.parse(counterpart)], clone).then((encryptedStanza) -> { return Promise.resolve(encryptedStanza); }); case NoE2EE: - return Promise.resolve(stanza); + return Promise.resolve(clone); case Default: throw "Impossible"; } diff --git a/test/TestChat.hx b/test/TestChat.hx index 100efe2..1ae449b 100644 --- a/test/TestChat.hx +++ b/test/TestChat.hx @@ -1230,6 +1230,57 @@ class TestChat extends utest.Test { chat.sendMessage(builder, borogove.Chat.OutgoingE2EEPreference.OMEMO); } #end + + public function testSendMessageExtendedMultiDMSendsToEachParticipant(async: Async) { + final persistence = new RecordingPersistence(); + final client = new Client("me@example.com", persistence); + final chat = client.getDirectChat("bob@example.com\ncarol@example.com"); + final sent: Array<Stanza> = []; + + client.stream.on("sendStanza", (stanza: Stanza) -> { + if (stanza.name != "message" || stanza.getChildText("body") != "hello") return EventUnhandled; + sent.push(stanza); + if (sent.length < 2) return EventUnhandled; + + final tos = sent.map(s -> s.attr.get("to")); + tos.sort(Reflect.compare); + Assert.same(["bob@example.com", "carol@example.com"], tos); + for (s in sent) { + final addresses = s.getChild("addresses", "http://jabber.org/protocol/address"); + Assert.notNull(addresses); + if (addresses != null) { + final jids = addresses.allTags("address").map(a -> a.attr.get("jid")); + jids.sort(Reflect.compare); + Assert.same(["bob@example.com", "carol@example.com"], jids); + } + } + + Assert.equals(1, persistence.storedMessages.length); + if (persistence.storedMessages.length > 0) { + final stored = persistence.storedMessages[0]; + Assert.equals(chat.chatId, stored.chatId()); + Assert.equals("bob@example.com", stored.to?.asString()); + Assert.same(["bob@example.com", "carol@example.com"], stored.recipients.map(r -> r.asBare().asString())); + } + async.done(); + return EventHandled; + }); + + final builder = new ChatMessageBuilder(); + builder.text = "hello"; + chat.sendMessage(builder, borogove.Chat.OutgoingE2EEPreference.NoE2EE); + } + +} + +@:access(borogove) +class RecordingPersistence extends Dummy { + public var storedMessages: Array<borogove.ChatMessage> = []; + + override public function storeMessages(accountId: String, messages: Array<borogove.ChatMessage>) { + storedMessages = storedMessages.concat(messages); + return Promise.resolve(messages); + } } @:access(borogove)