git » sdk » commit 5888d2b

Presetve stanza ID for call updates

author Stephen Paul Weber
2026-11-03 20:39:43 UTC
committer Stephen Paul Weber
2026-11-09 14:58:42 UTC
parent a3fc6ef4f59bebe2146d6ee34719bfc3499051fc

Presetve stanza ID for call updates

Use the callSid as the "main" ID for the propose that they all join
against, but keep the individual ids for the versions.

borogove/Message.hx +9 -6
test/persistence-tests.ts +90 -0

diff --git a/borogove/Message.hx b/borogove/Message.hx
index ea4cdff..70eda18 100644
--- a/borogove/Message.hx
+++ b/borogove/Message.hx
@@ -243,13 +243,20 @@ class Message {
 			msg.type = MessageCall;
 			msg.payloads.push(jmi);
 			if (msg.text == null) msg.text = "call " + jmi.name;
-			// The session id is what really identifies us
-			msg.localId = jmi.attr.get("id");
 		}
 
 		if (addContext != null) msg = addContext(msg, stanza);
 		final timeSent = msg.timeSent ?? msg.timeReceived ?? Date.format(std.Date.now());
 
+		if (jmi != null && jmi.name != "accept") {
+			final version = msg.build();
+			// The session id is what really identifies us
+			msg.localId = jmi.attr.get("id");
+			if (jmi.name != "propose") {
+				msg.versions = [version];
+			}
+		}
+
 		final xep0070 = stanza.getChild("confirm", "http://jabber.org/protocol/http-auth");
 		if (xep0070 != null) {
 			final threadId = msg.threadId;
@@ -261,10 +268,6 @@ class Message {
 			}
 		}
 
-		if (jmi != null && jmi.name != "accept" && jmi.name != "propose") {
-			msg.versions = [msg.build()];
-		}
-
 		final reactionsEl = stanza.getChild("reactions", "urn:xmpp:reactions:0");
 		if (reactionsEl != null) {
 			// A reaction update is never also a chat message
diff --git a/test/persistence-tests.ts b/test/persistence-tests.ts
index feffe35..6781e07 100644
--- a/test/persistence-tests.ts
+++ b/test/persistence-tests.ts
@@ -2373,6 +2373,96 @@ export function sharedPersistenceTests(test) {
 		}
 	});
 
+	test("getChatUnreadDetails keeps outgoing call direction after a later remote status", async ({
+		borogove,
+		persistence,
+	}) => {
+		const account = "ordering-alice@example.com";
+		const contact = "ordering-hatter@example.com";
+		const sid = "ordering-outgoing-call";
+		const proposedAt = "2024-01-01T00:00:00.000Z";
+		const rejectedAt = "2024-01-01T00:00:01.000Z";
+		const callMessage = ({
+			direction,
+			event,
+			localId,
+			sortId,
+			timeReceived,
+			serverId,
+			versions,
+		}: {
+			direction: number;
+			event: string;
+			localId?: string;
+			sortId: string;
+			timeReceived: string;
+			serverId?: string;
+			versions?: any[];
+		}) => {
+			const received = direction === borogove.MessageDirection.MessageReceived;
+			const from = received ? contact : account;
+			const to = received ? account : contact;
+			const builder = new borogove.ChatMessageBuilder({
+				localId: localId ?? sid,
+				serverId: serverId ?? null,
+				serverIdBy: serverId == null ? null : account,
+				senderId: from,
+				direction,
+				type: borogove.MessageType.MessageCall,
+				timeReceived,
+				versions: versions ?? [],
+				payloads: [
+					borogove.Stanza.parse(
+						`<${event} xmlns="urn:xmpp:jingle-message:0" id="${sid}"/>`,
+					),
+				],
+				text: "call " + event,
+			});
+			builder.sortId = sortId;
+			builder.to = borogove.JID.parse(to);
+			builder.from = borogove.JID.parse(from);
+			builder.recipients = [builder.to];
+			builder.replyTo = [builder.from];
+			return builder.build();
+		};
+
+		const propose = callMessage({
+			direction: borogove.MessageDirection.MessageSent,
+			event: "propose",
+			sortId: "order-b1",
+			timeReceived: proposedAt,
+			serverId: "ordering-propose-server-id",
+		});
+		const rejectVersion = callMessage({
+			direction: borogove.MessageDirection.MessageReceived,
+			event: "reject",
+			localId: "ordering-reject-stanza-id",
+			sortId: "order-b2",
+			timeReceived: rejectedAt,
+			serverId: "ordering-reject-server-id",
+		});
+		const reject = callMessage({
+			direction: borogove.MessageDirection.MessageReceived,
+			event: "reject",
+			sortId: "order-b2",
+			timeReceived: rejectedAt,
+			serverId: "ordering-reject-server-id",
+			versions: [rejectVersion],
+		});
+
+		await persistence.storeMessages(account, [propose]);
+		await persistence.storeMessages(account, [reject]);
+
+		const chat = Object.create(borogove.DirectChat.prototype);
+		chat.chatId = contact;
+		chat.readUpToId = "no-such-message";
+		chat.notificationsFiltered = () => false;
+
+		const details = await persistence.getChatUnreadDetails(account, chat);
+		expect(details.message.direction).toBe(
+			borogove.MessageDirection.MessageSent,
+		);
+	});
 }
 
 type TestKeyPair = {