From 9335df51c1cceb07db5006b7306ebd54b2141bdc Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Thu, 24 Jun 2021 17:11:24 -0700 Subject: [PATCH 1/3] Design Doc Specs of the Sidebar / GSD Mode Aspect of NotificationPreferences --- desktop/main.js | 3 +++ src/CONST.js | 5 +++++ src/libs/UnreadIndicatorUpdater/index.js | 22 +++++++++++++++++-- .../updateUnread/index.ios.js | 3 +++ .../updateUnread/index.website.js | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/desktop/main.js b/desktop/main.js index 5a9dff5a1cf2..a2d233278cff 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -240,6 +240,9 @@ const mainWindow = (() => { // Listen to badge updater event emitted by the render process // and update the app badge count (MacOS only) ipcMain.on(ELECTRON_EVENTS.REQUEST_UPDATE_BADGE_COUNT, (event, totalCount) => { + if (totalCount === -1) { + app.setBadgeCount(); + } app.setBadgeCount(totalCount); }); diff --git a/src/CONST.js b/src/CONST.js index 39ef3103d848..a33e890426b0 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -147,6 +147,11 @@ const CONST = { PROCESSING: 1, SUBMITTED: 2, }, + NOTIFICATION_PREFERENCE: { + MUTE: 'mute', + DAILY: 'daily', + ALWAYS: 'always', + }, }, MODAL: { MODAL_TYPE: { diff --git a/src/libs/UnreadIndicatorUpdater/index.js b/src/libs/UnreadIndicatorUpdater/index.js index 3ef1fb47879f..00547ec957d5 100644 --- a/src/libs/UnreadIndicatorUpdater/index.js +++ b/src/libs/UnreadIndicatorUpdater/index.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; +import CONST from '../../CONST'; import updateUnread from './updateUnread'; // Stash the unread action counts for each report @@ -11,7 +12,14 @@ const unreadActionCounts = {}; * and Mac OS or iOS dock icon with an unread indicator. */ const throttledUpdatePageTitleAndUnreadCount = _.throttle(() => { - const totalCount = _.reduce(unreadActionCounts, (total, reportCount) => total + reportCount, 0); + // If all of our nonzero unread action counts show -1, update the unread count to be -1 as well so we don't show a + // number in the indicator badge. + if (_.every(unreadActionCounts, count => count < 1) && _.some(unreadActionCounts, count => count === -1)) { + updateUnread(-1); + return; + } + + const totalCount = _.reduce(unreadActionCounts, (total, reportCount) => total + Math.max(reportCount, 0), 0); updateUnread(totalCount); }, 1000, {leading: false}); @@ -29,7 +37,17 @@ function listenForReportChanges() { return; } - unreadActionCounts[report.reportID] = report.unreadActionCount || 0; + if (report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE) { + return; + } + + // An unreadActionCount of -1 signifies that we should show a badge icon with no number + if (report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY + && report.unreadActionCount > 0) { + unreadActionCounts[report.reportID] = -1; + } else { + unreadActionCounts[report.reportID] = report.unreadActionCount || 0; + } throttledUpdatePageTitleAndUnreadCount(); }, }); diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js index b9b62a42ea67..43d86f285873 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js @@ -7,6 +7,9 @@ import {UrbanAirship} from 'urbanairship-react-native'; * @param {Number} totalCount */ function updateUnread(totalCount) { + if (totalCount === -1) { + UrbanAirship.setBadgeNumber(1); + } UrbanAirship.setBadgeNumber(totalCount); } diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js b/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js index 2f5c2769ed9f..aca9134a16ab 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js @@ -9,7 +9,7 @@ import CONFIG from '../../../CONFIG'; * @param {Number} totalCount */ function updateUnread(totalCount) { - const hasUnread = totalCount > 0; + const hasUnread = totalCount !== 0; document.title = hasUnread ? `(NEW!) ${CONFIG.SITE_TITLE}` : CONFIG.SITE_TITLE; document.getElementById('favicon').href = hasUnread ? CONFIG.FAVICON.UNREAD : CONFIG.FAVICON.DEFAULT; } From 45dbe870ee5927e1ae10e70adf2023811af5ce03 Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Fri, 25 Jun 2021 12:04:07 -0700 Subject: [PATCH 2/3] Add fix for desktop --- desktop/main.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/desktop/main.js b/desktop/main.js index a2d233278cff..4f8892472fe0 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -241,9 +241,14 @@ const mainWindow = (() => { // and update the app badge count (MacOS only) ipcMain.on(ELECTRON_EVENTS.REQUEST_UPDATE_BADGE_COUNT, (event, totalCount) => { if (totalCount === -1) { - app.setBadgeCount(); + // The electron docs say you should be able to update this and pass no parameters to set the badge + // to a single red dot, but in practice it resulted in an error "TypeError: Insufficient number of + // arguments." - Thus, setting to 1 instead. + // See: https://www.electronjs.org/docs/api/app#appsetbadgecountcount-linux-macos + app.setBadgeCount(1); + } else { + app.setBadgeCount(totalCount); } - app.setBadgeCount(totalCount); }); return browserWindow; From fd74b95dbf59e50bf6b3c8f93eec9aafb753b926 Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Mon, 28 Jun 2021 16:57:07 -0700 Subject: [PATCH 3/3] Update if/else error --- src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js index 43d86f285873..16f102622c13 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js @@ -9,8 +9,9 @@ import {UrbanAirship} from 'urbanairship-react-native'; function updateUnread(totalCount) { if (totalCount === -1) { UrbanAirship.setBadgeNumber(1); + } else { + UrbanAirship.setBadgeNumber(totalCount); } - UrbanAirship.setBadgeNumber(totalCount); } export default updateUnread;