Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic notification support #2459

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2fff918
Basic notification support
corrideat Dec 15, 2024
ad7835c
Merge branch 'master' into 2455-implement-push-notifications-for-noti…
corrideat Dec 16, 2024
5839cfa
Notification template updates
corrideat Dec 17, 2024
b61be2f
Add groupID and plaintext display name
corrideat Dec 19, 2024
e7894ab
Merge branch 'master' into 2455-implement-push-notifications-for-noti…
corrideat Dec 19, 2024
3c62ff5
Set the correct group ID when clicking on notifications, etc.
corrideat Dec 19, 2024
846aac4
Fallback Notification
corrideat Dec 19, 2024
b0e8dd4
Comment for sbp-type message
corrideat Dec 22, 2024
6a9ad06
Notification icons
corrideat Dec 22, 2024
6fea6bf
server-side push recurring inverval notification
corrideat Dec 22, 2024
9a43338
More generic periodic notifications
corrideat Dec 25, 2024
95813ea
`ForGroup` pattern
corrideat Dec 27, 2024
3775003
Improvements and bugfixes
corrideat Dec 28, 2024
2612cf8
Update `mainNotificationsMixin`
corrideat Dec 28, 2024
d1d77e2
WIP
corrideat Dec 28, 2024
db5a4e4
WIP
corrideat Dec 29, 2024
98d2f56
Emit notifications on recurring push event
corrideat Dec 29, 2024
46bb3c2
Fixes WIP
corrideat Dec 29, 2024
8b47148
Revert changes to NotificationCard.vue
corrideat Dec 29, 2024
399a17b
Wait for queue invocation to be empty
corrideat Dec 31, 2024
7860a7b
Remove unnecessary setTimeout
corrideat Dec 31, 2024
f0fc1f3
Periodic sync events
corrideat Dec 31, 2024
efcf79e
Fix types
corrideat Dec 31, 2024
0ddaaa4
Bugfix
corrideat Dec 31, 2024
1981a2f
Merge branch 'master' into 2455-implement-push-notifications-for-noti…
corrideat Dec 31, 2024
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
3 changes: 3 additions & 0 deletions frontend/controller/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ sbp('sbp/selectors/register', {
break
}
case 'navigate': {
if (data.groupID) {
sbp('state/vuex/commit', 'setCurrentGroupId', { contractID: data.groupID })
}
sbp('controller/router').push({ path: data.path }).catch(console.warn)
break
}
Expand Down
18 changes: 16 additions & 2 deletions frontend/controller/serviceworkers/sw-primary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

import { MESSAGE_RECEIVE, MESSAGE_SEND, PROPOSAL_ARCHIVED } from '@model/contracts/shared/constants.js'
import { makeNotification } from '@model/notifications/nativeNotification.js'
import '@model/swCaptureLogs.js'
import '@sbp/okturtles.data'
import '@sbp/okturtles.eventqueue'
Expand Down Expand Up @@ -157,11 +158,11 @@ sbp('sbp/selectors/register', {
})()
})

const x = new URL(self.location)
const ourLocation = new URL(self.location)

sbp('sbp/selectors/register', {
'controller/router': () => {
return { options: { base: x.searchParams.get('routerBase') } }
return { options: { base: ourLocation.searchParams.get('routerBase') } }
}
})

Expand Down Expand Up @@ -281,6 +282,7 @@ self.addEventListener('notificationclick', event => {
if (event.notification.data?.path) {
client.postMessage({
type: 'navigate',
groupID: event.notification.data.groupID,
path: event.notification.data.path
})
}
Expand Down Expand Up @@ -326,3 +328,15 @@ sbp('okTurtles.events/on', NEW_CHATROOM_UNREAD_POSITION, ({ chatRoomID, messageH
}
sbp('okTurtles.events/emit', CHELONIA_STATE_MODIFIED)
})

sbp('okTurtles.events/on', NOTIFICATION_EMITTED, (notification) => {
makeNotification({
// icon: undefined, // TODO
title: notification.title,
body: notification.plaintextBody,
groupID: notification.groupID,
path: notification.linkTo
}).catch(e => {
console.error('Error displaying native notification', e)
})
})
11 changes: 6 additions & 5 deletions frontend/model/notifications/nativeNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export async function requestNotificationPermission (): Promise<null | string> {
}
}

export function makeNotification ({ title, body, icon, path }: {
title: string, body: string, icon?: string, path?: string
}): void | Promise<void> {
// eslint-disable-next-line require-await
export async function makeNotification ({ title, body, icon, path, groupID }: {
title: string, body: string, icon?: string, path?: string, groupID?: string
}): Promise<void> {
if (typeof Notification !== 'function') return
// If not running on a SW
if (typeof WorkerGlobalScope !== 'function') {
Expand All @@ -108,11 +109,11 @@ export function makeNotification ({ title, body, icon, path }: {
} else {
// If running in a SW
return self.clients.matchAll({ type: 'window' }).then((clientList) => {
// If the no window is focused, display a native notification
// If no window is focused, display a native notification
if (clientList.some(client => client.focused)) {
return
}
return self.registration.showNotification(title, { body, icon, data: { path } }).catch(console.warn)
return self.registration.showNotification(title, { body, icon, data: { groupID, path } }).catch(console.warn)
})
}
}
Loading