git » sdk » commit 5309f42

Only trigger for new chat once

author Stephen Paul Weber
2026-03-11 03:40:33 UTC
committer Stephen Paul Weber
2026-03-11 03:40:33 UTC
parent 0020b7baaf76f556dadaed54f9e4c2da49bf2a43

Only trigger for new chat once

borogove/Client.hx +11 -1

diff --git a/borogove/Client.hx b/borogove/Client.hx
index b0c2ada..84eb8b0 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -454,9 +454,13 @@ class Client extends EventEmitter {
 			if (channel != null) channel.selfPing(true);
 		}
 
+		var newChat: Null<Chat> = null;
+
 		final message = Message.fromStanza(stanza, this.jid, (builder, stanza) -> {
 			var chat = getChat(builder.chatId());
-			if (chat == null && stanza.attr.get("type") != "groupchat") chat = getDirectChat(builder.chatId());
+			final isNewChat = chat == null;
+			if (chat == null && stanza.attr.get("type") != "groupchat") chat = getDirectChat(builder.chatId(), false);
+			if (isNewChat) newChat = chat;
 			if (chat == null) return builder;
 			return chat.prepareIncomingMessage(builder, stanza);
 		}, encryptionInfo);
@@ -474,6 +478,8 @@ class Client extends EventEmitter {
 							chat.setLastMessage(chatMessage);
 							if (chatMessage.versions.length < 1) chat.setUnreadCount(chatMessage.isIncoming() ? chat.unreadCount() + 1 : 0);
 							chatActivity(chat);
+						} else if (newChat != null) {
+							this.trigger("chats/update", [newChat]);
 						}
 					};
 					if (chatMessage.serverId == null) {
@@ -487,8 +493,10 @@ class Client extends EventEmitter {
 					fetchMediaByHash([hash], [from]);
 				}
 				persistence.storeReaction(accountId(), update).then((stored) -> if (stored != null) notifyMessageHandlers(stored, ReactionEvent));
+				if (newChat != null) this.trigger("chats/update", [newChat]);
 			case ModerateMessageStanza(action):
 				moderateMessage(action).then((stored) -> if (stored != null) notifyMessageHandlers(stored, CorrectionEvent));
+				if (newChat != null) this.trigger("chats/update", [newChat]);
 			case ErrorMessageStanza(localId, stanza):
 				persistence.updateMessageStatus(
 					this.accountId(),
@@ -496,11 +504,13 @@ class Client extends EventEmitter {
 					MessageFailedToSend,
 					stanza.getErrorText(),
 				).then((m) -> notifyMessageHandlers(m, StatusEvent), _ -> null);
+				if (newChat != null) this.trigger("chats/update", [newChat]);
 			case MucInviteStanza(serverId, serverIdBy, reason, password):
 				mucInvite(message.chatId, getChat(message.chatId), message.senderId, message.threadId, serverId, serverIdBy, reason, password);
 			default:
 				// ignore
 				trace("Ignoring non-chat message: " + stanza.toString());
+				if (newChat != null) this.trigger("chats/update", [newChat]);
 		}
 
 #if !NO_JINGLE