git » sdk » commit 45a54a2

Sort messages before choosing what is last one

author Stephen Paul Weber
2025-11-11 15:33:34 UTC
committer Stephen Paul Weber
2025-11-11 15:54:32 UTC
parent af411fa8d4f5f3e72eba8c0a286bc24e3a487641

Sort messages before choosing what is last one

Instead of using MAM order use time order, since edits are in the past

borogove/Chat.hx +4 -0

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 448b0b7..2886fd3 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -1247,6 +1247,10 @@ class Channel extends Chat {
 				} else {
 					inSync = true;
 					sync = null;
+
+					// Sort by time so that eg edits go into the past
+					chatMessages.sort((x, y) -> Reflect.compare(x.timestamp, y.timestamp));
+
 					final lastFromSync = chatMessages[chatMessages.length - 1];
 					if (lastFromSync != null && (lastMessage?.timestamp == null || Reflect.compare(lastFromSync.timestamp, lastMessage?.timestamp) > 0)) {
 						setLastMessage(lastFromSync);