Fix and test matrix.to alias permalinks
Fixes https://github.com/vector-im/riot-web/issues/7614 Regression of https://github.com/matrix-org/matrix-react-sdk/pull/2250
This commit is contained in:
parent
0bd1d6b778
commit
3bc5e2beb3
2 changed files with 133 additions and 4 deletions
|
@ -24,8 +24,13 @@ export const baseUrl = `https://${host}`;
|
|||
const MAX_SERVER_CANDIDATES = 3;
|
||||
|
||||
export function makeEventPermalink(roomId, eventId) {
|
||||
const permalinkBase = `${baseUrl}/#/${roomId}/${eventId}`;
|
||||
|
||||
// If the roomId isn't actually a room ID, don't try to list the servers.
|
||||
// Aliases are already routable, and don't need extra information.
|
||||
if (roomId[0] !== '!') return permalinkBase;
|
||||
const serverCandidates = pickServerCandidates(roomId);
|
||||
return `${baseUrl}/#/${roomId}/${eventId}?${encodeServerCandidates(serverCandidates)}`;
|
||||
return `${permalinkBase}${encodeServerCandidates(serverCandidates)}`;
|
||||
}
|
||||
|
||||
export function makeUserPermalink(userId) {
|
||||
|
@ -33,8 +38,14 @@ export function makeUserPermalink(userId) {
|
|||
}
|
||||
|
||||
export function makeRoomPermalink(roomId) {
|
||||
const permalinkBase = `${baseUrl}/#/${roomId}`;
|
||||
|
||||
// If the roomId isn't actually a room ID, don't try to list the servers.
|
||||
// Aliases are already routable, and don't need extra information.
|
||||
if (roomId[0] !== '!') return permalinkBase;
|
||||
|
||||
const serverCandidates = pickServerCandidates(roomId);
|
||||
return `${baseUrl}/#/${roomId}?${encodeServerCandidates(serverCandidates)}`;
|
||||
return `${permalinkBase}${encodeServerCandidates(serverCandidates)}`;
|
||||
}
|
||||
|
||||
export function makeGroupPermalink(groupId) {
|
||||
|
@ -43,7 +54,7 @@ export function makeGroupPermalink(groupId) {
|
|||
|
||||
export function encodeServerCandidates(candidates) {
|
||||
if (!candidates) return '';
|
||||
return `via=${candidates.map(c => encodeURIComponent(c)).join("&via=")}`;
|
||||
return `?via=${candidates.map(c => encodeURIComponent(c)).join("&via=")}`;
|
||||
}
|
||||
|
||||
export function pickServerCandidates(roomId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue