Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
New: capability of muting or unmuting a user in a room
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutdeb committed Nov 15, 2022
1 parent 0f02a27 commit 62f1db9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/definition/accessors/IRoomUpdater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IRoom } from '../rooms';
import { IUser } from '../users';

export interface IRoomUpdater {
muteUser(room: IRoom, executorId: IUser, user: IUser): Promise<void>;

unmuteUser(room: IRoom, executorId: IUser, user: IUser): Promise<void>;
}
17 changes: 17 additions & 0 deletions src/server/accessors/RoomUpdater.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
29 changes: 29 additions & 0 deletions src/server/bridges/RoomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (this.hasWritePermission(appId)) {
return this.doUnmuteUser(roomId, executorId, userId, appId);
}
}

public async doUnmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
if (this.hasWritePermission(appId)) {
return this.doMuteUser(roomId, executorId, userId, appId);
}
}

public async doUpdate(room: IRoom, members: Array<string>, appId: string): Promise<void> {
if (this.hasWritePermission(appId)) {
return this.update(room, members, appId);
Expand Down Expand Up @@ -92,25 +105,41 @@ export abstract class RoomBridge extends BaseBridge {
}

protected abstract create(room: IRoom, members: Array<string>, appId: string): Promise<string>;

protected abstract getById(roomId: string, appId: string): Promise<IRoom>;

protected abstract getByName(roomName: string, appId: string): Promise<IRoom>;

protected abstract getCreatorById(roomId: string, appId: string): Promise<IUser | undefined>;

protected abstract getCreatorByName(roomName: string, appId: string): Promise<IUser | undefined>;

protected abstract getDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined>;

protected abstract getMembers(roomId: string, appId: string): Promise<Array<IUser>>;

protected abstract update(room: IRoom, members: Array<string>, appId: string): Promise<void>;

protected abstract createDiscussion(
room: IRoom,
parentMessage: IMessage | undefined,
reply: string | undefined,
members: Array<string>,
appId: string,
): Promise<string>;

protected abstract delete(room: string, appId: string): Promise<void>;

protected abstract getModerators(roomId: string, appId: string): Promise<Array<IUser>>;

protected abstract getOwners(roomId: string, appId: string): Promise<Array<IUser>>;

protected abstract getLeaders(roomId: string, appId: string): Promise<Array<IUser>>;

protected abstract muteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void>;

protected abstract unmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void>;

private hasWritePermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.room.write)) {
return true;
Expand Down
8 changes: 8 additions & 0 deletions tests/test-data/bridges/roomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ export class TestsRoomBridge extends RoomBridge {
public getOwners(roomId: string, appId: string): Promise<Array<IUser>> {
throw new Error('Method not implemented.');
}

public muteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
throw new Error('Method not implemented');
}

public unmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
throw new Error('Method not implemented');
}
}

0 comments on commit 62f1db9

Please sign in to comment.