Skip to content

Commit

Permalink
resolve aliases and get via servers before storing watch list
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Aug 20, 2024
1 parent f526b97 commit a19241e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/commands/WatchUnwatchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Permalinks, RichReply } from "matrix-bot-sdk";

// !mjolnir watch <room alias or ID>
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?";
Expand Down
10 changes: 7 additions & 3 deletions src/models/PolicyList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down

0 comments on commit a19241e

Please sign in to comment.