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

Call clear notification badges on native app init #5

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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