From a1a822c5b64eb4e31edbf9cbd4bd12f3926f084b Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:50:51 +0530 Subject: [PATCH] Fix selecting tombstone room opens replacement room (#1820) --- src/app/utils/matrix.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/utils/matrix.ts b/src/app/utils/matrix.ts index 55e16a9..278bb46 100644 --- a/src/app/utils/matrix.ts +++ b/src/app/utils/matrix.ts @@ -14,6 +14,8 @@ import { } from 'matrix-js-sdk'; import { IImageInfo, IThumbnailContent, IVideoInfo } from '../../types/matrix/common'; import { AccountDataEvent } from '../../types/matrix/accountData'; +import { getStateEvent } from './room'; +import { StateEvent } from '../../types/matrix/room'; export const matchMxId = (id: string): RegExpMatchArray | null => id.match(/^([@!$+#])(\S+):(\S+)$/); @@ -42,8 +44,12 @@ export const parseMatrixToUrl = (url: string): [string | undefined, string | und export const getCanonicalAliasRoomId = (mx: MatrixClient, alias: string): string | undefined => mx.getRooms()?.find((room) => room.getCanonicalAlias() === alias)?.roomId; -export const getCanonicalAliasOrRoomId = (mx: MatrixClient, roomId: string): string => - mx.getRoom(roomId)?.getCanonicalAlias() || roomId; +export const getCanonicalAliasOrRoomId = (mx: MatrixClient, roomId: string): string => { + const room = mx.getRoom(roomId); + if (!room) return roomId; + if (getStateEvent(room, StateEvent.RoomTombstone) !== undefined) return roomId; + return room.getCanonicalAlias() || roomId; +}; export const getImageInfo = (img: HTMLImageElement, fileOrBlob: File | Blob): IImageInfo => { const info: IImageInfo = {};