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 all commits
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
2 changes: 1 addition & 1 deletion client/startup/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Meteor.startup(function() {
let unreadCount = 0;
let unreadAlert = false;

const subscriptions = ChatSubscription.find({open: true}, { fields: { unread: 1, alert: 1, rid: 1, t: 1, name: 1, ls: 1, unreadAlert: 1 } });
const subscriptions = ChatSubscription.find({open: true, hideUnreadStatus: { $ne: true }}, { fields: { unread: 1, alert: 1, rid: 1, t: 1, name: 1, ls: 1, unreadAlert: 1 } });

let openedRoomId = undefined;
Tracker.nonreactive(function() {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
"Desktop_Notifications_Enabled": "Desktop Notifications are Enabled",
"Direct_message_someone": "Direct message someone",
"Direct_Messages": "Direct Messages",
"Disable_Notifications": "Disable Notifications",
"Disable_two-factor_authentication": "Disable two-factor authentication",
"Display_offline_form": "Display offline form",
"Displays_action_text": "Displays action text",
Expand Down Expand Up @@ -644,6 +645,7 @@
"Hide_room": "Hide room",
"Hide_Room_Warning": "Are you sure you want to hide the room \"%s\"?",
"Hide_roles": "Hide roles",
"Hide_Unread_Room_Status": "Hide Unread Room Status",
"Hide_usernames": "Hide usernames",
"Highlights": "Highlights",
"Highlights_How_To": "To be notified when someone mentions a word or phrase, add it here. You can separate words or phrases with commas. Highlight Words are not case sensitive.",
Expand Down Expand Up @@ -1082,6 +1084,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, except for mentions. 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 Expand Up @@ -1547,7 +1550,7 @@
"Unmute_user": "Unmute user",
"Unnamed": "Unnamed",
"Unpin_Message": "Unpin Message",
"Unread_Alert": "Unread Alert",
"Unread_Tray_Icon_Alert": "Unread Tray Icon Alert",
"Unread_Messages": "Unread Messages",
"Unread_Rooms": "Unread Rooms",
"Unread_Rooms_Mode": "Unread Rooms Mode",
Expand Down Expand Up @@ -1711,4 +1714,4 @@
"your_message_optional": "your message (optional)",
"Your_password_is_wrong": "Your password is wrong!",
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices"
}
}
30 changes: 17 additions & 13 deletions packages/rocketchat-lib/server/lib/sendEmailOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,24 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
messageHTML = messageHTML.replace(/\n/gm, '<br/>');

RocketChat.models.Subscriptions.findWithSendEmailByRoomId(room._id).forEach((sub) => {
switch (sub.emailNotifications) {
case 'all':
usersToSendEmail[sub.u._id] = 'force';
break;
case 'mentions':
if (usersToSendEmail[sub.u._id]) {
if (sub.disableNotifications) {
delete usersToSendEmail[sub.u._id];
} else {
switch (sub.emailNotifications) {
case 'all':
usersToSendEmail[sub.u._id] = 'force';
}
break;
case 'nothing':
delete usersToSendEmail[sub.u._id];
break;
case 'default':
break;
break;
case 'mentions':
if (usersToSendEmail[sub.u._id]) {
usersToSendEmail[sub.u._id] = 'force';
}
break;
case 'nothing':
delete usersToSendEmail[sub.u._id];
break;
case 'default':
break;
}
}
});

Expand Down
19 changes: 12 additions & 7 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {

const notificationPreferencesByRoom = RocketChat.models.Subscriptions.findNotificationPreferencesByRoom(room._id);
notificationPreferencesByRoom.forEach(function(subscription) {
if (subscription.desktopNotifications === 'all') {
settings.alwaysNotifyDesktopUsers.push(subscription.u._id);
} else if (subscription.desktopNotifications === 'nothing') {
if (subscription.disableNotifications) {
settings.dontNotifyDesktopUsers.push(subscription.u._id);
}
if (subscription.mobilePushNotifications === 'all') {
settings.alwaysNotifyMobileUsers.push(subscription.u._id);
} else if (subscription.mobilePushNotifications === 'nothing') {
settings.dontNotifyMobileUsers.push(subscription.u._id);
} else {
if (subscription.desktopNotifications === 'all') {
settings.alwaysNotifyDesktopUsers.push(subscription.u._id);
} else if (subscription.desktopNotifications === 'nothing') {
settings.dontNotifyDesktopUsers.push(subscription.u._id);
}
if (subscription.mobilePushNotifications === 'all') {
settings.alwaysNotifyMobileUsers.push(subscription.u._id);
} else if (subscription.mobilePushNotifications === 'nothing') {
settings.dontNotifyMobileUsers.push(subscription.u._id);
}
}
settings.desktopNotificationDurations[subscription.u._id] = subscription.desktopNotificationDuration;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,95 +7,111 @@ <h2>{{_ "Notifications"}}</h2>
<form>
<ul class="list clearfix">
<li>
<label>{{_ "Audio"}}</label>
<div>
{{#if editing 'audioNotification'}}
<label>
<select name="audioNotification" class="audio">
<option value="none" selected="{{$eq audioNotification 'none'}}">{{_ "None"}}</option>
<option value="" selected="{{$eq audioNotification ''}}">{{_ "Use_account_preference"}} ({{_ "Default"}})</option>
<option value="chime" selected="{{$eq audioNotification 'chime'}}">Chime</option>
{{#each audioAssets}}
<option value="{{_id}}" selected="{{$eq audioNotification _id}}">{{name}}</option>
{{/each}}
</select>
</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{audioValue}} <i class="icon-play-circled" data-play="{{audioNotification}}"></i> <i class="icon-pencil" data-edit="audioNotification"></i></span>
{{/if}}
<label>{{_ "Disable_Notifications"}}</label>
<div class="input checkbox toggle">
<input type="checkbox" id="disableNotifications" name="disableNotifications" value="1" checked="{{$eq disableNotifications true}}" />
<label for="disableNotifications"></label>
</div>
</li>
<li>
<label>{{_ "Desktop"}}</label>
<div>
{{#if editing 'desktopNotifications'}}
<label><input type="radio" name="desktopNotifications" value="all" checked="{{$eq desktopNotifications 'all'}}" /> {{_ "All_messages"}}</label>
<label><input type="radio" name="desktopNotifications" value="mentions" checked="{{$eq desktopNotifications 'mentions'}}" /> {{_ "Mentions_default"}}</label>
<label><input type="radio" name="desktopNotifications" value="nothing" checked="{{$eq desktopNotifications 'nothing'}}" /> {{_ "Nothing"}}</label>
<br />
{{#if desktopNotificationDuration}}
<label>{{_ "Duration"}} ({{_ "seconds"}}) <input type="number" name="duration" min="0" value="{{desktopNotificationDuration}}" class="content-background-color"></label>
{{#if $neq disableNotifications true}}
<li>
<label>{{_ "Audio"}}</label>
<div>
{{#if editing 'audioNotification'}}
<label>
<select name="audioNotification" class="audio">
<option value="none" selected="{{$eq audioNotification 'none'}}">{{_ "None"}}</option>
<option value="" selected="{{$eq audioNotification ''}}">{{_ "Use_account_preference"}} ({{_ "Default"}})</option>
<option value="chime" selected="{{$eq audioNotification 'chime'}}">Chime</option>
{{#each audioAssets}}
<option value="{{_id}}" selected="{{$eq audioNotification _id}}">{{name}}</option>
{{/each}}
</select>
</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<label>{{_ "Duration"}} ({{_ "seconds"}}) <input type="number" name="duration" min="0" value="" placeholder="{{_ "Use_User_Preferences_or_Global_Settings"}}" class="content-background-color"></label>
<span class="current-setting">{{audioValue}} <i class="icon-play-circled" data-play="{{audioNotification}}"></i> <i class="icon-pencil" data-edit="audioNotification"></i></span>
{{/if}}
</div>
</li>
<li>
<label>{{_ "Desktop"}}</label>
<div>
{{#if editing 'desktopNotifications'}}
<label><input type="radio" name="desktopNotifications" value="all" checked="{{$eq desktopNotifications 'all'}}" /> {{_ "All_messages"}}</label>
<label><input type="radio" name="desktopNotifications" value="mentions" checked="{{$eq desktopNotifications 'mentions'}}" /> {{_ "Mentions_default"}}</label>
<label><input type="radio" name="desktopNotifications" value="nothing" checked="{{$eq desktopNotifications 'nothing'}}" /> {{_ "Nothing"}}</label>
<br />
{{#if desktopNotificationDuration}}
<label>{{_ "Duration"}} ({{_ "seconds"}}) <input type="number" name="duration" min="0" value="{{desktopNotificationDuration}}"></label>
{{else}}
<label>{{_ "Duration"}} ({{_ "seconds"}}) <input type="number" name="duration" min="0" value="" placeholder="{{_ "Use_User_Preferences_or_Global_Settings"}}"></label>
{{/if}}

<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{subValue 'desktopNotifications'}} <i class="icon-pencil" data-edit="desktopNotifications"></i></span>
{{/if}}
</div>
</li>
{{#unless editing 'desktopNotifications'}}
<li>
<label>{{_ "Desktop_Notifications_Duration"}}</label>
<div>
<span class="current-setting">{{#if desktopNotificationDuration}}{{desktopNotificationDuration}} {{_"seconds"}}{{else}}{{_ "Use_User_Preferences_or_Global_Settings"}}{{/if}}</span>
</div>
</li>
{{/unless}}
<li>
<label>{{_ "Mobile"}}</label>
<div>
{{#if editing 'mobilePushNotifications'}}
<label><input type="radio" name="mobilePushNotifications" value="all" checked="{{$eq mobilePushNotifications 'all'}}" /> {{_ "All_messages"}}</label>
<label><input type="radio" name="mobilePushNotifications" value="mentions" checked="{{$eq mobilePushNotifications 'mentions'}}" /> {{_ "Mentions_default"}}</label>
<label><input type="radio" name="mobilePushNotifications" value="nothing" checked="{{$eq mobilePushNotifications 'nothing'}}" /> {{_ "Nothing"}}</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{subValue 'mobilePushNotifications'}} <i class="icon-pencil" data-edit="mobilePushNotifications"></i></span>
{{/if}}
</div>
</li>
<li>
<label>{{_ "Email"}}</label>
<div>
{{#if editing 'emailNotifications'}}
<label><input type="radio" name="emailNotifications" value="all" checked="{{$eq emailNotifications 'all'}}" /> {{_ "All_messages"}}</label>
{{#if showEmailMentions}}
<label><input type="radio" name="emailNotifications" value="mentions" checked="{{$eq emailNotifications 'mentions'}}" /> {{_ "Mentions"}}</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{subValue 'desktopNotifications'}} <i class="icon-pencil" data-edit="desktopNotifications"></i></span>
{{/if}}
<label><input type="radio" name="emailNotifications" value="nothing" checked="{{$eq emailNotifications 'nothing'}}" /> {{_ "Nothing"}}</label>
<label><input type="radio" name="emailNotifications" value="default" checked="{{$eq emailNotifications 'default'}}" /> {{_ "Use_account_preference"}}</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{subValue 'emailNotifications'}} <i class="icon-pencil" data-edit="emailNotifications"></i></span>
{{/if}}
</div>
</li>
{{#unless emailVerified}}
</div>
</li>
{{#unless editing 'desktopNotifications'}}
<li>
<label>{{_ "Desktop_Notifications_Duration"}}</label>
<div>
<span class="current-setting">{{#if desktopNotificationDuration}}{{desktopNotificationDuration}} {{_"seconds"}}{{else}}{{_ "Use_User_Preferences_or_Global_Settings"}}{{/if}}</span>
</div>
</li>
{{/unless}}
<li>
<label>{{_ "Mobile"}}</label>
<div>
{{#if editing 'mobilePushNotifications'}}
<label><input type="radio" name="mobilePushNotifications" value="all" checked="{{$eq mobilePushNotifications 'all'}}" /> {{_ "All_messages"}}</label>
<label><input type="radio" name="mobilePushNotifications" value="mentions" checked="{{$eq mobilePushNotifications 'mentions'}}" /> {{_ "Mentions_default"}}</label>
<label><input type="radio" name="mobilePushNotifications" value="nothing" checked="{{$eq mobilePushNotifications 'nothing'}}" /> {{_ "Nothing"}}</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{subValue 'mobilePushNotifications'}} <i class="icon-pencil" data-edit="mobilePushNotifications"></i></span>
{{/if}}
</div>
</li>
<li>
<label>{{_ "Email"}}</label>
<div>
{{#if editing 'emailNotifications'}}
<label><input type="radio" name="emailNotifications" value="all" checked="{{$eq emailNotifications 'all'}}" /> {{_ "All_messages"}}</label>
{{#if showEmailMentions}}
<label><input type="radio" name="emailNotifications" value="mentions" checked="{{$eq emailNotifications 'mentions'}}" /> {{_ "Mentions"}}</label>
{{/if}}
<label><input type="radio" name="emailNotifications" value="nothing" checked="{{$eq emailNotifications 'nothing'}}" /> {{_ "Nothing"}}</label>
<label><input type="radio" name="emailNotifications" value="default" checked="{{$eq emailNotifications 'default'}}" /> {{_ "Use_account_preference"}}</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{subValue 'emailNotifications'}} <i class="icon-pencil" data-edit="emailNotifications"></i></span>
{{/if}}
</div>
</li>
{{#unless emailVerified}}
<li>
<div class="alert alert-warning pending-background pending-border">
{{_ "You_wont_receive_email_notifications_because_you_have_not_verified_your_email"}}
</div>
</li>
{{/unless}}
{{/if}}
<li>
<div class="alert alert-warning pending-background pending-border">
{{_ "You_wont_receive_email_notifications_because_you_have_not_verified_your_email"}}
<label>{{_ "Hide_Unread_Room_Status"}}</label>
<div class="input checkbox toggle">
<input type="checkbox" id="hideUnreadStatus" name="hideUnreadStatus" value="1" checked="{{$eq hideUnreadStatus true}}" />
<label for="hideUnreadStatus"></label>
</div>
</li>
{{/unless}}
<li>
<label>{{_ "Unread_Alert"}}</label>
<label>{{_ "Unread_Tray_Icon_Alert"}}</label>
<div>
{{#if editing 'unreadAlert'}}
<label><input type="radio" name="unreadAlert" value="all" checked="{{$eq unreadAlert 'all'}}" /> {{_ "On"}}</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ Template.pushNotificationsFlexTab.helpers({
});
return sub ? sub.audioNotification || '' : '';
},
disableNotifications() {
const sub = ChatSubscription.findOne({
rid: Session.get('openedRoom')
}, {
fields: {
disableNotifications: 1
}
});
return sub ? sub.disableNotifications || false : false;
},
hideUnreadStatus() {
const sub = ChatSubscription.findOne({
rid: Session.get('openedRoom')
}, {
fields: {
hideUnreadStatus: 1
}
});
return sub ? sub.hideUnreadStatus || false : false;
},
desktopNotifications() {
const sub = ChatSubscription.findOne({
rid: Session.get('openedRoom')
Expand Down Expand Up @@ -160,6 +180,8 @@ Template.pushNotificationsFlexTab.onCreated(function() {
this.validateSetting = (field) => {
switch (field) {
case 'audioNotification':
case 'hideUnreadStatus':
case 'disableNotifications':
return true;
default:
const value = this.$(`input[name=${ field }]:checked`).val();
Expand All @@ -178,6 +200,10 @@ Template.pushNotificationsFlexTab.onCreated(function() {
case 'audioNotification':
value = this.$(`select[name=${ field }]`).val();
break;
case 'hideUnreadStatus':
case 'disableNotifications':
value = this.$(`input[name=${ field }]:checked`).val() ? '1' : '0';
break;
default:
value = this.$(`input[name=${ field }]:checked`).val();
break;
Expand Down Expand Up @@ -255,5 +281,11 @@ Template.pushNotificationsFlexTab.events({
$audio[0].play();
}
}
},

'change input[type=checkbox]'(e, instance) {
e.preventDefault();
instance.editing.set($(e.currentTarget).attr('name'));
instance.saveSetting();
}
});
Loading