mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-08-31 06:02:09 +00:00
Self-service removal of channel links
This commit is contained in:
parent
f33f7e5716
commit
9a8041ea38
@ -46,4 +46,20 @@ export class DimensionIrcService {
|
||||
LogService.info("DimensionIrcService", userId + " requested #" + channelNoHash + " on " + networkId + " to be linked to " + roomId);
|
||||
return {}; // 200 OK
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path(":networkId/channel/:channel/unlink/:roomId")
|
||||
public async unlink(@QueryParam("scalar_token") scalarToken: string, @PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string, @PathParam("roomId") roomId: string): Promise<any> {
|
||||
const userId = await ScalarService.getTokenOwner(scalarToken);
|
||||
|
||||
const parsed = IrcBridge.parseNetworkId(networkId);
|
||||
const bridge = await IrcBridgeRecord.findByPrimary(parsed.bridgeId);
|
||||
if (!bridge) throw new ApiError(404, "Bridge not found");
|
||||
|
||||
const client = new IrcBridge(userId);
|
||||
await client.removeLink(bridge, parsed.bridgeNetworkId, "#" + channelNoHash, roomId);
|
||||
|
||||
LogService.info("DimensionIrcService", userId + " unlinked #" + channelNoHash + " on " + networkId + " from " + roomId);
|
||||
return {}; // 200 OK
|
||||
}
|
||||
}
|
@ -127,6 +127,25 @@ export class IrcBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public async removeLink(bridge: IrcBridgeRecord, networkId: string, channel: string, inRoomId: string): Promise<any> {
|
||||
const network = (await this.getAllNetworks()).find(n => n.isEnabled && n.ircBridgeId === bridge.id && n.bridgeNetworkId === networkId);
|
||||
if (!network) throw new Error("Network not found");
|
||||
|
||||
const requestBody = {
|
||||
remote_room_server: network.domain,
|
||||
remote_room_channel: channel,
|
||||
matrix_room_id: inRoomId,
|
||||
user_id: this.requestingUserId,
|
||||
};
|
||||
|
||||
if (bridge.upstreamId) {
|
||||
delete requestBody["user_id"];
|
||||
await this.doUpstreamRequest(bridge, "POST", "/bridges/irc/_matrix/provision/unlink", null, requestBody);
|
||||
} else {
|
||||
await this.doProvisionRequest(bridge, "POST", "/_matrix/provision/unlink", null, requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
private async getAllNetworks(): Promise<CachedNetwork[]> {
|
||||
const cached = Cache.for(CACHE_IRC_BRIDGE).get("networks");
|
||||
if (cached) return cached;
|
||||
|
@ -1,5 +1,4 @@
|
||||
Release checklist:
|
||||
* IRC Bridge
|
||||
* Update documentation
|
||||
* Configuration migration (if possible)
|
||||
* Final testing (widgets, bots, etc)
|
||||
|
@ -127,7 +127,16 @@ export class IrcBridgeConfigComponent extends BridgeComponent<IrcConfig> {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public removeChannel(channel: any) {
|
||||
console.log(channel);
|
||||
public removeChannel(channel: LocalChannel) {
|
||||
this.isUpdating = true;
|
||||
this.irc.removeLink(this.roomId, channel.networkId, channel.name.substring(1)).then(() => {
|
||||
this.isUpdating = false;
|
||||
const idx = this.bridge.config.links[channel.networkId].findIndex(c => c.channelName === channel.name);
|
||||
if (idx !== -1) this.bridge.config.links[channel.networkId].splice(idx, 1);
|
||||
this.toaster.pop("success", "Link removed");
|
||||
}).catch(err => {
|
||||
console.error(err);
|
||||
this.toaster.pop("error", "Failed to remove link");
|
||||
});
|
||||
}
|
||||
}
|
@ -15,4 +15,8 @@ export class IrcApiService extends AuthedApi {
|
||||
public requestLink(roomId: string, networkId: string, channelNoHash: string, op: string): Promise<any> {
|
||||
return this.authedPost("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/link/" + roomId, {op: op}).map(r => r.json()).toPromise();
|
||||
}
|
||||
|
||||
public removeLink(roomId: string, networkId: string, channelNoHash: string): Promise<any> {
|
||||
return this.authedPost("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/unlink/" + roomId).map(r => r.json()).toPromise();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user