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

Provides "Do Not Disturb" and "Snooze Notifications" #8806

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ea123ac
[WIP] Working on UI for channel snooze notifications.
lindoelio Oct 28, 2017
288b9f3
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
lindoelio Oct 30, 2017
05121d8
[WIP] Working on channel snooze notifications and channel do not dist…
lindoelio Oct 30, 2017
f63fbc1
[WIP] Working on channel snooze notifications and channel do not dist…
lindoelio Nov 2, 2017
3429631
[WIP] Working on channel snooze notifications and channel do not dist…
lindoelio Nov 3, 2017
0d46f64
[WIP] Working on channel snooze notifications and channel do not dist…
lindoelio Nov 4, 2017
271e8da
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
lindoelio Nov 4, 2017
450f91c
[WIP] Applying channel and general snooze notifications and do not di…
lindoelio Nov 4, 2017
9c63dfa
[WIP] Applying channel and general snooze notifications and do not di…
lindoelio Nov 7, 2017
ce887c2
[WIP] Applying channel and general snooze notifications and do not di…
lindoelio Nov 7, 2017
6b916e1
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
lindoelio Nov 7, 2017
a20b147
Finishing 'do not disturb' and 'snooze notifications' for channel and…
lindoelio Nov 7, 2017
e825475
Working on 'how long to stay do not disturb' feature.
lindoelio Nov 13, 2017
bde52aa
Working on 'how long to stay do not disturb' feature.
lindoelio Nov 13, 2017
74c508c
Add settings for 'how long to stay do not disturb' on application and…
lindoelio Nov 14, 2017
54432b0
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
lindoelio Nov 14, 2017
0deb089
Merge branch 'develop' into do-not-disturb-and-snooze-notifications
rodrigok Dec 7, 2017
d6bb645
Update accountPreferences.js
rodrigok Dec 7, 2017
8d4779e
Update pushNotificationsFlexTab.js
rodrigok Dec 10, 2017
3b82ff2
Applies user's UTC offset on 'do not disturb' check at server side.
lindoelio Dec 14, 2017
eb67799
Applies user's UTC offset on 'do not disturb' check at server side.
lindoelio Dec 14, 2017
260e4e1
Pull updates on branch.
lindoelio Dec 14, 2017
9bf97fb
Removing legacy code already inexistent on current develop codebase.
lindoelio Dec 14, 2017
bf8f172
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
lindoelio Dec 14, 2017
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
21 changes: 21 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,17 @@
"Disable_two-factor_authentication": "Disable two-factor authentication",
"Display_offline_form": "Display Offline Form",
"Displays_action_text": "Displays action text",
"Do_Not_Disturb_Final_Time_Label": "To",
"Do_Not_Disturb_Initial_Time_Label": "From",
"Do_Not_Disturb_Label": "Do Not Disturb",
"Do_Not_Disturb_Repeat_For_Label": "Repeat for",
"Do_Not_Disturb_Repeat_For_1_Day_Option": "1 Day",
"Do_Not_Disturb_Repeat_For_1_Week_Option": "1 Week",
"Do_Not_Disturb_Repeat_For_1_Month_Option": "1 Month",
"Do_Not_Disturb_Repeat_For_1_Year_Option": "1 Year",
"Do_Not_Disturb_Repeat_For_Current_Limit_Label": "Current Limit",
"Do_Not_Disturb_Repeat_For_Every_Day_Option": "Every day",
"Do_Not_Disturb_Repeat_For_Limit_Date_Label": "Until",
"Do_you_want_to_change_to_s_question": "Do you want to change to <strong>%s</strong>?",
"Domain": "Domain",
"Domain_added": "domain Added",
Expand Down Expand Up @@ -1693,6 +1704,16 @@
"Snippet_Added": "Created on %s",
"Snippet_Messages": "Snippet Messages",
"Snippeted_a_message": "Created a snippet __snippetLink__",
"Snooze_Notifications_Current_Enabled_Label": "Current enabled",
"Snooze_Notifications_Final_Time_Label": "Until",
"Snooze_Notifications_Initial_Time_Label": "From",
"Snooze_Notifications_Label": "Snooze Notifications",
"Snooze_Notifications_20_Minutes_Option": "20 minutes",
"Snooze_Notifications_1_Hour_Option": "1 hour",
"Snooze_Notifications_2_Hours_Option": "2 hours",
"Snooze_Notifications_4_Hours_Option": "4 hours",
"Snooze_Notifications_8_Hours_Option": "8 hours",
"Snooze_Notifications_24_Hours_Option": "24 hours",
"Sort_by_activity": "Sort by Activity",
"Sound": "Sound",
"Sound_File_mp3": "Sound File (mp3)",
Expand Down
13 changes: 13 additions & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@
"Direct_Messages": "Mensagens Diretas",
"Display_offline_form": "Exibir formulário quando offline",
"Displays_action_text": "Exibe texto da ação",
"Do_Not_Disturb_Final_Time_Label": "Até",
"Do_Not_Disturb_Initial_Time_Label": "De",
"Do_Not_Disturb_Label": "Não Incomodar",
"Do_you_want_to_change_to_s_question": "Você quer mudar para <strong>%s</strong>?",
"Domain": "Domínio",
"Domains": "Domínios",
Expand Down Expand Up @@ -1069,6 +1072,16 @@
"SMTP_Port": "Porta SMTP",
"SMTP_Test_Button": "Testar Configurações SMTP",
"SMTP_Username": "Nome de usuário SMTP",
"Snooze_Notifications_Current_Enabled_Label": "Atualmente habilitado",
"Snooze_Notifications_Final_Time_Label": "Até",
"Snooze_Notifications_Initial_Time_Label": "A partir de",
"Snooze_Notifications_Label": "Silenciar Notificações",
"Snooze_Notifications_20_Minutes_Option": "20 minutos",
"Snooze_Notifications_1_Hour_Option": "1 hora",
"Snooze_Notifications_2_Hours_Option": "2 horas",
"Snooze_Notifications_4_Hours_Option": "4 horas",
"Snooze_Notifications_8_Hours_Option": "8 horas",
"Snooze_Notifications_24_Hours_Option": "24 horas",
"Sound": "Som",
"SSL": "SSL",
"Star_Message": "Favoritar Message",
Expand Down
13 changes: 13 additions & 0 deletions packages/rocketchat-i18n/i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@
"Disable_two-factor_authentication": "Desactivar autenticação de dois passos",
"Display_offline_form": "Exibir formulário quando offline",
"Displays_action_text": "Exibe texto da ação",
"Do_Not_Disturb_Final_Time_Label": "Até",
"Do_Not_Disturb_Initial_Time_Label": "De",
"Do_Not_Disturb_Label": "Não Incomodar",
"Do_you_want_to_change_to_s_question": "Você quer mudar para <strong>%s</strong>?",
"Domain": "Domínio",
"Domain_added": "Domínio Adicionado",
Expand Down Expand Up @@ -1095,6 +1098,16 @@
"SMTP_Port": "Porta SMTP",
"SMTP_Test_Button": "Testar Configurações SMTP",
"SMTP_Username": "Nome de usuário SMTP",
"Snooze_Notifications_Current_Enabled_Label": "Atualmente habilitado",
"Snooze_Notifications_Final_Time_Label": "Até",
"Snooze_Notifications_Initial_Time_Label": "A partir de",
"Snooze_Notifications_Label": "Silenciar Notificações",
"Snooze_Notifications_20_Minutes_Option": "20 minutos",
"Snooze_Notifications_1_Hour_Option": "1 hora",
"Snooze_Notifications_2_Hours_Option": "2 horas",
"Snooze_Notifications_4_Hours_Option": "4 horas",
"Snooze_Notifications_8_Hours_Option": "8 horas",
"Snooze_Notifications_24_Hours_Option": "24 horas",
"Sound": "Som",
"SSL": "SSL",
"Star_Message": "Favoritar Message",
Expand Down
16 changes: 10 additions & 6 deletions packages/rocketchat-katex/package-lock.json

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

42 changes: 38 additions & 4 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,49 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
userIds.push(s.u._id);
});
const userSettings = {};
RocketChat.models.Users.findUsersByIds(userIds, { fields: { 'settings.preferences.audioNotifications': 1, 'settings.preferences.desktopNotifications': 1, 'settings.preferences.mobileNotifications': 1 } }).forEach((user) => {
RocketChat.models.Users.findUsersByIds(userIds, { fields: { 'settings.preferences.audioNotifications': 1, 'settings.preferences.desktopNotifications': 1, 'settings.preferences.mobileNotifications': 1, 'settings.preferences.snoozeNotifications': 1, 'settings.preferences.doNotDisturb': 1 } }).forEach((user) => {
userSettings[user._id] = user.settings;
});

subscriptions.forEach(subscription => {
if (subscription.disableNotifications) {
const preferences = userSettings[subscription.u._id] ? userSettings[subscription.u._id].preferences || {} : {};

let snoozeNotifications = !!(subscription.snoozeNotifications && subscription.snoozeNotifications.duration && subscription.snoozeNotifications.finalDateTime && moment().isBefore(subscription.snoozeNotifications.finalDateTime));

if (!snoozeNotifications) {
snoozeNotifications = !!(preferences.snoozeNotifications && preferences.snoozeNotifications.duration && preferences.snoozeNotifications.finalDateTime && moment().isBefore(preferences.snoozeNotifications.finalDateTime));
}

let doNotDisturb = false;

const doNotDisturbValidate = (doNotDisturbObject) => {
if (doNotDisturbObject.repeatFor && (doNotDisturbObject.repeatFor === 'every day' || (doNotDisturbObject.limitDateTime && moment().isBefore(doNotDisturbObject.limitDateTime)))) {
const initialMoment = moment(doNotDisturbObject.initialTime, 'HH:mm');
tassoevan marked this conversation as resolved.
Show resolved Hide resolved
let finalMoment = moment(doNotDisturbObject.finalTime, 'HH:mm');

if (initialMoment.isAfter(finalMoment)) {
finalMoment = finalMoment.add(1, 'day');
}

doNotDisturb = moment().isBetween(initialMoment, finalMoment);
}
};

if (subscription.doNotDisturb && subscription.doNotDisturb.initialTime && subscription.doNotDisturb.finalTime) {
doNotDisturbValidate(subscription.doNotDisturb);
}

if (!doNotDisturb && preferences.doNotDisturb && preferences.doNotDisturb.initialTime && preferences.doNotDisturb.finalTime) {
doNotDisturbValidate(preferences.doNotDisturb);
}

if (subscription.disableNotifications || snoozeNotifications || doNotDisturb) {
settings.dontNotifyDesktopUsers.push(subscription.u._id);
settings.dontNotifyMobileUsers.push(subscription.u._id);
settings.dontNotifyAudioUsers.push(subscription.u._id);
return;
}
const preferences = userSettings[subscription.u._id] ? userSettings[subscription.u._id].preferences || {} : {};

const userAudioNotificationPreference = preferences.audioNotifications !== 'default' ? preferences.audioNotifications : undefined;
const userDesktopNotificationPreference = preferences.desktopNotifications !== 'default' ? preferences.desktopNotifications : undefined;
const userMobileNotificationPreference = preferences.mobileNotifications !== 'default' ? preferences.mobileNotifications : undefined;
Expand All @@ -228,14 +259,17 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
desktopNotifications = userDesktopNotificationPreference || RocketChat.settings.get('Desktop_Notifications_Default_Alert'),
mobilePushNotifications = userMobileNotificationPreference || RocketChat.settings.get('Mobile_Notifications_Default_Alert')
} = subscription;

if (audioNotifications === 'all' && !disableAllMessageNotifications) {
settings.alwaysNotifyAudioUsers.push(subscription.u._id);
}

if (desktopNotifications === 'all' && !disableAllMessageNotifications) {
settings.alwaysNotifyDesktopUsers.push(subscription.u._id);
} else if (desktopNotifications === 'nothing') {
settings.dontNotifyDesktopUsers.push(subscription.u._id);
}

if (mobilePushNotifications === 'all' && !disableAllMessageNotifications) {
settings.alwaysNotifyMobileUsers.push(subscription.u._id);
} else if (mobilePushNotifications === 'nothing') {
Expand Down Expand Up @@ -378,7 +412,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {

if (mentionIds.length + settings.alwaysNotifyAudioUsers.length > 0) {
let audioMentionIds = _.union(mentionIds, settings.alwaysNotifyAudioUsers);
audioMentionIds = _.difference(audioMentionIds, userIdsToNotify);
audioMentionIds = _.difference(audioMentionIds, settings.dontNotifyAudioUsers);

let usersOfAudioMentions = RocketChat.models.Users.find({ _id: { $in: audioMentionIds }, statusConnection: {
$ne:'offline'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,86 @@ <h2>{{_ "Notifications"}}</h2>
</div>
</li>
{{#if $neq disableNotifications true}}
<li class="snooze-notifications">
<label>{{_ "Snooze_Notifications_Label"}}</label>
<div class="input checkbox toggle">
<input type="checkbox" id="snoozeNotifications" name="snoozeNotifications" value="1" checked="{{snoozeNotificationsIsValid}}" />
<label for="snoozeNotifications"></label>
</div>
{{#if snoozeNotificationsIsValid }}
<li class="snooze-notifications-time-period">
<div>
{{#if editing 'snoozeNotifications'}}
<label><input type="radio" name="snoozeNotificationsOptions" value="20" checked="{{$eq snoozeNotifications.duration 20}}"/> {{_ "Snooze_Notifications_20_Minutes_Option"}}</label>
<label><input type="radio" name="snoozeNotificationsOptions" value="60" checked="{{$eq snoozeNotifications.duration 60}}"/> {{_ "Snooze_Notifications_1_Hour_Option"}}</label>
<label><input type="radio" name="snoozeNotificationsOptions" value="120" checked="{{$eq snoozeNotifications.duration 120}}"/> {{_ "Snooze_Notifications_2_Hours_Option"}}</label>
<label><input type="radio" name="snoozeNotificationsOptions" value="240" checked="{{$eq snoozeNotifications.duration 240}}"/> {{_ "Snooze_Notifications_4_Hours_Option"}}</label>
<label><input type="radio" name="snoozeNotificationsOptions" value="480" checked="{{$eq snoozeNotifications.duration 480}}"/> {{_ "Snooze_Notifications_8_Hours_Option"}}</label>
<label><input type="radio" name="snoozeNotificationsOptions" value="1440" checked="{{$eq snoozeNotifications.duration 1440}}"/> {{_ "Snooze_Notifications_24_Hours_Option"}}</label>

<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
{{#if snoozeNotifications.duration}}
<span class="current-setting">{{snoozeNotificationsInfo.description}} - {{_ "Snooze_Notifications_Final_Time_Label"}} {{snoozeNotificationsInfo.to}}<i class="icon-pencil" data-edit="snoozeNotifications"></i></span>
{{/if}}
{{/if}}
</div>
</li>
{{/if}}
</li>

<li class="do-not-disturb">
<label>{{_ "Do_Not_Disturb_Label"}}</label>
<div class="input checkbox toggle">
<input type="checkbox" id="doNotDisturb" name="doNotDisturb" value="1" checked="{{doNotDisturbIsValid}}" />
<label for="doNotDisturb"></label>
</div>
{{#if doNotDisturbIsValid}}
<li class="do-not-disturb">
<div>
{{#if editing 'doNotDisturb'}}
<section id="do-not-disturb-initial-period-select">
<label>{{_ "Do_Not_Disturb_Initial_Time_Label"}}</label>
<label>
<select name="doNotDisturbInitialTime">
{{#each selectHoursOptions}}
<option value="{{this}}" selected="{{$eq this doNotDisturb.initialTime}}">{{this}}</option>
{{/each}}
</select>
</label>

<label>{{_ "Do_Not_Disturb_Final_Time_Label"}}</label>
<label>
<select name="doNotDisturbFinalTime">
{{#each selectHoursOptions}}
<option value="{{this}}" selected="{{$eq this doNotDisturb.finalTime}}">{{this}}</option>
{{/each}}
</select>
</label>

<label>{{_ "Do_Not_Disturb_Repeat_For_Label"}}</label>
<label>
<select name="doNotDisturbRepeatFor">
<option value="1 day" selected="{{$eq doNotDisturb.repeatFor '1 day'}}">{{_ "Do_Not_Disturb_Repeat_For_1_Day_Option"}}</option>
<option value="1 week" selected="{{$eq doNotDisturb.repeatFor '1 week'}}">{{_ "Do_Not_Disturb_Repeat_For_1_Week_Option"}}</option>
<option value="1 month" selected="{{$eq doNotDisturb.repeatFor '1 month'}}">{{_ "Do_Not_Disturb_Repeat_For_1_Month_Option"}}</option>
<option value="1 year" selected="{{$eq doNotDisturb.repeatFor '1 year'}}">{{_ "Do_Not_Disturb_Repeat_For_1_Year_Option"}}</option>
<option value="every day" selected="{{$eq doNotDisturb.repeatFor 'every day'}}">{{_ "Do_Not_Disturb_Repeat_For_Every_Day_Option"}}</option>
</select>
</label>
</section>

<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{_ "Do_Not_Disturb_Initial_Time_Label"}} {{doNotDisturbInfo.initialTime}} {{_ "Do_Not_Disturb_Final_Time_Label"}} {{doNotDisturbInfo.finalTime}} ({{doNotDisturbInfo.repeatFor}}{{#if doNotDisturbInfo.limitDateTime}} - {{_ "Do_Not_Disturb_Repeat_For_Limit_Date_Label"}} {{doNotDisturbInfo.limitDateTime}}{{/if}}) <i class="icon-pencil" data-edit="doNotDisturb"></i></span>
{{/if}}
</div>
</li>
{{/if}}
</li>

<li class="audio-notifications">
<label>{{_ "Audio"}}</label>
<div>
Expand Down Expand Up @@ -65,7 +145,7 @@ <h2>{{_ "Notifications"}}</h2>
<li class="desktop-notifications-duration">
<label>{{_ "Desktop_Notifications_Duration"}}</label>
<div>
<span class="current-setting">{{#if desktopNotificationDuration}}{{desktopNotificationDuration}} {{_"seconds"}}{{else}}{{_ "Use_User_Preferences_or_Global_Settings"}}{{/if}}</span>
<span class="current-setting">{{#if desktopNotificationDuration}}{{desktopNotificationDuration}} {{_ "seconds"}}{{else}}{{_ "Use_User_Preferences_or_Global_Settings"}}{{/if}}</span>
</div>
</li>
{{/unless}}
Expand Down
Loading