git » sdk » commit 18e3a97

Improve chat sorting

author Stephen Paul Weber
2025-12-01 15:06:40 UTC
committer Stephen Paul Weber
2025-12-01 15:06:40 UTC
parent 45858a09bd19a30ed2207de5544819a0dcf5d34f

Improve chat sorting

Especially make sure closed chats are always at the end so it doesn't
mess up the chatActivity logic and preserved pinned chats at the top.

borogove/Chat.hx +1 -0
borogove/Client.hx +7 -3

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 80dcaa9..7c3ef75 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -1249,6 +1249,7 @@ class DirectChat extends Chat {
 		persistence.storeChats(client.accountId(), [this]);
 		if (!isBlocked) sendChatState("gone", null);
 		client.trigger("chats/update", [this]);
+		client.sortChats();
 	}
 }
 
diff --git a/borogove/Client.hx b/borogove/Client.hx
index 2686352..d12538b 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -1465,9 +1465,13 @@ class Client extends EventEmitter {
 	@:allow(borogove)
 	private function sortChats() {
 		chats.sort((a, b) -> {
-			if (a.uiState == Pinned && b.uiState != Pinned) return -1;
-			if (b.uiState == Pinned && a.uiState != Pinned) return 1;
-			return -Reflect.compare(a.lastMessage?.timestamp ?? "0", b.lastMessage?.timestamp ?? "0");
+			if (a.uiState == b.uiState) {
+				final tcompare = -Reflect.compare(a.lastMessage?.timestamp ?? "0", b.lastMessage?.timestamp ?? "0");
+				if (tcompare != 0) return tcompare;
+				return Reflect.compare(a.getDisplayName(), b.getDisplayName());
+			} else {
+				return Reflect.compare(a.uiState, b.uiState);
+			}
 		});
 	}