Skip to content
Snippets Groups Projects
Commit f852091a authored by Gary Chapman's avatar Gary Chapman
Browse files

- Refactored to remove unnecessary addUsernameByIdAndMute method

- Completed setReadOnlyById to set/unset muted user array
parent 5b680c5e
Loading
...@@ -16,10 +16,21 @@ RocketChat.models.Rooms.setReadOnlyById = (_id, readOnly) -> ...@@ -16,10 +16,21 @@ RocketChat.models.Rooms.setReadOnlyById = (_id, readOnly) ->
$set: $set:
ro: readOnly ro: readOnly
update.$set.muted = []
if readOnly if readOnly
users = @findOne(query, { fields: { usernames: 1 }})?.usernames # we want to mute all users without the post-read-only permission
else
update.$set.muted = [] # get all usernames for this room
users = @findOne(query, { fields: { usernames: 1 }})
users.usernames.forEach (userName) ->
# lookup the user
user = RocketChat.models.Users.findOneByUsername userName
if user != null and RocketChat.authz.hasPermission(user._id, 'post-read-only') is false
update.$set.muted.push userName
return @update query, update return @update query, update
......
...@@ -23,10 +23,10 @@ Meteor.methods ...@@ -23,10 +23,10 @@ Meteor.methods
RocketChat.callbacks.run 'beforeJoinRoom', user, room RocketChat.callbacks.run 'beforeJoinRoom', user, room
# Automatically mute users in read only rooms # Automatically mute users in read only rooms
if room.ro and not RocketChat.authz.hasPermission(Meteor.userId(), 'post-read-only')
RocketChat.models.Rooms.addUsernameByIdAndMute rid, user.username muted = room.ro and not RocketChat.authz.hasPermission(Meteor.userId(), 'post-read-only')
else
RocketChat.models.Rooms.addUsernameById rid, user.username RocketChat.models.Rooms.addUsernameById rid, user.username, muted
RocketChat.models.Subscriptions.createWithRoomAndUser room, user, RocketChat.models.Subscriptions.createWithRoomAndUser room, user,
ts: now ts: now
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment