From e40884c19c02f77fa3b2661fa50b3ed521c938f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Wed, 9 Jul 2025 22:43:53 +0200 Subject: [PATCH] Fix: Horrible direct chat invitation UX #118 --- src/MatrixRoomHandler.ts | 8 ++++++++ src/ProtoHacks.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/MatrixRoomHandler.ts b/src/MatrixRoomHandler.ts index c9c7bb7e..d47917d6 100644 --- a/src/MatrixRoomHandler.ts +++ b/src/MatrixRoomHandler.ts @@ -285,6 +285,7 @@ export class MatrixRoomHandler { if (!this.bridge) { throw Error("Couldn't handleIncomingIM, bridge was not defined"); } + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) log.debug(`Handling incoming IM from ${data.sender}`); data.message.body = entityDecode(data.message.body); // First, find out who the message was intended for. @@ -357,6 +358,7 @@ export class MatrixRoomHandler { if (!this.bridge) { throw Error("Couldn't handleIncomingChatMsg, bridge was not defined"); } + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) log.debug(`Handling incoming chat from ${data.sender} (${data.conv.name})`); data.message.body = entityDecode(data.message.body); const acctId = Util.createRemoteId(data.account.protocol_id, data.account.username); @@ -429,6 +431,7 @@ export class MatrixRoomHandler { } private async handleChatInvite(data: IChatInvite) { + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) if (!this.bridge) { throw Error("Couldn't handleChatInvite, bridge was not defined"); } @@ -465,6 +468,7 @@ export class MatrixRoomHandler { } private async handleRemoteUserState(data: IUserStateChanged) { + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) if (!this.bridge) { throw Error("Couldn't handleRemoteUserState, bridge was not defined"); } @@ -529,6 +533,7 @@ export class MatrixRoomHandler { } private async handleTopic(data: IChatTopicState) { + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) if (!this.bridge) { throw Error("Couldn't handleTopic, bridge was not defined"); } @@ -558,6 +563,7 @@ export class MatrixRoomHandler { } } private async handleIMTyping(data: IChatTyping) { + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) if (!this.bridge) { throw Error("Couldn't handleIMTyping, bridge was not defined"); } @@ -579,6 +585,7 @@ export class MatrixRoomHandler { } private async handleChatTyping(data: IChatTyping) { + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) if (!this.bridge) { throw Error("Couldn't handleTyping, bridge was not defined"); } @@ -593,6 +600,7 @@ export class MatrixRoomHandler { } private async handleReadReceipt(data: IChatReadReceipt) { + data.sender = ProtoHacks.removeJabberResourceInMXID(data.account.protocol_id, data.sender) if (!this.bridge) { throw Error("Couldn't handleTyping, bridge was not defined"); } diff --git a/src/ProtoHacks.ts b/src/ProtoHacks.ts index 77eaeef6..3fe42960 100644 --- a/src/ProtoHacks.ts +++ b/src/ProtoHacks.ts @@ -76,4 +76,11 @@ export class ProtoHacks { } return senderId; } + + public static removeJabberResourceInMXID(protocolId: string, id: string): string { + if (protocolId === PRPL_XMPP) { + return id.split('/')[0] + } + return id; + } }