Skip to content

Commit

Permalink
Optimize chat updates for roster
Browse files Browse the repository at this point in the history
No need to update every chat we know about when we know exactly which
chats we just modified.
  • Loading branch information
singpolyma committed Nov 19, 2024
1 parent f0492f0 commit 6570ce1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions snikket/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6570ce1

Please sign in to comment.