git » sdk » commit 895a298

Need chatId to make senderId

author Stephen Paul Weber
2026-05-27 01:04:00 UTC
committer Stephen Paul Weber
2026-05-27 01:04:00 UTC
parent 26bf099192d05526a73d17477c3f0f4f2dc8ebd4

Need chatId to make senderId

borogove/ChatMessageBuilder.hx +4 -2
borogove/Message.hx +13 -10

diff --git a/borogove/ChatMessageBuilder.hx b/borogove/ChatMessageBuilder.hx
index 029e743..c7c1771 100644
--- a/borogove/ChatMessageBuilder.hx
+++ b/borogove/ChatMessageBuilder.hx
@@ -329,8 +329,8 @@ class ChatMessageBuilder {
 
 		@returns sender ID for this message
 	**/
-	public function get_senderId():String {
-		return senderId ?? sender?.asString() ?? throw "sender is null";
+	public function get_senderId(): Null<String> {
+		return senderId ?? sender?.asString();
 	}
 
 	@:allow(borogove)
@@ -347,6 +347,8 @@ class ChatMessageBuilder {
 		if (serverId == null && localId == null) throw "Cannot build a ChatMessage with no id";
 		final to = this.to ?? (isIncoming() ? new JID(null, "inbound.to.me.example.com") : null);
 		if (to == null) throw "Cannot build a ChatMessage with no to";
+		final senderId = this.senderId;
+		if (senderId == null) throw "Cannot builder a ChatMessage with no sender";
 		final from = this.from ?? (senderId == null ? null : JID.parse(senderId));
 		if (from == null) throw "Cannot build a ChatMessage with no from";
 		final sender = this.sender ?? from.asBare();
diff --git a/borogove/Message.hx b/borogove/Message.hx
index 07bf735..1ec0a35 100644
--- a/borogove/Message.hx
+++ b/borogove/Message.hx
@@ -51,9 +51,9 @@ class Message {
 	public final encryption: Null<EncryptionInfo>;
 	public final parsed: MessageStanza;
 
-	private function new(chatId: String, senderId: String, threadId: Null<String>, parsed: MessageStanza, encryption:Null<EncryptionInfo>) {
+	private function new(chatId: String, senderId: Null<String>, threadId: Null<String>, parsed: MessageStanza, encryption:Null<EncryptionInfo>) {
 		this.chatId = chatId;
-		this.senderId = senderId;
+		this.senderId = senderId ?? throw "no sender id";
 		this.threadId = threadId;
 		this.parsed = parsed;
 		this.encryption = encryption;
@@ -88,8 +88,6 @@ class Message {
 		if (msg.type == MessageChat && stanza.getChild("x", "http://jabber.org/protocol/muc#user") != null) {
 			msg.type = MessageChannelPrivate;
 		}
-		final occupantId = stanza.getChild("occupant-id", "urn:xmpp:occupant-id:0")?.attr?.get("id");
-		msg.senderId = occupantId != null ? msg.chatId() + "/" + occupantId : (msg.type == MessageChannel || msg.type == MessageChannelPrivate ? msg.from : msg.from?.asBare())?.asString();
 		final localJidBare = localJid.asBare();
 		final domain = localJid.domain;
 		final to = stanza.attr.get("to");
@@ -195,6 +193,11 @@ class Message {
 		msg.replyTo = ({ iterator: () -> replyTo.keys() }).map((s) -> JID.parse(s));
 		msg.replyTo.sort((x, y) -> Reflect.compare(x.asString(), y.asString()));
 
+		if (msg.senderId == null) {
+			final occupantId = stanza.getChild("occupant-id", "urn:xmpp:occupant-id:0")?.attr?.get("id");
+			msg.senderId = occupantId != null ? msg.chatId() + "/" + occupantId : (msg.type == MessageChannel || msg.type == MessageChannelPrivate ? msg.from : msg.from?.asBare())?.asString();
+		}
+
 		final msgFrom = msg.from;
 		// Not sure why the compiler things we need to use Null<JID> with findFast
 		if (msg.direction == MessageReceived && msgFrom != null && Util.findFast(msg.replyTo, @:nullSafety(Off) (r: Null<JID>) -> r.asBare().equals(msgFrom.asBare())) == null) {
@@ -218,9 +221,9 @@ class Message {
 					isGroupchat ? msg.chatId() : null,
 					isGroupchat ? null : reactionId,
 					msg.chatId(),
-					msg.senderId,
+					msg.senderId ?? throw "no sender",
 					timestamp,
-					reactions.map(text -> new Reaction(msg.senderId, timestamp, text, msg.localId)),
+					reactions.map(text -> new Reaction(msg.senderId ?? throw "no sender", timestamp, text, msg.localId)),
 					EmojiReactions
 				)), encryptionInfo);
 			}
@@ -310,9 +313,9 @@ class Message {
 					isGroupchat ? msg.chatId() : null,
 					isGroupchat ? null : replyToID,
 					msg.chatId(),
-					msg.senderId,
+					msg.senderId ?? throw "no sender",
 					timestamp,
-					[new Reaction(msg.senderId, timestamp, text.trim(), msg.localId)],
+					[new Reaction(msg.senderId ?? throw "no sender", timestamp, text.trim(), msg.localId)],
 					AppendReactions
 				)), encryptionInfo);
 			}
@@ -330,9 +333,9 @@ class Message {
 								isGroupchat ? msg.chatId() : null,
 								isGroupchat ? null : replyToID,
 								msg.chatId(),
-								msg.senderId,
+								msg.senderId ?? throw "no sender",
 								timestamp,
-								[new CustomEmojiReaction(msg.senderId, timestamp, els[0].attr.get("alt") ?? "", hash.serializeUri(), msg.localId)],
+								[new CustomEmojiReaction(msg.senderId ?? throw "no sender", timestamp, els[0].attr.get("alt") ?? "", hash.serializeUri(), msg.localId)],
 								AppendReactions
 							)), encryptionInfo);
 						}