Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 62f1db9

Browse files
committed
New: capability of muting or unmuting a user in a room
1 parent 0f02a27 commit 62f1db9

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { IRoom } from '../rooms';
2+
import { IUser } from '../users';
3+
4+
export interface IRoomUpdater {
5+
muteUser(room: IRoom, executorId: IUser, user: IUser): Promise<void>;
6+
7+
unmuteUser(room: IRoom, executorId: IUser, user: IUser): Promise<void>;
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { IRoomUpdater } from '../../definition/accessors/IRoomUpdater';
2+
import { IRoom } from '../../definition/rooms';
3+
import { IUser } from '../../definition/users';
4+
import { AppBridges } from '../bridges';
5+
6+
export class RoomUpdater implements IRoomUpdater {
7+
constructor(private readonly bridges: AppBridges, private readonly appId: string) {
8+
}
9+
10+
public async muteUser(room: IRoom, executor: IUser, user: IUser) {
11+
return this.bridges.getRoomBridge().doMuteUser(room.id, executor.id, user.id, this.appId);
12+
}
13+
14+
public async unmuteUser(room: IRoom, executor: IUser, user: IUser) {
15+
return this.bridges.getRoomBridge().doUnmuteUser(room.id, executor.id, user.id, this.appId);
16+
}
17+
}

src/server/bridges/RoomBridge.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ export abstract class RoomBridge extends BaseBridge {
4949
}
5050
}
5151

52+
// TODO: check if we can use a list of user ids
53+
public async doMuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
54+
if (this.hasWritePermission(appId)) {
55+
return this.doUnmuteUser(roomId, executorId, userId, appId);
56+
}
57+
}
58+
59+
public async doUnmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
60+
if (this.hasWritePermission(appId)) {
61+
return this.doMuteUser(roomId, executorId, userId, appId);
62+
}
63+
}
64+
5265
public async doUpdate(room: IRoom, members: Array<string>, appId: string): Promise<void> {
5366
if (this.hasWritePermission(appId)) {
5467
return this.update(room, members, appId);
@@ -92,25 +105,41 @@ export abstract class RoomBridge extends BaseBridge {
92105
}
93106

94107
protected abstract create(room: IRoom, members: Array<string>, appId: string): Promise<string>;
108+
95109
protected abstract getById(roomId: string, appId: string): Promise<IRoom>;
110+
96111
protected abstract getByName(roomName: string, appId: string): Promise<IRoom>;
112+
97113
protected abstract getCreatorById(roomId: string, appId: string): Promise<IUser | undefined>;
114+
98115
protected abstract getCreatorByName(roomName: string, appId: string): Promise<IUser | undefined>;
116+
99117
protected abstract getDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined>;
118+
100119
protected abstract getMembers(roomId: string, appId: string): Promise<Array<IUser>>;
120+
101121
protected abstract update(room: IRoom, members: Array<string>, appId: string): Promise<void>;
122+
102123
protected abstract createDiscussion(
103124
room: IRoom,
104125
parentMessage: IMessage | undefined,
105126
reply: string | undefined,
106127
members: Array<string>,
107128
appId: string,
108129
): Promise<string>;
130+
109131
protected abstract delete(room: string, appId: string): Promise<void>;
132+
110133
protected abstract getModerators(roomId: string, appId: string): Promise<Array<IUser>>;
134+
111135
protected abstract getOwners(roomId: string, appId: string): Promise<Array<IUser>>;
136+
112137
protected abstract getLeaders(roomId: string, appId: string): Promise<Array<IUser>>;
113138

139+
protected abstract muteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void>;
140+
141+
protected abstract unmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void>;
142+
114143
private hasWritePermission(appId: string): boolean {
115144
if (AppPermissionManager.hasPermission(appId, AppPermissions.room.write)) {
116145
return true;

tests/test-data/bridges/roomBridge.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@ export class TestsRoomBridge extends RoomBridge {
5555
public getOwners(roomId: string, appId: string): Promise<Array<IUser>> {
5656
throw new Error('Method not implemented.');
5757
}
58+
59+
public muteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
60+
throw new Error('Method not implemented');
61+
}
62+
63+
public unmuteUser(roomId: string, executorId: string, userId: string, appId: string): Promise<void> {
64+
throw new Error('Method not implemented');
65+
}
5866
}

0 commit comments

Comments
 (0)