This commit is contained in:
tamaina
2021-02-17 02:20:45 +09:00
parent 2dc4f24f18
commit c0e9cc1902
6 changed files with 97 additions and 53 deletions

View File

@@ -169,14 +169,42 @@ async function composeNotification(data: pushNotificationData): Promise<[string,
icon: body.user.avatarUrl,
tag: `messaging:user:${body.userId}`,
data,
renotify: true,
}];
}
return [t('_notification.youGotMessagingMessageFromGroup', { name: body.group.name }), {
icon: body.user.avatarUrl,
tag: `messaging:group:${body.groupId}`,
data,
renotify: true,
}];
default:
return null;
}
}
export async function createAllReadNotification(type: 'notifications' | 'messagingMessages') {
const n = await composeAllReadNotification(type);
if (n) return self.registration.showNotification(...n);
}
async function composeAllReadNotification(type: string): Promise<[string, NotificationOptions] | null | undefined> {
if (!swLang.i18n) swLang.fetchLocale();
const i18n = await swLang.i18n as I18n<any>;
const { t } = i18n;
if (type === 'notifications') {
return [t('readAllNotifications'), {
silent: true,
tag: 'user_visible_auto_notification',
}];
}
if (type === 'messagingMessages') {
return [t('readAllMessagingMessages'), {
silent: true,
tag: 'user_visible_auto_notification',
}];
}
return;
}

View File

@@ -61,7 +61,12 @@ export async function openPost(options: any, loginId: string) {
export async function openClient(order: swMessageOrderType, url: string, loginId: string, query: any = {}) {
const client = await self.clients.matchAll({
type: 'window'
}).then(clients => clients.length > 0 ? clients[0] as WindowClient : null);
}).then(clients => {
for (const c of clients) {
if (c.url.indexOf('?zen') < 0) return c;
}
return null;
});
if (client) {
client.postMessage({ type: 'order', ...query, order, loginId, url } as SwMessage);

View File

@@ -38,6 +38,14 @@ self.addEventListener('fetch', ev => {
//#region When: Caught Notification
self.addEventListener('push', ev => {
setTimeout(async () => {
console.log('to');
for (const n of await self.registration.getNotifications({ tag: 'user_visible_auto_notification' })) {
console.log(close)
n.close();
}
}, 5000);
// クライアント取得
ev.waitUntil(self.clients.matchAll({
includeUncontrolled: true,