git » sdk » commit 1b7aa3c

Don't try to combine when there's one message

author Eric Roberts
2026-09-21 19:28:56 UTC
committer Stephen Paul Weber
2026-09-21 19:29:50 UTC
parent 4a3db8a247eab612cd43977cfe8eaa0d502fbba5

Don't try to combine when there's one message

Combining will make it so there is always a versions list with the
message, which causes the pencil icon to show.

borogove/ChatMessageCombiner.hx +2 -0
test/TestChatMessageCombiner.hx +18 -0

diff --git a/borogove/ChatMessageCombiner.hx b/borogove/ChatMessageCombiner.hx
index 162376e..be89ab2 100644
--- a/borogove/ChatMessageCombiner.hx
+++ b/borogove/ChatMessageCombiner.hx
@@ -26,6 +26,8 @@ class ChatMessageCombiner {
 	}
 
 	private static function combineMessages(messages: Array<ChatMessage>): ChatMessage {
+		if (messages.length == 1) return messages[0];
+
 		final original = messages.find(message -> message.versions.length == 0) ?? messages[0];
 		final combinedVersions = combineVersions(original, messages);
 		final newest = combinedVersions[0];
diff --git a/test/TestChatMessageCombiner.hx b/test/TestChatMessageCombiner.hx
index 149b170..0a7f468 100644
--- a/test/TestChatMessageCombiner.hx
+++ b/test/TestChatMessageCombiner.hx
@@ -8,6 +8,24 @@ import borogove.Message;
 
 @:access(borogove)
 class TestChatMessageCombiner extends utest.Test {
+	public function testCombineUniqueMessagesKeepsVersionsEmpty() {
+		final input = [
+			message({ localId: "first" }),
+			message({ localId: "second" }),
+			message({ localId: "third" })
+		];
+		for (m in input) Assert.equals(0, m.versions.length);
+
+		final combined = ChatMessageCombiner.combine(input);
+
+		final localIds = combined.map(m -> m.localId);
+		localIds.sort(Reflect.compare);
+		Assert.equals(3, combined.length);
+		Assert.same(["first", "second", "third"], localIds);
+		for (m in combined) Assert.equals(0, m.versions.length);
+		for (m in input) Assert.equals(0, m.versions.length);
+	}
+
 	public function testCombineCorrections() {
 		final original = message({ localId: "original", timestamp: "2024-01-01T00:00:00Z", sortId: "m", body: "old" });
 		final correction = correction(original, "version", "2024-01-02T00:00:00Z", "new");