| author | Eric Roberts
<ericroberts@gmail.com> 2026-08-12 17:52:53 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-08-17 14:26:49 UTC |
| parent | d2e11d67c923dd1b0dc6d32bd539d1f0c5ed5e64 |
| borogove/Client.hx | +11 | -5 |
| test/TestClient.hx | +26 | -0 |
diff --git a/borogove/Client.hx b/borogove/Client.hx index ff5bc51..9262813 100644 --- a/borogove/Client.hx +++ b/borogove/Client.hx @@ -2075,11 +2075,17 @@ class Client extends EventEmitter { } else { final cachedCaps = capsRepo.add(resultCaps); if (cachedCaps.isChannel(jid)) { - final chat = new Channel(this, this.stream, this.persistence, jid, uiState, false, false, null, cachedCaps); - chat.setupNotifications(); - chats.unshift(chat); - chatsIndex[chat.chatId] = chat; - if (inSync && sendAvailable) chat.selfPing(false); + final existing = getChat(jid); + final chat = if (existing == null) { + final channel = new Channel(this, this.stream, this.persistence, jid, uiState, false, false, null, cachedCaps); + channel.setupNotifications(); + if (inSync && sendAvailable) channel.selfPing(false); + chatsIndex[channel.chatId] = channel; + chats.unshift(channel); + channel; + } else { + existing; + } handleChat(chat); persistence.storeChats(accountId(), [chat]); this.trigger("chats/update", [chat]); diff --git a/test/TestClient.hx b/test/TestClient.hx index 993562d..e6ddc71 100644 --- a/test/TestClient.hx +++ b/test/TestClient.hx @@ -761,6 +761,32 @@ class TestClient extends utest.Test { ); } + public function testStartChatWith(async: Async) { + final persistence = new Dummy(); + final client = new Client("test@example.com", persistence); + final chat = new borogove.Chat.Channel(client, client.stream, persistence, "room@example.com"); + client.chats.push(chat); + + client.stream.on("sendStanza", (stanza: Stanza) -> { + if (stanza.name == "iq" && stanza.attr.get("type") == "get") { + final stanza = Stanza.parse('<iq from="room@example.com" type="result" id="${stanza.attr.get("id")}" xmlns="jabber:client"> + <query xmlns="http://jabber.org/protocol/disco#info"> + <identity category="conference" type="text" name="Cool chatroom" /> + <feature var="http://jabber.org/protocol/muc" /> + </query> + </iq>'); + + client.stream.onStanza(stanza); + } + return EventHandled; + }); + + client.startChatWith("room@example.com", _->Open, _->{ + Assert.equals(1, client.chats.length); + async.done(); + }); + } + #if js public function testPreferOMEMO() { final persistence = new Dummy();