Skip to content

Commit

Permalink
fix: Unmuting users on average rooms allows them to speak if room is …
Browse files Browse the repository at this point in the history
…later set as read-only (#30050)

Co-authored-by: Matheus Barbosa Silva <36537004+matheusbsilva137@users.noreply.github.com>
  • Loading branch information
heitortanoue and matheusbsilva137 committed Aug 31, 2023
1 parent dcfb771 commit 8a59855
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-cats-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/model-typings": patch
---

When setting a room as read-only, do not allow previously unmuted users to send messages.
4 changes: 2 additions & 2 deletions apps/meteor/app/federation/server/endpoints/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ const eventHandlers = {
// Denormalize user
const denormalizedUser = normalizers.denormalizeUser(user);

// Mute user
await Rooms.unmuteUsernameByRoomId(roomId, denormalizedUser.username);
// Unmute user
await Rooms.unmuteMutedUsernameByRoomId(roomId, denormalizedUser.username);
}

return eventResult;
Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/server/methods/muteUserInRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export const muteUserInRoom = async (fromId: string, data: { rid: IRoom['_id'];

await callbacks.run('beforeMuteUser', { mutedUser, fromUser }, room);

await Rooms.muteUsernameByRoomId(data.rid, mutedUser.username);
if (room.ro) {
await Rooms.muteReadOnlyUsernameByRoomId(data.rid, mutedUser.username);
} else {
await Rooms.muteUsernameByRoomId(data.rid, mutedUser.username);
}

await Message.saveSystemMessage('user-muted', data.rid, mutedUser.username, fromUser);

Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/server/methods/unmuteUserInRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export const unmuteUserInRoom = async (fromId: string, data: { rid: IRoom['_id']

await callbacks.run('beforeUnmuteUser', { unmutedUser, fromUser }, room);

await Rooms.unmuteUsernameByRoomId(data.rid, unmutedUser.username);
if (room.ro) {
await Rooms.unmuteReadOnlyUsernameByRoomId(data.rid, unmutedUser.username);
} else {
await Rooms.unmuteMutedUsernameByRoomId(data.rid, unmutedUser.username);
}

await Message.saveSystemMessage('user-unmuted', data.rid, unmutedUser.username, fromUser);

Expand Down
26 changes: 25 additions & 1 deletion apps/meteor/server/models/raw/Rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1708,9 +1708,33 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
return this.updateOne(query, update);
}

unmuteUsernameByRoomId(_id: IRoom['_id'], username: IUser['username']): Promise<UpdateResult> {
muteReadOnlyUsernameByRoomId(_id: IRoom['_id'], username: IUser['username']): Promise<UpdateResult> {
const query: Filter<IRoom> = { _id, ro: true };

const update: UpdateFilter<IRoom> = {
$pull: {
unmuted: username,
},
};

return this.updateOne(query, update);
}

unmuteMutedUsernameByRoomId(_id: IRoom['_id'], username: IUser['username']): Promise<UpdateResult> {
const query: Filter<IRoom> = { _id };

const update: UpdateFilter<IRoom> = {
$pull: {
muted: username,
},
};

return this.updateOne(query, update);
}

unmuteReadOnlyUsernameByRoomId(_id: string, username: string): Promise<UpdateResult> {
const query: Filter<IRoom> = { _id, ro: true };

const update: UpdateFilter<IRoom> = {
$pull: {
muted: username,
Expand Down
4 changes: 3 additions & 1 deletion packages/model-typings/src/models/IRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ export interface IRoomsModel extends IBaseModel<IRoom> {
): Promise<UpdateResult>;
setCustomFieldsById(rid: string, customFields: Record<string, any>): Promise<UpdateResult>;
muteUsernameByRoomId(rid: string, username: string): Promise<UpdateResult>;
unmuteUsernameByRoomId(rid: string, username: string): Promise<UpdateResult>;
muteReadOnlyUsernameByRoomId(rid: string, username: string): Promise<UpdateResult>;
unmuteMutedUsernameByRoomId(rid: string, username: string): Promise<UpdateResult>;
unmuteReadOnlyUsernameByRoomId(rid: string, username: string): Promise<UpdateResult>;
saveFeaturedById(rid: string, featured: boolean): Promise<UpdateResult>;
saveDefaultById(rid: string, defaultValue: boolean): Promise<UpdateResult>;
saveFavoriteById(rid: string, favorite: boolean, defaultValue: boolean): Promise<UpdateResult>;
Expand Down

0 comments on commit 8a59855

Please sign in to comment.