git » sdk » commit 751099e

Never add self as counterpart

author Stephen Paul Weber
2026-11-08 19:20:04 UTC
committer Stephen Paul Weber
2026-11-16 14:55:03 UTC
parent c448105713e64a46a8e469358866837e7ed48d21

Never add self as counterpart

borogove/Chat.hx +2 -1
test/TestChat.hx +24 -0

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 7c5610b..3dd8ba9 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -1191,7 +1191,8 @@ class DirectChat extends Chat {
 		// If last message at load time is a sent message, this may not include everyone
 		if (_fullCounterparts.length < 2 && (message?.recipients?.length ?? 0) > 1) {
 			_fullCounterparts = message.recipients.map(r -> r.asBare().asString()).filter(id -> id != client.accountId());
-			if (!_fullCounterparts.contains(message.senderId)) _fullCounterparts.push(message.senderId);
+			final senderId = JID.parse(message.senderId).asBare().asString();
+			if (senderId != client.accountId() && !_fullCounterparts.contains(senderId)) _fullCounterparts.push(senderId);
 		}
 		return super.setLastMessage(message);
 	}
diff --git a/test/TestChat.hx b/test/TestChat.hx
index 1ae449b..60d565b 100644
--- a/test/TestChat.hx
+++ b/test/TestChat.hx
@@ -1271,6 +1271,30 @@ class TestChat extends utest.Test {
 		chat.sendMessage(builder, borogove.Chat.OutgoingE2EEPreference.NoE2EE);
 	}
 
+	public function testCompatMultiDMParticipantsRecoveredFromOutgoingLastMessage(async: Async) {
+		final persistence = new Dummy();
+		final client = new Client("me@example.com", persistence);
+		final chat = new borogove.Chat.DirectChat(client, client.stream, persistence, "multi@example.com");
+
+		final builder = new ChatMessageBuilder();
+		builder.localId = "out-1";
+		builder.sortId = "a0";
+		builder.direction = MessageSent;
+		builder.from = JID.parse("me@example.com");
+		builder.senderId = "me@example.com";
+		builder.to = JID.parse("multi@example.com");
+		builder.recipients = [JID.parse("bob@example.com"), JID.parse("carol@example.com")];
+		builder.replyTo = [JID.parse("me@example.com")];
+
+		chat.setLastMessage(builder.build()).then(_ -> {
+			Assert.same(["bob@example.com", "carol@example.com"], chat._fullCounterparts);
+			chat.members().then(members -> {
+				final ids = members.map(m -> m.id);
+				Assert.same(["bob@example.com", "carol@example.com", "me@example.com"], ids);
+				async.done();
+			});
+		});
+	}
 }
 
 @:access(borogove)