Skip to content
Snippets Groups Projects
Commit 3161216f authored by Alex Brazier's avatar Alex Brazier
Browse files

Add setting to disable system notifications

parent 072e4725
No related branches found
No related tags found
No related merge requests found
Showing
with 62 additions and 19 deletions
......@@ -35,6 +35,8 @@ Template.channelSettings.helpers
return t('Room_archivation_state_false')
readOnly: ->
return ChatRoom.findOne(@rid, { fields: { ro: 1 }})?.ro
systemMessages: ->
return ChatRoom.findOne(@rid, { fields: { sysMes: 1 }})?.sysMes isnt false
Template.channelSettings.events
'keydown input[type=text]': (e, t) ->
......@@ -133,6 +135,10 @@ Template.channelSettings.onCreated ->
RocketChat.callbacks.run 'unarchiveRoom', ChatRoom.findOne(room._id)
when 'readOnly'
Meteor.call 'saveRoomSettings', room._id, 'readOnly', @$('input[name=readOnly]:checked').val() is 'true', (err, result) ->
return handleError err if err
toastr.success TAPi18n.__ 'Read_only_changed_successfully'
return handleError err if err
toastr.success TAPi18n.__ 'Read_only_changed_successfully'
when 'systemMessages'
Meteor.call 'saveRoomSettings', room._id, 'systemMessages', @$('input[name=systemMessages]:checked').val() is 'true', (err, result) ->
return handleError err if err
toastr.success TAPi18n.__ 'System_messages_setting_changed_successfully'
@editing.set()
......@@ -78,6 +78,19 @@
{{/if}}
</div>
</li>
<li>
<label>{{_ "System_messages"}}</label>
<div>
{{#if editing 'systemMessages'}}
<label><input type="radio" name="systemMessages" class="editing" value="true" checked="{{$eq systemMessages true}}" /> {{_ "On"}}</label>
<label><input type="radio" name="systemMessages" value="false" checked="{{$neq systemMessages true}}" /> {{_ "Off"}}</label>
<button type="button" class="button secondary cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span>{{#if systemMessages}}{{_ "On"}}{{else}}{{_ "Off"}}{{/if}}{{#if canEdit}} <i class="icon-pencil" data-edit="systemMessages"></i>{{/if}}</span>
{{/if}}
</div>
</li>
{{/if}}
{{#each channelSettings}}
{{> Template.dynamic template=template data=data}}
......
......@@ -33,6 +33,7 @@ Package.onUse(function(api) {
'server/functions/saveRoomName.coffee',
'server/functions/saveRoomReadOnly.coffee',
'server/functions/saveRoomDescription.coffee',
'server/functions/saveRoomSystemMessages.coffee',
'server/methods/saveRoomSettings.coffee',
'server/models/Messages.coffee',
'server/models/Rooms.coffee'
......
RocketChat.saveRoomSystemMessages = (rid, systemMessages, user) ->
unless Match.test rid, String
throw new Meteor.Error 'invalid-room', 'Invalid room', { function: 'RocketChat.saveRoomSystemMessages' }
update = RocketChat.models.Rooms.setSystemMessagesById rid, systemMessages
return update
......@@ -3,7 +3,7 @@ Meteor.methods
unless Match.test rid, String
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'saveRoomSettings' }
if setting not in ['roomName', 'roomTopic', 'roomDescription', 'roomType', 'readOnly', 'default']
if setting not in ['roomName', 'roomTopic', 'roomDescription', 'roomType', 'readOnly', 'systemMessages', 'default']
throw new Meteor.Error 'error-invalid-settings', 'Invalid settings provided', { method: 'saveRoomSettings' }
unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid)
......@@ -35,6 +35,9 @@ Meteor.methods
when 'readOnly'
if value isnt room.ro
RocketChat.saveRoomReadOnly rid, value, Meteor.user()
when 'systemMessages'
if value isnt room.sysMes
RocketChat.saveRoomSystemMessages rid, value, Meteor.user()
when 'default'
RocketChat.models.Rooms.saveDefaultById rid, value
......
......@@ -14,13 +14,21 @@ RocketChat.models.Rooms.setReadOnlyById = (_id, readOnly) ->
update =
$set:
ro: readOnly is true
ro: readOnly
if readOnly is true
if readOnly
users = @findOne(query, { fields: { usernames: 1 }})?.usernames
if users
update.$set.muted = users
else
update.$set.muted = []
return @update query, update
RocketChat.models.Rooms.setSystemMessagesById = (_id, systemMessages) ->
query =
_id: _id
update =
$set:
sysMes: systemMessages
return @update query, update
......@@ -268,6 +268,9 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base
# INSERT
createWithTypeRoomIdMessageAndUser: (type, roomId, message, user, extraData) ->
room = RocketChat.models.Rooms.findOneById roomId, { fields: { sysMes: 1 }}
if room?.sysMes is false
return
record =
t: type
rid: roomId
......
......@@ -28,7 +28,7 @@ Meteor.methods
newUser = RocketChat.models.Users.findOneByUsername data.username
if room.ro and not RocketChat.authz.hasPermission(Meteor.userId(), 'post-read-only')
if room.ro and not RocketChat.authz.hasPermission(newUser._id, 'post-read-only')
RocketChat.models.Rooms.addUsernameByIdAndMute data.rid, data.username
else
RocketChat.models.Rooms.addUsernameById data.rid, data.username
......@@ -41,12 +41,11 @@ Meteor.methods
alert: true
unread: 1
if not room.ro
fromUser = RocketChat.models.Users.findOneById fromId
RocketChat.models.Messages.createUserAddedWithRoomIdAndUser data.rid, newUser,
ts: now
u:
_id: fromUser._id
username: fromUser.username
fromUser = RocketChat.models.Users.findOneById fromId
RocketChat.models.Messages.createUserAddedWithRoomIdAndUser data.rid, newUser,
ts: now
u:
_id: fromUser._id
username: fromUser.username
return true
......@@ -33,6 +33,7 @@ Meteor.methods
name: name
ts: now
ro: readOnly is true
sysMes: readOnly isnt true
usernames: members
u:
_id: user._id
......@@ -42,6 +43,7 @@ Meteor.methods
room = RocketChat.models.Rooms.createWithTypeNameUserAndUsernames 'c', name, user, members,
ts: now
ro: readOnly is true
sysMes: readOnly isnt true
for username in members
member = RocketChat.models.Users.findOneByUsername username
......
......@@ -33,6 +33,7 @@ Meteor.methods
room = RocketChat.models.Rooms.createWithTypeNameUserAndUsernames 'p', name, me, members,
ts: now
ro: readOnly is true
sysMes: readOnly isnt true
for username in members
member = RocketChat.models.Users.findOneByUsername(username, { fields: { username: 1 }})
......
......@@ -34,10 +34,8 @@ Meteor.methods
alert: true
unread: 1
# Don't post message in read only rooms
if not room.ro
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser rid, user,
ts: now
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser rid, user,
ts: now
Meteor.defer ->
RocketChat.callbacks.run 'afterJoinRoom', user, room
......
......@@ -13,6 +13,7 @@ Meteor.startup ->
ro: 1
jitsiTimeout: 1
description: 1
sysMes: 1
if RocketChat.authz.hasPermission(this.userId, 'view-c-room')
return RocketChat.models.Rooms.findByTypeAndName 'c', identifier, options
......@@ -36,6 +37,7 @@ Meteor.startup ->
ro: 1
jitsiTimeout: 1
description: 1
sysMes: 1
user = RocketChat.models.Users.findOneById this.userId, fields: username: 1
return RocketChat.models.Rooms.findByTypeAndNameContainingUsername 'p', identifier, user.username, options
......
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