diff --git a/src/definition/accessors/IRoomUpdater.ts b/src/definition/accessors/IRoomUpdater.ts new file mode 100644 index 000000000..630a369db --- /dev/null +++ b/src/definition/accessors/IRoomUpdater.ts @@ -0,0 +1,8 @@ +import { IRoom } from '../rooms'; +import { IUser } from '../users'; + +export interface IRoomUpdater { + muteUser(room: IRoom, executorId: IUser, user: IUser): Promise; + + unmuteUser(room: IRoom, executorId: IUser, user: IUser): Promise; +} diff --git a/src/server/accessors/RoomUpdater.ts b/src/server/accessors/RoomUpdater.ts new file mode 100644 index 000000000..ed1193c95 --- /dev/null +++ b/src/server/accessors/RoomUpdater.ts @@ -0,0 +1,17 @@ +import { IRoomUpdater } from '../../definition/accessors/IRoomUpdater'; +import { IRoom } from '../../definition/rooms'; +import { IUser } from '../../definition/users'; +import { AppBridges } from '../bridges'; + +export class RoomUpdater implements IRoomUpdater { + constructor(private readonly bridges: AppBridges, private readonly appId: string) { + } + + public async muteUser(room: IRoom, executor: IUser, user: IUser) { + return this.bridges.getRoomBridge().doMuteUser(room.id, executor.id, user.id, this.appId); + } + + public async unmuteUser(room: IRoom, executor: IUser, user: IUser) { + return this.bridges.getRoomBridge().doUnmuteUser(room.id, executor.id, user.id, this.appId); + } +} diff --git a/src/server/bridges/RoomBridge.ts b/src/server/bridges/RoomBridge.ts index 1a97ff017..9501b5839 100644 --- a/src/server/bridges/RoomBridge.ts +++ b/src/server/bridges/RoomBridge.ts @@ -49,6 +49,19 @@ export abstract class RoomBridge extends BaseBridge { } } + // TODO: check if we can use a list of user ids + public async doMuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise { + if (this.hasWritePermission(appId)) { + return this.doUnmuteUser(roomId, executorId, userId, appId); + } + } + + public async doUnmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise { + if (this.hasWritePermission(appId)) { + return this.doMuteUser(roomId, executorId, userId, appId); + } + } + public async doUpdate(room: IRoom, members: Array, appId: string): Promise { if (this.hasWritePermission(appId)) { return this.update(room, members, appId); @@ -92,13 +105,21 @@ export abstract class RoomBridge extends BaseBridge { } protected abstract create(room: IRoom, members: Array, appId: string): Promise; + protected abstract getById(roomId: string, appId: string): Promise; + protected abstract getByName(roomName: string, appId: string): Promise; + protected abstract getCreatorById(roomId: string, appId: string): Promise; + protected abstract getCreatorByName(roomName: string, appId: string): Promise; + protected abstract getDirectByUsernames(usernames: Array, appId: string): Promise; + protected abstract getMembers(roomId: string, appId: string): Promise>; + protected abstract update(room: IRoom, members: Array, appId: string): Promise; + protected abstract createDiscussion( room: IRoom, parentMessage: IMessage | undefined, @@ -106,11 +127,19 @@ export abstract class RoomBridge extends BaseBridge { members: Array, appId: string, ): Promise; + protected abstract delete(room: string, appId: string): Promise; + protected abstract getModerators(roomId: string, appId: string): Promise>; + protected abstract getOwners(roomId: string, appId: string): Promise>; + protected abstract getLeaders(roomId: string, appId: string): Promise>; + protected abstract muteUser(roomId: string, executorId: string, userId: string, appId: string): Promise; + + protected abstract unmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise; + private hasWritePermission(appId: string): boolean { if (AppPermissionManager.hasPermission(appId, AppPermissions.room.write)) { return true; diff --git a/tests/test-data/bridges/roomBridge.ts b/tests/test-data/bridges/roomBridge.ts index 1159e2456..8e3a20502 100644 --- a/tests/test-data/bridges/roomBridge.ts +++ b/tests/test-data/bridges/roomBridge.ts @@ -55,4 +55,12 @@ export class TestsRoomBridge extends RoomBridge { public getOwners(roomId: string, appId: string): Promise> { throw new Error('Method not implemented.'); } + + public muteUser(roomId: string, executorId: string, userId: string, appId: string): Promise { + throw new Error('Method not implemented'); + } + + public unmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise { + throw new Error('Method not implemented'); + } }