diff --git a/snikket/Chat.hx b/snikket/Chat.hx index 9f349f1..27c6b35 100644 --- a/snikket/Chat.hx +++ b/snikket/Chat.hx @@ -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]); } } diff --git a/snikket/Client.hx b/snikket/Client.hx index fdd919d..86bf715 100644 --- a/snikket/Client.hx +++ b/snikket/Client.hx @@ -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) -> { @@ -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) { @@ -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);