git » sdk » commit c3fa377

Always add all recipients to outbound message

author Stephen Paul Weber
2026-11-08 19:21:50 UTC
committer Stephen Paul Weber
2026-11-16 14:55:03 UTC
parent a8d3c491a05ff6ed174cee9318093128735ce2ea

Always add all recipients to outbound message

borogove/Chat.hx +4 -8
test/TestChat.hx +33 -0

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 3dd8ba9..be0e678 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -1278,8 +1278,8 @@ class DirectChat extends Chat {
 		message.from = client.jid;
 		message.sender = message.from.asBare();
 		message.replyTo = [message.sender];
-		message.recipients = counterparts().map((p) -> JID.parse(p));
-		message.to = message.recipients[0];
+		message.recipients = _fullCounterparts.map((p) -> JID.parse(p));
+		message.to = JID.parse(counterparts()[0]);
 		if (message.localId == null) message.localId = ID.unique();
 		return message;
 	}
@@ -1309,11 +1309,10 @@ class DirectChat extends Chat {
 		if (typingTimer != null) typingTimer.stop();
 		client.chatActivity(this);
 		message = prepareOutgoingMessage(message);
-		message.to = message.recipients[0]; // Just pick one for the stanza we re-parse
+		final outboxItem = outbox.newItem();
 		final fromStanza = Message.fromStanza(message.build().asStanza(), client.jid).parsed;
 		switch (fromStanza) {
 			case ChatMessageStanza(_):
-				final outboxItem = outbox.newItem();
 				client.storeMessageBuilder(message).then((stored) -> {
 					final stanza = message.build().asStanza();
 					if (isActive != null) {
@@ -1334,10 +1333,7 @@ class DirectChat extends Chat {
 				});
 			case ReactionUpdateStanza(update):
 				persistence.storeReaction(client.accountId(), update).then((stored) -> {
-					for (recipient in message.recipients) {
-						message.to = recipient;
-						client.sendStanza(message.build().asStanza());
-					}
+					sendMessageStanza(message.build().asStanza(), outboxItem, e2eePreference);
 					if (stored != null) client.notifyMessageHandlers(stored, ReactionEvent);
 				});
 			default:
diff --git a/test/TestChat.hx b/test/TestChat.hx
index 60d565b..fe9751d 100644
--- a/test/TestChat.hx
+++ b/test/TestChat.hx
@@ -1231,6 +1231,39 @@ class TestChat extends utest.Test {
 	}
 #end
 
+	public function testSendMessageMultiDMSendsOnlyToRoutingJid(async: Async) {
+		final persistence = new RecordingPersistence();
+		final client = new Client("me@example.com", persistence);
+		final routing = "multi@example.com";
+		final chat = new borogove.Chat.DirectChat(client, client.stream, persistence, routing);
+		chat._fullCounterparts = ["bob@example.com", "carol@example.com"];
+
+		client.stream.on("sendStanza", (stanza: Stanza) -> {
+			if (stanza.name != "message" || stanza.getChildText("body") != "hello") return EventUnhandled;
+
+			Assert.equals(1, persistence.storedMessages.length);
+			if (persistence.storedMessages.length > 0) {
+				final stored = persistence.storedMessages[0];
+				Assert.equals(routing, stored.chatId());
+				Assert.equals(routing, stored.to?.asString());
+				Assert.same(["bob@example.com", "carol@example.com"], stored.recipients.map(r -> r.asBare().asString()));
+			}
+
+			Assert.equals(routing, stanza.attr.get("to"));
+			final addresses = stanza.getChild("addresses", "http://jabber.org/protocol/address");
+			Assert.notNull(addresses);
+			if (addresses != null) {
+				Assert.same(["bob@example.com", "carol@example.com"], addresses.allTags("address").map(a -> a.attr.get("jid")));
+			}
+			async.done();
+			return EventHandled;
+		});
+
+		final builder = new ChatMessageBuilder();
+		builder.text = "hello";
+		chat.sendMessage(builder, borogove.Chat.OutgoingE2EEPreference.NoE2EE);
+	}
+
 	public function testSendMessageExtendedMultiDMSendsToEachParticipant(async: Async) {
 		final persistence = new RecordingPersistence();
 		final client = new Client("me@example.com", persistence);