git » sdk » commit 60b22f3

Do not create a DirectChat for PMs

author Stephen Paul Weber
2026-11-10 03:44:39 UTC
committer Stephen Paul Weber
2026-11-10 03:57:39 UTC
parent 68860e67f3cfc2f3d8c6ce410926049246abc440

Do not create a DirectChat for PMs

borogove/Client.hx +1 -1
test/TestClient.hx +12 -0

diff --git a/borogove/Client.hx b/borogove/Client.hx
index 3e4ed52..bfd8ab8 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -499,7 +499,7 @@ class Client extends EventEmitter {
 		final message = Message.fromStanza(stanza, this.jid, (builder, stanza) -> {
 			var chat = getChat(builder.chatId());
 			final isNewChat = chat == null;
-			if (chat == null && stanza.attr.get("type") != "groupchat") chat = getDirectChat(builder.chatId(), false);
+			if (chat == null && builder.type != MessageChannel && builder.type != MessageChannelPrivate) chat = getDirectChat(builder.chatId(), false);
 			if (isNewChat) newChat = chat;
 			if (chat == null) return builder;
 			return chat.prepareIncomingMessage(builder, stanza);
diff --git a/test/TestClient.hx b/test/TestClient.hx
index aa4a177..6393d2a 100644
--- a/test/TestClient.hx
+++ b/test/TestClient.hx
@@ -66,6 +66,18 @@ class TestClient extends utest.Test {
 		Assert.isTrue(channel.isJoined);
 	}
 
+	public function testChannelPrivateMessageDoesNotCreateChat() {
+		final client = new Client("test@example.com", new Dummy());
+		client.stream.onStanza(Stanza.parse('<message xmlns="jabber:client" from="room@example.com/nick" to="test@example.com" type="chat" id="pm-1"><body>secret</body><x xmlns="http://jabber.org/protocol/muc#user"><item affiliation="member" role="participant"/></x></message>'));
+
+		Assert.isNull(client.getChat("room@example.com"));
+		Assert.isNull(client.getChat("room@example.com/nick"));
+
+		// Normal 1:1 messages must still start a chat
+		client.stream.onStanza(Stanza.parse('<message xmlns="jabber:client" from="alice@example.com/phone" to="test@example.com" type="chat" id="dm-1"><body>hi</body></message>'));
+		Assert.notNull(client.getChat("alice@example.com"));
+	}
+
 	public function testChatsUpdateBatchSurvivesResubscription() {
 		final client = new Client("test@example.com", new Dummy());
 		final first = client.getDirectChat("first@example.com", false);