Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Commit

Permalink
Add missing capture for MUC URIs
Browse files Browse the repository at this point in the history
Completes matrix-org#308 fix ..
  • Loading branch information
maranda committed Mar 23, 2022
1 parent 115150d commit 2a01f96
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/xmppjs/XJSInstance.ts
Expand Up @@ -62,8 +62,8 @@ class XmppProtocol extends BifrostProtocol {

export const XMPP_PROTOCOL = new XmppProtocol();
const SEEN_MESSAGES_SIZE = 16384;
const XMPP_URI_GLOBAL_MATCH = /xmpp:[a-zA-Z0-9.-\u00c0-\u024f\u1e00-\u1eff]+@[a-zA-Z0-9.-]+/g;
const XMPP_URI_SUB_MATCH = /xmpp:(.+)@([a-zA-Z0-9.-]+)/;
const XMPP_URI_GLOBAL_MATCH = /xmpp:[a-zA-Z0-9.-\u00c0-\u024f\u1e00-\u1eff]+@[a-zA-Z0-9.-]+(\?join)?/g;
const XMPP_URI_SUB_MATCH = /xmpp:(.+)@([a-zA-Z0-9.-]+)(\?join)?/;

export class XmppJsInstance extends EventEmitter implements IBifrostInstance {
public readonly presenceCache: PresenceCache;
Expand Down Expand Up @@ -461,11 +461,16 @@ export class XmppJsInstance extends EventEmitter implements IBifrostInstance {
if (bodyMatches) {
for (const uri of bodyMatches) {
const portions = uri.match(XMPP_URI_SUB_MATCH);
if (portions.length === 3) {
const mxId = XMPP_PROTOCOL.getMxIdForProtocol(
portions[1] + "=40" + portions[2], this.config.bridge.domain, this.config.bridge.userPrefix
);
body = body.replace(uri, "https://matrix.to/#/" + mxId.userId);
if (portions.length >= 3) {
let mxId;
if (portions[3]) { // it's a MUC
mxId = `#${this.config.bridge.userPrefix}${portions[1]}_${portions[2]}:${this.config.bridge.domain}`;
} else {
mxId = XMPP_PROTOCOL.getMxIdForProtocol(
portions[1] + "=40" + portions[2], this.config.bridge.domain, this.config.bridge.userPrefix
).userId;
}
body = body.replace(uri, `https://matrix.to/#/${mxId}`);
}
}
}
Expand Down Expand Up @@ -651,7 +656,6 @@ export class XmppJsInstance extends EventEmitter implements IBifrostInstance {
}
}


private async handleMessageStanza(stanza: Element, alias: string|null) {
if (!stanza.attrs.from || !stanza.attrs.to) {
return;
Expand Down

0 comments on commit 2a01f96

Please sign in to comment.