Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell the homeserver if a room alias request failed #655

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/655.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tell the homeserver if a room alias request failed.
8 changes: 6 additions & 2 deletions src/discordas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ async function run(): Promise<void> {
});

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<void>) => {
appservice.on("query.room", async (roomAlias: string, createRoom: (opts: unknown) => Promise<void>) => {
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) {
Expand Down
36 changes: 25 additions & 11 deletions src/matrixroomhandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in src/matrixroomhandler.ts

View workflow job for this annotation

GitHub Actions / test (18)

Property '__roomId' is missing in type '{ initial_state: { content: { join_rule: string; }; state_key: string; type: string; }[]; room_alias_name: string; visibility: string; }' but required in type 'ICreationOptions'.

Check failure on line 1 in src/matrixroomhandler.ts

View workflow job for this annotation

GitHub Actions / lint

Property '__roomId' is missing in type '{ initial_state: { content: { join_rule: string; }; state_key: string; type: string; }[]; room_alias_name: string; visibility: string; }' but required in type 'ICreationOptions'.

Check failure on line 1 in src/matrixroomhandler.ts

View workflow job for this annotation

GitHub Actions / test (20)

Property '__roomId' is missing in type '{ initial_state: { content: { join_rule: string; }; state_key: string; type: string; }[]; room_alias_name: string; visibility: string; }' but required in type 'ICreationOptions'.
Copyright 2018, 2019 matrix-appservice-discord

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -37,6 +37,19 @@
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(
Expand All @@ -56,12 +69,13 @@
}
);

// 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) => {
Expand Down Expand Up @@ -133,8 +147,8 @@
await Promise.all(promiseList);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async OnAliasQuery(alias: string): Promise<any> {

public async OnAliasQuery(alias: string): Promise<ICreationOptions | undefined> {
const aliasLocalpart = alias.substring("#".length, alias.indexOf(":"));
log.info("Got request for #", aliasLocalpart);
const srvChanPair = aliasLocalpart.substring("_discord_".length).split("_", ROOM_NAME_PARTS);
Expand Down Expand Up @@ -247,7 +261,7 @@
channel: Discord.TextChannel,
alias: string,
aliasLocalpart: string
) {
): Promise<ICreationOptions> {
const remote = new RemoteStoreRoom(`discord_${channel.guild.id}_${channel.id}`, {
/* eslint-disable @typescript-eslint/naming-convention */
discord_channel: channel.id,
Expand All @@ -258,7 +272,7 @@
update_topic: 1,
/* eslint-enable @typescript-eslint/naming-convention */
});
const creationOpts = {
const creationOpts: ICreationOptions = {
/* eslint-disable @typescript-eslint/naming-convention */
initial_state: [
{
Expand All @@ -273,7 +287,7 @@
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,
Expand Down
Loading