Skip to content

Commit b1a0abe

Browse files
authored
Service Worker rewrite (#2274)
* Convert all top-level arrow functions to regular functions * Refactor webPush.sendNotification call * Refactor webPush logging * Rename var to title * Rewrite service worker This rewrite simplifies the service worker by removing * merging of push notifications via tag property * badge count These features weren't properly working on iOS. We concluded that we don't really need them. For example, this means replies will no longer get merged to "you have X new replies" but show up as individual notifications. Only zaps still use the tag property so devices that support it can still replace any previous "your post stacked X sats" notification for the same item. * Don't use async/await in service worker * Support app badge count * Fix extremely slow notificationclick * Fix serialization and save in pushsubscriptionchange event
1 parent bfced69 commit b1a0abe

File tree

8 files changed

+266
-345
lines changed

8 files changed

+266
-345
lines changed

components/serviceworker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ServiceWorkerContext = createContext()
99
// message types for communication between app and service worker
1010
export const DELETE_SUBSCRIPTION = 'DELETE_SUBSCRIPTION'
1111
export const STORE_SUBSCRIPTION = 'STORE_SUBSCRIPTION'
12+
export const CLEAR_NOTIFICATIONS = 'CLEAR_NOTIFICATIONS'
1213

1314
export const ServiceWorkerProvider = ({ children }) => {
1415
const [registration, setRegistration] = useState(null)
@@ -140,6 +141,10 @@ export const ServiceWorkerProvider = ({ children }) => {
140141
)
141142
}
142143

144+
export function clearNotifications () {
145+
return navigator.serviceWorker?.controller?.postMessage({ action: CLEAR_NOTIFICATIONS })
146+
}
147+
143148
export function useServiceWorker () {
144149
return useContext(ServiceWorkerContext)
145150
}

components/use-has-new-notes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { HAS_NOTIFICATIONS } from '@/fragments/notifications'
2-
import { clearNotifications } from '@/lib/badge'
32
import { NORMAL_POLL_INTERVAL, SSR } from '@/lib/constants'
43
import { useQuery } from '@apollo/client'
54
import React, { useContext } from 'react'
5+
import { clearNotifications } from '@/components/serviceworker'
66

77
export const HasNewNotesContext = React.createContext(false)
88

lib/badge.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)