git » sdk » commit 7b5bd51

Don't try to get sortid for messages that don't need one

author Stephen Paul Weber
2026-09-21 14:56:01 UTC
committer Stephen Paul Weber
2026-09-21 14:56:01 UTC
parent 74232e5ae78cc3dc95f8ec962fdaf2142d3cba04

Don't try to get sortid for messages that don't need one

Such as subject only messages

borogove/Chat.hx +1 -1
borogove/ChatMessageBuilder.hx +1 -0
borogove/Message.hx +24 -24

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 738ae1c..76e3c51 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -2266,7 +2266,7 @@ class Channel extends Chat {
 	private function prepareIncomingMessage(message:ChatMessageBuilder, stanza:Stanza) {
 		message.syncPoint = inSync;
 		if (message.type == MessageChat) message.type = MessageChannelPrivate;
-		if (message.sortId == null) {
+		if (message.sortId == null && (message.text != null || message.attachments.length > 0)) {
 			if (sortId != null && message.type == MessageChannel) {
 				final lower = sortId;
 				sortId = message.sortId = FractionalIndexing.between(lower, null, FractionalIndexing.BASE_95_DIGITS);
diff --git a/borogove/ChatMessageBuilder.hx b/borogove/ChatMessageBuilder.hx
index b5a5742..fe9aee9 100644
--- a/borogove/ChatMessageBuilder.hx
+++ b/borogove/ChatMessageBuilder.hx
@@ -107,6 +107,7 @@ class ChatMessageBuilder {
 		Body text of this message or NULL
 	**/
 	@:allow(borogove.Message)
+	@:allow(borogove.Channel)
 	private var text: Null<String> = null;
 
 	/**
diff --git a/borogove/Message.hx b/borogove/Message.hx
index 0534d3d..acaf824 100644
--- a/borogove/Message.hx
+++ b/borogove/Message.hx
@@ -220,30 +220,6 @@ class Message {
 			return new Message(msg.chatId(), msg.senderId, msg.threadId, UnknownMessageStanza(stanza), encryptionInfo);
 		}
 
-		if (addContext != null) msg = addContext(msg, stanza);
-		final timestamp = msg.timestamp ?? Date.format(std.Date.now());
-		msg.timestamp = timestamp;
-
-		final reactionsEl = stanza.getChild("reactions", "urn:xmpp:reactions:0");
-		if (reactionsEl != null) {
-			// A reaction update is never also a chat message
-			final reactions = reactionsEl.allTags("reaction").map((r) -> r.getText());
-			final reactionId = reactionsEl.attr.get("id");
-			if (reactionId != null) {
-				return new Message(msg.chatId(), msg.senderId, msg.threadId, ReactionUpdateStanza(new ReactionUpdate(
-					stanza.attr.get("id") ?? ID.unique(),
-					isGroupchat ? reactionId : null,
-					isGroupchat ? msg.chatId() : null,
-					isGroupchat ? null : reactionId,
-					msg.chatId(),
-					msg.senderId ?? throw "no sender",
-					timestamp,
-					reactions.map(text -> new Reaction(msg.senderId ?? throw "no sender", timestamp, text, msg.localId)),
-					EmojiReactions
-				)), encryptionInfo);
-			}
-		}
-
 		for (ref in stanza.allTags("reference", "urn:xmpp:reference:0")) {
 			if (ref.attr.get("begin") == null && ref.attr.get("end") == null) {
 				final sims = ref.getChild("media-sharing", "urn:xmpp:sims:1");
@@ -273,6 +249,30 @@ class Message {
 			msg.localId = jmi.attr.get("id");
 		}
 
+		if (addContext != null) msg = addContext(msg, stanza);
+		final timestamp = msg.timestamp ?? Date.format(std.Date.now());
+		msg.timestamp = timestamp;
+
+		final reactionsEl = stanza.getChild("reactions", "urn:xmpp:reactions:0");
+		if (reactionsEl != null) {
+			// A reaction update is never also a chat message
+			final reactions = reactionsEl.allTags("reaction").map((r) -> r.getText());
+			final reactionId = reactionsEl.attr.get("id");
+			if (reactionId != null) {
+				return new Message(msg.chatId(), msg.senderId, msg.threadId, ReactionUpdateStanza(new ReactionUpdate(
+					stanza.attr.get("id") ?? ID.unique(),
+					isGroupchat ? reactionId : null,
+					isGroupchat ? msg.chatId() : null,
+					isGroupchat ? null : reactionId,
+					msg.chatId(),
+					msg.senderId ?? throw "no sender",
+					timestamp,
+					reactions.map(text -> new Reaction(msg.senderId ?? throw "no sender", timestamp, text, msg.localId)),
+					EmojiReactions
+				)), encryptionInfo);
+			}
+		}
+
 		final retract = stanza.getChild("retract", "urn:xmpp:message-retract:1");
 		final fasten = stanza.getChild("apply-to", "urn:xmpp:fasten:0");
 		final moderated = retract?.getChild("moderated", "urn:xmpp:message-retract:1") ?? fasten?.getChild("moderated", "urn:xmpp:message-moderate:0");