From 867e31c9ffefb57d01add5ad8568151fce39614c Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 18 Dec 2022 19:50:02 +0900 Subject: enhance: Push notification of Antenna note (#9338) * wip * wip * wip * fix * fix * :art: --- packages/sw/src/scripts/create-notification.ts | 9 +++++ packages/sw/src/scripts/operations.ts | 5 +++ packages/sw/src/sw.ts | 47 +++++++++++++++++--------- packages/sw/src/types.ts | 8 ++++- 4 files changed, 52 insertions(+), 17 deletions(-) (limited to 'packages/sw/src') diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts index c27e8c709c..fd5b0fa312 100644 --- a/packages/sw/src/scripts/create-notification.ts +++ b/packages/sw/src/scripts/create-notification.ts @@ -252,6 +252,15 @@ async function composeNotification(data data, renotify: true, }]; + case 'unreadAntennaNote': + return [t('_notification.unreadAntennaNote', { name: data.body.antenna.name }), { + body: `${getUserName(data.body.note.user)}: ${data.body.note.text || ''}`, + icon: data.body.note.user.avatarUrl, + badge: iconUrl('satellite'), + tag: `antenna:${data.body.antenna.id}`, + data, + renotify: true, + }]; default: return null; } diff --git a/packages/sw/src/scripts/operations.ts b/packages/sw/src/scripts/operations.ts index fd27418073..719e3ea9fa 100644 --- a/packages/sw/src/scripts/operations.ts +++ b/packages/sw/src/scripts/operations.ts @@ -27,6 +27,11 @@ export function openNote(noteId: string, loginId: string) { return openClient('push', `/notes/${noteId}`, loginId, { noteId }); } +// noteIdからノートを開く +export function openAntenna(antennaId: string, loginId: string) { + return openClient('push', `/timeline/antenna/${antennaId}`, loginId, { antennaId }); +} + export async function openChat(body: any, loginId: string) { if (body.groupId === null) { return openClient('push', `/my/messaging/${getAcct(body.user)}`, loginId, { body }); diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts index 04372a0708..d47563939a 100644 --- a/packages/sw/src/sw.ts +++ b/packages/sw/src/sw.ts @@ -50,6 +50,7 @@ self.addEventListener('push', ev => { // case 'driveFileCreated': case 'notification': case 'unreadMessagingMessage': + case 'unreadAntennaNote': // 1日以上経過している場合は無視 if ((new Date()).getTime() - data.dateTime > 1000 * 60 * 60 * 24) break; @@ -67,6 +68,11 @@ self.addEventListener('push', ev => { if (n?.data?.type === 'unreadMessagingMessage') n.close(); } break; + case 'readAllAntennas': + for (const n of await self.registration.getNotifications()) { + if (n?.data?.type === 'unreadAntennaNote') n.close(); + } + break; case 'readNotifications': for (const n of await self.registration.getNotifications()) { if (data.body?.notificationIds?.includes(n.data.body.id)) { @@ -85,6 +91,13 @@ self.addEventListener('push', ev => { } } break; + case 'readAntenna': + for (const n of await self.registration.getNotifications()) { + if (n?.data?.type === 'unreadAntennaNote' && data.body?.antennaId === n.data.body.antenna.id) { + n.close(); + } + } + break; } return createEmptyNotification(); @@ -99,71 +112,73 @@ self.addEventListener('notificationclick', = { -- cgit v1.2.3-freya