From a19241e2ad902dcf65d8fa2b695162ed0d1caafa Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 20 Aug 2024 15:58:09 -0700 Subject: [PATCH] resolve aliases and get via servers before storing watch list --- src/commands/WatchUnwatchCommand.ts | 1 + src/models/PolicyList.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commands/WatchUnwatchCommand.ts b/src/commands/WatchUnwatchCommand.ts index 0ffc05b7..9bfc0a2e 100644 --- a/src/commands/WatchUnwatchCommand.ts +++ b/src/commands/WatchUnwatchCommand.ts @@ -19,6 +19,7 @@ import { Permalinks, RichReply } from "matrix-bot-sdk"; // !mjolnir watch export async function execWatchCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { + const list = await mjolnir.policyListManager.watchList(Permalinks.forRoom(parts[2])); if (!list) { const replyText = "Cannot watch list due to error - is that a valid room alias?"; diff --git a/src/models/PolicyList.ts b/src/models/PolicyList.ts index 00095042..af0981a0 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();