From 8012315a7e626e6537735e12c306ff0688d314e8 Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Thu, 31 Dec 2020 17:11:02 +0100 Subject: [PATCH 1/4] Add more types to MatrixRoomHandler --- src/matrixroomhandler.ts | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts index 812066eb..e7546ed5 100644 --- a/src/matrixroomhandler.ts +++ b/src/matrixroomhandler.ts @@ -42,6 +42,18 @@ const JOIN_ROOM_SCHEDULE = [ 900000, // 15 minutes ]; +export interface ICreationOptions { + initial_state: { + content: { + join_rule: string, + }, + state_key: string, + type: string, + }[]; + room_alias_name: string; + visibility: string; +} + export class MatrixRoomHandler { private botUserId: string; constructor( @@ -61,12 +73,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) => { @@ -138,8 +151,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); @@ -252,7 +265,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, @@ -263,7 +276,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: [ { @@ -278,7 +291,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, From 0ed6f6811314a2fa4e6d26e2f4fb7146e5f4f0fb Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Tue, 26 Jan 2021 11:59:19 +0100 Subject: [PATCH 2/4] If createRoomOpts === undefined, tell the homeserver that the alias request failed --- src/discordas.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/discordas.ts b/src/discordas.ts index 951b4fb9..545d8263 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -191,10 +191,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) { From 45a1a0ff1949a3dbe8e99248c60f669075f0bc5b Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Tue, 26 Jan 2021 12:14:42 +0100 Subject: [PATCH 3/4] __roomId is a thing --- src/matrixroomhandler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts index e7546ed5..e82dbc9f 100644 --- a/src/matrixroomhandler.ts +++ b/src/matrixroomhandler.ts @@ -43,6 +43,7 @@ const JOIN_ROOM_SCHEDULE = [ ]; export interface ICreationOptions { + __roomId: string; initial_state: { content: { join_rule: string, From c04880861ebc20ea4295f78020612f0ad545f907 Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Tue, 9 Aug 2022 15:20:56 +0200 Subject: [PATCH 4/4] Add newsfile --- changelog.d/655.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/655.bugfix 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