git » sdk » commit 6570ce1

Optimize chat updates for roster

author Stephen Paul Weber
2024-11-19 20:05:52 UTC
committer Stephen Paul Weber
2024-11-19 20:05:52 UTC
parent f0492f00081ce10759ee3dd3b07f6ffd324dbef3

Optimize chat updates for roster

No need to update every chat we know about when we know exactly which
chats we just modified.

snikket/Client.hx +6 -2

diff --git a/snikket/Client.hx b/snikket/Client.hx
index ff25060..37147f5 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -396,13 +396,15 @@ class Client extends EventEmitter {
 			var items = roster.getResult();
 			if (items.length == 0) return IqNoResult;
 
+			final chatsToUpdate = [];
 			for (item in items) {
 				if (item.subscription != "remove") {
 					final chat = getDirectChat(item.jid, false);
 					chat.setTrusted(item.subscription == "both" || item.subscription == "from");
+					chatsToUpdate.push(chat);
 				}
 			}
-			this.trigger("chats/update", chats);
+			this.trigger("chats/update", chatsToUpdate);
 
 			return IqResult;
 		});
@@ -1232,13 +1234,15 @@ class Client extends EventEmitter {
 	private function rosterGet() {
 		var rosterGet = new RosterGet();
 		rosterGet.onFinished(() -> {
+			final chatsToUpdate = [];
 			for (item in rosterGet.getResult()) {
 				var chat = getDirectChat(item.jid, false);
 				chat.setTrusted(item.subscription == "both" || item.subscription == "from");
 				if (item.fn != null && item.fn != "") chat.setDisplayName(item.fn);
 				persistence.storeChat(accountId(), chat);
+				chatsToUpdate.push(chat);
 			}
-			this.trigger("chats/update", chats);
+			this.trigger("chats/update", chatsToUpdate);
 		});
 		sendQuery(rosterGet);
 	}