mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 18:07:31 -07:00
enhance(sw): If receiving a push notification issued more than a day, ignore it. (#8980)
* enhance(sw): ignore old push notification
* ✌️
* 半日
* !==
* 1日
This commit is contained in:
parent
f73871e73e
commit
a461625b31
3 changed files with 7 additions and 1 deletions
|
@ -64,6 +64,7 @@ export async function pushNotification<T extends keyof pushNotificationsTypes>(u
|
||||||
type,
|
type,
|
||||||
body: type === 'notification' ? truncateNotification(body as Packed<'Notification'>) : body,
|
body: type === 'notification' ? truncateNotification(body as Packed<'Notification'>) : body,
|
||||||
userId,
|
userId,
|
||||||
|
dateTime: (new Date()).getTime(),
|
||||||
}), {
|
}), {
|
||||||
proxy: config.proxy,
|
proxy: config.proxy,
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
|
|
|
@ -42,8 +42,12 @@ self.addEventListener('push', ev => {
|
||||||
// case 'driveFileCreated':
|
// case 'driveFileCreated':
|
||||||
case 'notification':
|
case 'notification':
|
||||||
case 'unreadMessagingMessage':
|
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);
|
return createNotification(data);
|
||||||
case 'readAllNotifications':
|
case 'readAllNotifications':
|
||||||
for (const n of await self.registration.getNotifications()) {
|
for (const n of await self.registration.getNotifications()) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ export type pushNotificationData<K extends keyof pushNotificationDataSourceMap>
|
||||||
type: K;
|
type: K;
|
||||||
body: pushNotificationDataSourceMap[K];
|
body: pushNotificationDataSourceMap[K];
|
||||||
userId: string;
|
userId: string;
|
||||||
|
dateTime: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type pushNotificationDataMap = {
|
export type pushNotificationDataMap = {
|
||||||
|
|
Loading…
Reference in a new issue