You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-10 09:22:25 +03:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user