diff --git a/changelog.d/655.bugfix b/changelog.d/655.bugfix new file mode 100644 index 00000000..b1854e72 --- /dev/null +++ b/changelog.d/655.bugfix @@ -0,0 +1 @@ +Tell the homeserver if a room alias request failed. \ No newline at end of file diff --git a/src/discordas.ts b/src/discordas.ts index baebd985..c15c7678 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -193,10 +193,14 @@ async function run(): Promise { }); if (config.bridge.disablePortalBridging !== true) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - appservice.on("query.room", async (roomAlias: string, createRoom: (opts: any) => Promise) => { + appservice.on("query.room", async (roomAlias: string, createRoom: (opts: unknown) => Promise) => { try { const createRoomOpts = await roomhandler.OnAliasQuery(roomAlias); + if (!createRoomOpts) { + // This will tell the homeserver that the alias request failed. + await createRoom(false); + return; + } await createRoom(createRoomOpts); await roomhandler.OnAliasQueried(roomAlias, createRoomOpts.__roomId); } catch (err) { diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts index 1febaba5..996f7bb0 100644 --- a/src/matrixroomhandler.ts +++ b/src/matrixroomhandler.ts @@ -37,6 +37,19 @@ const JOIN_ROOM_SCHEDULE = [ 900000, // 15 minutes ]; +export interface ICreationOptions { + __roomId: string; + initial_state: { + content: { + join_rule: string, + }, + state_key: string, + type: string, + }[]; + room_alias_name: string; + visibility: string; +} + export class MatrixRoomHandler { private botUserId: string; constructor( @@ -56,12 +69,13 @@ export class MatrixRoomHandler { } ); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this.bridge.on("thirdparty.location.remote", (protocol: string, fields: any, cb: (response: any) => void) => { - this.tpGetLocation(protocol, fields) - .then(cb) - .catch((err) => log.warn("Failed to get remote locations", err)); - }); + this.bridge.on("thirdparty.location.remote", + (protocol: string, fields: unknown, cb: (response: IThirdPartyLookup[]) => void) => { + this.tpGetLocation(protocol, fields) + .then(cb) + .catch((err) => log.warn("Failed to get remote locations", err)); + }, + ); // These are not supported. this.bridge.on("thirdparty.location.matrix", (matrixId: string, cb: (response: null) => void) => { @@ -133,8 +147,8 @@ export class MatrixRoomHandler { await Promise.all(promiseList); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public async OnAliasQuery(alias: string): Promise { + + public async OnAliasQuery(alias: string): Promise { const aliasLocalpart = alias.substring("#".length, alias.indexOf(":")); log.info("Got request for #", aliasLocalpart); const srvChanPair = aliasLocalpart.substring("_discord_".length).split("_", ROOM_NAME_PARTS); @@ -247,7 +261,7 @@ export class MatrixRoomHandler { channel: Discord.TextChannel, alias: string, aliasLocalpart: string - ) { + ): Promise { const remote = new RemoteStoreRoom(`discord_${channel.guild.id}_${channel.id}`, { /* eslint-disable @typescript-eslint/naming-convention */ discord_channel: channel.id, @@ -258,7 +272,7 @@ export class MatrixRoomHandler { update_topic: 1, /* eslint-enable @typescript-eslint/naming-convention */ }); - const creationOpts = { + const creationOpts: ICreationOptions = { /* eslint-disable @typescript-eslint/naming-convention */ initial_state: [ { @@ -273,7 +287,7 @@ export class MatrixRoomHandler { visibility: this.config.room.defaultVisibility, /* eslint-enable @typescript-eslint/naming-convention */ }; - // We need to tempoarily store this until we know the room_id. + // We need to temporarily store this until we know the room_id. await this.roomStore.linkRooms( new MatrixStoreRoom(alias), remote,