git » sdk » commit aff1ebd

New chats should go after pinned chats

author Stephen Paul Weber
2026-03-12 02:35:21 UTC
committer Stephen Paul Weber
2026-03-12 02:35:21 UTC
parent 819bcf4719e73836d2b934ddeda2eed008274ce6

New chats should go after pinned chats

Not blindly unshift onto the front

borogove/Client.hx +2 -2
test/TestClient.hx +11 -0

diff --git a/borogove/Client.hx b/borogove/Client.hx
index 1825bb7..8e9f193 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -1034,8 +1034,8 @@ class Client extends EventEmitter {
 		}
 		final chat = new DirectChat(this, this.stream, this.persistence, chatId);
 		persistence.storeChats(accountId(), [chat]);
-		chats.unshift(chat);
-		if (triggerIfNew) this.trigger("chats/update", [chat]);
+		chats.push(chat);
+		chatActivity(chat, triggerIfNew);
 		return chat;
 	}
 
diff --git a/test/TestClient.hx b/test/TestClient.hx
index 670db8e..61f3d97 100644
--- a/test/TestClient.hx
+++ b/test/TestClient.hx
@@ -41,6 +41,17 @@ class TestClient extends utest.Test {
 		Assert.equals("Test Name", client.displayName());
 	}
 
+	public function testSortAfterDirectChat() {
+		final persistence = new Dummy();
+		final client = new Client("test@example.com", persistence);
+		final pinned = client.getDirectChat("pinned@example.com");
+		pinned.togglePinned();
+		client.getDirectChat("notpinned@example.com");
+		Assert.equals(2, client.chats.length);
+		Assert.equals(pinned, client.chats[0]);
+		Assert.equals(pinned, client.getChats()[0]);
+	}
+
 	public function testStart(async: Async) {
 		final persistence = new Dummy();
 		final client = new Client("test@example.com", persistence);