matrix.to urls for aliases don't need a via param (#348)

This commit is contained in:
Jess Porter 2022-08-18 09:37:30 +01:00 committed by GitHub
parent 625b62ce6d
commit 10b7233e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -226,7 +226,8 @@ export async function replaceRoomIdsWithPills(mjolnir: Mjolnir, text: string, ro
const regexRoomId = new RegExp(escapeRegex(roomId), "g");
content.body = content.body.replace(regexRoomId, alias);
if (content.formatted_body) {
content.formatted_body = content.formatted_body.replace(regexRoomId, `<a href="${Permalinks.forRoom(alias, viaServers)}">${alias}</a>`);
const permalink = Permalinks.forRoom(alias, alias !== roomId ? [] : viaServers);
content.formatted_body = content.formatted_body.replace(regexRoomId, `<a href="${permalink}">${alias}</a>`);
}
}

View File

@ -20,13 +20,13 @@ describe("Test: utils", function() {
const out = await replaceRoomIdsWithPills(
this.mjolnir,
`it's fun here in ${this.mjolnir.managementRoomId}`,
new Set([this.mjolnir.managementRoomId])
new Set([this.mjolnir.managementRoomId, "!myfaketestid:example.com"])
);
const ourHomeserver = new UserID(await this.mjolnir.client.getUserId()).domain;
assert.equal(
out.formatted_body,
`it's fun here in <a href="https://matrix.to/#/${managementRoomAlias}?via=${ourHomeserver}">${managementRoomAlias}</a>`
`it's fun here in <a href="https://matrix.to/#/${managementRoomAlias}">${managementRoomAlias}</a>`
);
});
});