Skip to content

Commit

Permalink
Sort chats after MAM sync for a MUC
Browse files Browse the repository at this point in the history
If it gets a new last message, since that means this chat was previously
sorted wrong.
  • Loading branch information
singpolyma committed Jun 27, 2024
1 parent 1b7a81e commit 7b1088e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions snikket/Chat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ class Channel extends Chat {
final lastFromSync = chatMessages[chatMessages.length - 1];
if (lastFromSync != null && (lastMessageTimestamp() == null || Reflect.compare(lastFromSync.timestamp, lastMessageTimestamp()) > 0)) {
setLastMessage(lastFromSync);
client.sortChats();
client.trigger("chats/update", [this]);
}
}
Expand Down
9 changes: 7 additions & 2 deletions snikket/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class Client extends EventEmitter {
chat.setUnreadCount(detail.unreadCount);
}
}
chats.sort((a, b) -> -Reflect.compare(a.lastMessageTimestamp() ?? "0", b.lastMessageTimestamp() ?? "0"));
sortChats();
this.trigger("chats/update", chats);

stream.on("auth/password-needed", (data) -> {
Expand Down Expand Up @@ -545,7 +545,7 @@ class Client extends EventEmitter {
chatActivity(chat, false);
}
}
chats.sort((a, b) -> -Reflect.compare(a.lastMessageTimestamp() ?? "0", b.lastMessageTimestamp() ?? "0"));
sortChats();
this.trigger("chats/update", chats);
// Set self to online
if (sendAvailable) {
Expand Down Expand Up @@ -897,6 +897,11 @@ class Client extends EventEmitter {
}
}

@:allow(snikket)
private function sortChats() {
chats.sort((a, b) -> -Reflect.compare(a.lastMessageTimestamp() ?? "0", b.lastMessageTimestamp() ?? "0"));
}

@:allow(snikket)
private function sendQuery(query:GenericQuery) {
this.stream.sendIq(query.getQueryStanza(), query.handleResponse);
Expand Down

0 comments on commit 7b1088e

Please sign in to comment.