git » sdk » commit 8bbf87c

Allow manually switching a chat to a MUC

author Stephen Paul Weber
2023-11-27 19:13:38 UTC
committer Stephen Paul Weber
2023-11-27 19:13:38 UTC
parent 42fff24823de8d850c7755042b876497fb1c20b8

Allow manually switching a chat to a MUC

xmpp/Client.hx +9 -4

diff --git a/xmpp/Client.hx b/xmpp/Client.hx
index 621aeb2..5523533 100644
--- a/xmpp/Client.hx
+++ b/xmpp/Client.hx
@@ -479,10 +479,15 @@ class Client extends xmpp.EventEmitter {
 	public function startChat(chatId:String, fn:Null<String>, caps:Caps):Chat {
 		final existingChat = getChat(chatId);
 		if (existingChat != null) {
-			if (existingChat.uiState == Closed) existingChat.uiState = Open;
-			Std.downcast(existingChat, Channel)?.selfPing();
-			this.trigger("chats/update", [existingChat]);
-			return existingChat;
+			final channel = Std.downcast(existingChat, Channel);
+			if (channel == null && caps.isChannel(chatId)) {
+				chats = chats.filter((chat) -> chat.chatId == chatId);
+			} else {
+				if (existingChat.uiState == Closed) existingChat.uiState = Open;
+				channel?.selfPing();
+				this.trigger("chats/update", [existingChat]);
+				return existingChat;
+			}
 		}
 
 		final chat = if (caps.isChannel(chatId)) {