Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Call clear notification badges on native app init (#5)
Browse files Browse the repository at this point in the history
* Call clear notification badges on native app init

* Updates notification saga to only add reset badge if native
  • Loading branch information
jowlee authored Aug 20, 2020
1 parent 8ca20b3 commit 4de870e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/containers/notification/store/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,24 @@ function* watchTogglePanel() {
})
}

// On Native App open, clear the notification badges
function* resetNotificationBadgeCount() {
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 [
const sagas: (() => Generator)[] = [
watchFetchNotifications,
watchFetchNotificationUsers,
watchMarkNotificationsRead,
Expand All @@ -550,4 +566,8 @@ export default function sagas() {
watchTogglePanel,
watchNotificationError
]
if (NATIVE_MOBILE) {
sagas.push(resetNotificationBadgeCount)
}
return sagas
}
19 changes: 19 additions & 0 deletions src/services/AudiusBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4de870e

Please sign in to comment.