From de1177123073fc295c86a907829c9904a19409cd Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 20 Aug 2024 15:58:09 -0700 Subject: [PATCH 1/2] resolve aliases and get via servers before storing watch list --- src/models/PolicyList.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/models/PolicyList.ts b/src/models/PolicyList.ts index 0009504..af0981a 100644 --- a/src/models/PolicyList.ts +++ b/src/models/PolicyList.ts @@ -659,10 +659,13 @@ export class PolicyListManager { if (!permalink.roomIdOrAlias) return null; let roomId: string; - let viaServers; + let viaServers: string[]; if (permalink.roomIdOrAlias.startsWith("!")) { + // get alias and then use alias to get via servers + const alias = await this.mjolnir.client.getPublishedAlias(permalink.roomIdOrAlias) + const roomInformation = await this.mjolnir.client.lookupRoomAlias(alias) roomId = permalink.roomIdOrAlias - viaServers = permalink.viaServers + viaServers = roomInformation.residentServers } else { const roomInfo = await this.mjolnir.client.lookupRoomAlias(permalink.roomIdOrAlias) roomId = roomInfo.roomId @@ -682,7 +685,8 @@ export class PolicyListManager { return null; } - const list = await this.addPolicyList(roomId, roomRef); + const newRef = Permalinks.forRoom(roomId, viaServers) + const list = await this.addPolicyList(roomId, newRef); await this.storeWatchedPolicyLists(); From 914af63c37c21268059f37ebfbda9c88051f8de8 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 22 Aug 2024 14:14:18 -0700 Subject: [PATCH 2/2] handle case where there's no alias --- src/models/PolicyList.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/models/PolicyList.ts b/src/models/PolicyList.ts index af0981a..6a82e78 100644 --- a/src/models/PolicyList.ts +++ b/src/models/PolicyList.ts @@ -661,11 +661,17 @@ export class PolicyListManager { let roomId: string; let viaServers: string[]; if (permalink.roomIdOrAlias.startsWith("!")) { - // get alias and then use alias to get via servers + // if we only have a room id, see if there's an alias we can use to get any possible + // via servers const alias = await this.mjolnir.client.getPublishedAlias(permalink.roomIdOrAlias) - const roomInformation = await this.mjolnir.client.lookupRoomAlias(alias) - roomId = permalink.roomIdOrAlias - viaServers = roomInformation.residentServers + if (alias) { + const roomInformation = await this.mjolnir.client.lookupRoomAlias(alias) + roomId = permalink.roomIdOrAlias + viaServers = roomInformation.residentServers + } else { + roomId = permalink.roomIdOrAlias + viaServers = permalink.viaServers + } } else { const roomInfo = await this.mjolnir.client.lookupRoomAlias(permalink.roomIdOrAlias) roomId = roomInfo.roomId