This commit is contained in:
tamaina
2021-02-13 01:28:20 +09:00
parent 538bba080f
commit 979f91bd34
5 changed files with 138 additions and 35 deletions

View File

@@ -46,54 +46,63 @@ async function composeNotification(data: pushNotificationData): Promise<[string,
case 'reply':
return [t('_notification.youGotReply', { name: getUserName(data.body.user) }), {
body: getNoteSummary(data.body.note, i18n.locale),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'renote':
return [t('_notification.youRenoted', { name: getUserName(data.body.user) }), {
body: getNoteSummary(data.body.note, i18n.locale),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'quote':
return [t('_notification.youGotQuote', { name: getUserName(data.body.user) }), {
body: getNoteSummary(data.body.note, i18n.locale),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'reaction':
return [`${data.body.reaction} ${getUserName(data.body.user)}`, {
body: getNoteSummary(data.body.note, i18n.locale),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'pollVote':
return [t('_notification.youGotPoll', { name: getUserName(data.body.user) }), {
body: getNoteSummary(data.body.note, i18n.locale),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'follow':
return [t('_notification.youWereFollowed'), {
body: getUserName(data.body.user),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'receiveFollowRequest':
return [t('_notification.youReceivedFollowRequest'), {
body: getUserName(data.body.user),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'followRequestAccepted':
return [t('_notification.yourFollowRequestAccepted'), {
body: getUserName(data.body.user),
icon: data.body.user.avatarUrl
icon: data.body.user.avatarUrl,
data,
}];
case 'groupInvited':
return [t('_notification.youWereInvitedToGroup'), {
body: data.body.group.name
body: data.body.group.name,
data,
}];
default:
@@ -103,12 +112,14 @@ async function composeNotification(data: pushNotificationData): Promise<[string,
if (data.body.groupId === null) {
return [t('_notification.youGotMessagingMessageFromUser', { name: getUserName(data.body.user) }), {
icon: data.body.user.avatarUrl,
tag: `messaging:user:${data.body.user.id}`
tag: `messaging:user:${data.body.user.id}`,
data,
}];
}
return [t('_notification.youGotMessagingMessageFromGroup', { name: data.body.group.name }), {
icon: data.body.user.avatarUrl,
tag: `messaging:group:${data.body.group.id}`
tag: `messaging:group:${data.body.group.id}`,
data,
}];
default:
return null;

View File

@@ -58,9 +58,11 @@ self.addEventListener('push', ev => {
const data: pushNotificationData = ev.data?.json();
console.log('push', data)
switch (data.type) {
case 'notification':
// case 'driveFileCreated':
case 'notification':
case 'unreadMessagingMessage':
return createNotification(data);
case 'readAllNotifications':
@@ -83,6 +85,7 @@ self.addEventListener('push', ev => {
//#region Notification
self.addEventListener('notificationclick', ev => {
const { action, notification } = ev;
console.log('click', action, notification)
const data: pushNotificationData = notification.data;
const { origin } = location;
@@ -110,6 +113,8 @@ self.addEventListener('notificationclick', ev => {
self.addEventListener('notificationclose', ev => {
const { notification } = ev;
console.log('close', notification)
if (notification.title !== 'notificationclose') {
self.registration.showNotification('notificationclose', { body: `${notification?.data?.body?.id}` });
}