git » sdk » commit aa4a191

Import "thin stanza" push handling

author Stephen Paul Weber
2026-11-10 03:46:44 UTC
committer Stephen Paul Weber
2026-11-10 04:08:46 UTC
parent b57dfaee832836246f4559d1c2efa182ba4a8940

Import "thin stanza" push handling

Showing fulljids isn't very helpful usually. Check if maybe it's MUC PM

borogove/Notification.hx +7 -3
test/TestClient.hx +13 -0

diff --git a/borogove/Notification.hx b/borogove/Notification.hx
index 0d115d8..ab7d0e0 100644
--- a/borogove/Notification.hx
+++ b/borogove/Notification.hx
@@ -124,14 +124,18 @@ class Notification {
 	// Assume it is an incoming message of some kind
 	@:allow(borogove)
 	private static function fromThinStanza(stanza: Stanza) {
+		final from = JID.parse(stanza.attr.get("from"));
+		final bareFrom = from.asBare().asString();
+		final mucUser = stanza.getChild("x", "http://jabber.org/protocol/muc#user");
+		final type = stanza.attr.get("type") == "groupchat" ? MessageChannel : (mucUser == null ? MessageChat : MessageChannelPrivate);
 		return new Notification(
 			"New Message",
 			"",
 			JID.parse(stanza.attr.get("to")).asBare().asString(),
-			JID.parse(stanza.attr.get("from")).asBare().asString(),
-			JID.parse(stanza.attr.get("from")).asString(),
+			bareFrom,
+			type == MessageChannel ? from.asString() : bareFrom,
 			stanza.getChildText("stanza-id", "urn:xmpp:sid:0"),
-			stanza.attr.get("type") == "groupchat" ? MessageChannel : MessageChat,
+			type,
 			null,
 			null,
 			null,
diff --git a/test/TestClient.hx b/test/TestClient.hx
index 6393d2a..106734f 100644
--- a/test/TestClient.hx
+++ b/test/TestClient.hx
@@ -66,6 +66,19 @@ class TestClient extends utest.Test {
 		Assert.isTrue(channel.isJoined);
 	}
 
+	public function testThinPushNotificationUsesBareJids() {
+		final privateMessage = borogove.Push.receive('<message xmlns="jabber:client" from="room@example.com/nick" to="test@example.com/device" type="chat"><x xmlns="http://jabber.org/protocol/muc#user"><item affiliation="member" role="participant"/></x></message>', new Dummy());
+		Assert.notNull(privateMessage);
+		Assert.equals("room@example.com", privateMessage.chatId);
+		Assert.equals("room@example.com", privateMessage.senderId);
+		Assert.equals(MessageChannelPrivate, privateMessage.type);
+
+		final groupMessage = borogove.Push.receive('<message xmlns="jabber:client" from="room@example.com/nick" to="test@example.com/device" type="groupchat"><x xmlns="http://jabber.org/protocol/muc#user"><item affiliation="member" role="participant"/></x></message>', new Dummy());
+		Assert.notNull(groupMessage);
+		Assert.equals("room@example.com", groupMessage.chatId);
+		Assert.equals(MessageChannel, groupMessage.type);
+	}
+
 	public function testChannelPrivateMessageDoesNotCreateChat() {
 		final client = new Client("test@example.com", new Dummy());
 		client.stream.onStanza(Stanza.parse('<message xmlns="jabber:client" from="room@example.com/nick" to="test@example.com" type="chat" id="pm-1"><body>secret</body><x xmlns="http://jabber.org/protocol/muc#user"><item affiliation="member" role="participant"/></x></message>'));