diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2022-07-10 15:15:21 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-10 15:15:21 +0900 |
| commit | 83ebe79a3fe5ddb22e80d3b47b9e8ec0701286ad (patch) | |
| tree | 55ebb5ef0e28f3ae2ccc68b0565372815fad926e | |
| parent | fix(client): fix style of mention (diff) | |
| download | misskey-83ebe79a3fe5ddb22e80d3b47b9e8ec0701286ad.tar.gz misskey-83ebe79a3fe5ddb22e80d3b47b9e8ec0701286ad.tar.bz2 misskey-83ebe79a3fe5ddb22e80d3b47b9e8ec0701286ad.zip | |
enhance(sw): If receiving a push notification issued more than a day, ignore it. (#8980)
* enhance(sw): ignore old push notification
* :v:
* 半日
* !==
* 1日
| -rw-r--r-- | packages/backend/src/services/push-notification.ts | 1 | ||||
| -rw-r--r-- | packages/sw/src/sw.ts | 6 | ||||
| -rw-r--r-- | packages/sw/src/types.ts | 1 |
3 files changed, 7 insertions, 1 deletions
diff --git a/packages/backend/src/services/push-notification.ts b/packages/backend/src/services/push-notification.ts index 5c3bafbb34..393a23d050 100644 --- a/packages/backend/src/services/push-notification.ts +++ b/packages/backend/src/services/push-notification.ts @@ -64,6 +64,7 @@ export async function pushNotification<T extends keyof pushNotificationsTypes>(u type, body: type === 'notification' ? truncateNotification(body as Packed<'Notification'>) : body, userId, + dateTime: (new Date()).getTime(), }), { proxy: config.proxy, }).catch((err: any) => { diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts index 0ba6a6e4af..872692f903 100644 --- a/packages/sw/src/sw.ts +++ b/packages/sw/src/sw.ts @@ -42,8 +42,12 @@ self.addEventListener('push', ev => { // case 'driveFileCreated': case 'notification': case 'unreadMessagingMessage': + // 1日以上経過している場合は無視 + if ((new Date()).getTime() - data.dateTime > 1000 * 60 * 60 * 24) break; + // クライアントがあったらストリームに接続しているということなので通知しない - if (clients.length != 0) return; + if (clients.length !== 0) break; + return createNotification(data); case 'readAllNotifications': for (const n of await self.registration.getNotifications()) { diff --git a/packages/sw/src/types.ts b/packages/sw/src/types.ts index 6aa3726eac..0404e21e57 100644 --- a/packages/sw/src/types.ts +++ b/packages/sw/src/types.ts @@ -24,6 +24,7 @@ export type pushNotificationData<K extends keyof pushNotificationDataSourceMap> type: K; body: pushNotificationDataSourceMap[K]; userId: string; + dateTime: number; }; export type pushNotificationDataMap = { |