Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Add option on Channel Settings: Hide Notifications and Hide Unread Room Status (#2707, #2143) #5373

Merged
merged 14 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add setting to mute room notifications
  • Loading branch information
marceloschmidt committed Dec 29, 2016
commit 28c3c4cc9318b650123e2fd13c41ddd50eb417c8
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@
"every_30_minutes": "Once every 30 minutes",
"every_hour": "Once every hour",
"every_six_hours": "Once every six hours",
"Everything": "Everything",
"Example_s": "Example: <code class=\"inline\">%s</code>",
"Exclude_Botnames": "Exclude bots",
"Exclude_Botnames_Description": "Do not propagate messages from bots whose name matches the regular expression above. If left empty, all messages from bots will be propagated.",
Expand Down Expand Up @@ -941,6 +942,7 @@
"Nothing_found": "Nothing found",
"Notification_Duration": "Notification Duration",
"Notifications": "Notifications",
"Notifications_Muted_Description": "If you choose to mute everything, you won't see the room highlight in the list when there are new messages. Muting notifications will override notifications settings.",
"Notify_all_in_this_room": "Notify all in this room",
"Notify_active_in_this_room": "Notify active users in this room",
"Num_Agents": "# Agents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ <h2>{{_ "Notifications"}}</h2>
</div>
<form>
<ul class="list clearfix">
<li>
<label>{{_ "Mute"}}</label>
<div>
{{#if editing 'mute'}}
<label><input type="radio" name="mute" value="everything" checked="{{$eq mute 'everything'}}" /> {{_ "Everything"}}</label>
<label><input type="radio" name="mute" value="notifications" checked="{{$eq mute 'notifications'}}" /> {{_ "Notifications"}}</label>
<label><input type="radio" name="mute" value="nothing" checked="{{$eq mute 'nothing'}}" /> {{_ "Nothing"}}</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
<div class="alert">
{{_ "Notifications_Muted_Description"}}
</div>
{{else}}
<span class="current-setting">{{subValue 'mute'}} <i class="icon-pencil" data-edit="mute"></i></span>
{{/if}}
</div>
</li>
<li>
<label>{{_ "Desktop"}}</label>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ Template.pushNotificationsFlexTab.helpers({
}, {
fields: {
t: 1,
mute: 1,
[field]: 1
}
});
if (sub) {
if (sub.mute && sub.mute !== 'nothing' && field !== 'mute') {
return t('Muted');
}
switch (sub[field]) {
case 'all':
return t('All_messages');
Expand All @@ -89,9 +93,15 @@ Template.pushNotificationsFlexTab.helpers({
return t('Use_account_preference');
case 'mentions':
return t('Mentions');
case 'everything':
return t('Everything');
case 'notifications':
return t('Notifications');
default:
if (field === 'emailNotifications') {
return t('Use_account_preference');
} else if (field === 'mute') {
return t('Nothing');
} else {
return t('Mentions');
}
Expand All @@ -117,6 +127,16 @@ Template.pushNotificationsFlexTab.helpers({
},
emailVerified() {
return Meteor.user().emails && Meteor.user().emails[0] && Meteor.user().emails[0].verified;
},
mute() {
var sub = ChatSubscription.findOne({
rid: Session.get('openedRoom')
}, {
fields: {
mute: 1
}
});
return sub ? sub.mute || 'nothing' : 'nothing';
}
});

Expand All @@ -125,7 +145,7 @@ Template.pushNotificationsFlexTab.onCreated(function() {

this.validateSetting = (field) => {
const value = this.$('input[name='+ field +']:checked').val();
if (['all', 'mentions', 'nothing', 'default'].indexOf(value) === -1) {
if (['all', 'mentions', 'nothing', 'default', 'everything', 'notifications'].indexOf(value) === -1) {
toastr.error(t('Invalid_notification_setting_s', value || ''));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Meteor.methods({
check(field, String);
check(value, String);

if (['desktopNotifications', 'mobilePushNotifications', 'emailNotifications', 'unreadAlert'].indexOf(field) === -1) {
if (['desktopNotifications', 'mobilePushNotifications', 'emailNotifications', 'unreadAlert', 'mute'].indexOf(field) === -1) {
throw new Meteor.Error('error-invalid-settings', 'Invalid settings field', { method: 'saveNotificationSettings' });
}

if (['all', 'mentions', 'nothing', 'default'].indexOf(value) === -1) {
if (['all', 'mentions', 'nothing', 'default', 'everything', 'notifications'].indexOf(value) === -1) {
throw new Meteor.Error('error-invalid-settings', 'Invalid settings value', { method: 'saveNotificationSettings' });
}

Expand All @@ -34,6 +34,9 @@ Meteor.methods({
case 'unreadAlert':
RocketChat.models.Subscriptions.updateUnreadAlertById(subscription._id, value);
break;
case 'mute':
RocketChat.models.Subscriptions.updateMuteById(subscription._id, value);
break;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ RocketChat.models.Subscriptions.updateUnreadAlertById = function(_id, unreadAler
return this.update(query, update);
};

RocketChat.models.Subscriptions.updateMuteById = function(_id, mute) {
const query = {
_id: _id
};

const update = {
$set: {
mute
}
};

return this.update(query, update);
};

RocketChat.models.Subscriptions.findAlwaysNotifyDesktopUsersByRoomId = function(roomId) {
const query = {
rid: roomId,
Expand Down
1 change: 1 addition & 0 deletions server/publications/subscription.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fields =
_updatedAt: 1
blocked: 1
blocker: 1
mute: 1


Meteor.methods
Expand Down