diff --git a/desktop/main.js b/desktop/main.js index 5a9dff5a1cf2..4f8892472fe0 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -240,7 +240,15 @@ 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) => { - app.setBadgeCount(totalCount); + if (totalCount === -1) { + // 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); + } }); return browserWindow; diff --git a/src/CONST.js b/src/CONST.js index 0d84a53b6b7b..b4255d042439 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -148,6 +148,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..16f102622c13 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.js @@ -7,7 +7,11 @@ import {UrbanAirship} from 'urbanairship-react-native'; * @param {Number} totalCount */ function updateUnread(totalCount) { - UrbanAirship.setBadgeNumber(totalCount); + if (totalCount === -1) { + UrbanAirship.setBadgeNumber(1); + } else { + UrbanAirship.setBadgeNumber(totalCount); + } } export default updateUnread; 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; }