From 72fa7654083650491d084ec70223cf3763897018 Mon Sep 17 00:00:00 2001 From: jowlee Date: Thu, 20 Aug 2020 12:06:08 -0400 Subject: [PATCH 1/2] Call clear notification badges on native app init --- src/containers/notification/store/sagas.ts | 17 +++++++++++++++++ src/services/AudiusBackend.js | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/containers/notification/store/sagas.ts b/src/containers/notification/store/sagas.ts index 8ac142934f..00b9f0fdd8 100644 --- a/src/containers/notification/store/sagas.ts +++ b/src/containers/notification/store/sagas.ts @@ -536,8 +536,25 @@ function* watchTogglePanel() { }) } +// On Native App open, clear the notification badges +function* notificationsInit() { + try { + yield call(waitForBackendSetup) + + const hasAccount = yield select(getHasAccount) + if (hasAccount && NATIVE_MOBILE) { + const message = new ResetNotificationsBadgeCount() + message.send() + yield call(AudiusBackend.clearNotificationBadges) + } + } catch (error) { + console.error(error) + } +} + export default function sagas() { return [ + notificationsInit, watchFetchNotifications, watchFetchNotificationUsers, watchMarkNotificationsRead, diff --git a/src/services/AudiusBackend.js b/src/services/AudiusBackend.js index 08052517bf..4582ae8548 100644 --- a/src/services/AudiusBackend.js +++ b/src/services/AudiusBackend.js @@ -1950,6 +1950,25 @@ class AudiusBackend { } } + static async clearNotificationBadges() { + await waitForLibsInit() + const account = audiusLibs.Account.getCurrentUser() + if (!account) return + try { + const { data, signature } = await AudiusBackend.signData() + return fetch(`${IDENTITY_SERVICE}/notifications/clear_badges`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + [AuthHeaders.Message]: data, + [AuthHeaders.Signature]: signature + } + }).then(res => res.json()) + } catch (e) { + console.error(e) + } + } + static async getEmailNotificationSettings() { await waitForLibsInit() const account = audiusLibs.Account.getCurrentUser() From 6960550b4818ec8697417bdf8d1a6aa36b797ef0 Mon Sep 17 00:00:00 2001 From: jowlee Date: Thu, 20 Aug 2020 14:45:57 -0400 Subject: [PATCH 2/2] Updates notification saga to only add reset badge if native --- src/containers/notification/store/sagas.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/containers/notification/store/sagas.ts b/src/containers/notification/store/sagas.ts index 00b9f0fdd8..5d15811ff1 100644 --- a/src/containers/notification/store/sagas.ts +++ b/src/containers/notification/store/sagas.ts @@ -537,7 +537,7 @@ function* watchTogglePanel() { } // On Native App open, clear the notification badges -function* notificationsInit() { +function* resetNotificationBadgeCount() { try { yield call(waitForBackendSetup) @@ -553,8 +553,7 @@ function* notificationsInit() { } export default function sagas() { - return [ - notificationsInit, + const sagas: (() => Generator)[] = [ watchFetchNotifications, watchFetchNotificationUsers, watchMarkNotificationsRead, @@ -567,4 +566,8 @@ export default function sagas() { watchTogglePanel, watchNotificationError ] + if (NATIVE_MOBILE) { + sagas.push(resetNotificationBadgeCount) + } + return sagas }