summaryrefslogtreecommitdiff
path: root/packages/sw/src
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2022-12-18 19:50:02 +0900
committerGitHub <noreply@github.com>2022-12-18 19:50:02 +0900
commit867e31c9ffefb57d01add5ad8568151fce39614c (patch)
tree133bec354505986b0db3bf95353b24e2d8277792 /packages/sw/src
parentchore(client): :art: about button (#9339) (diff)
downloadmisskey-867e31c9ffefb57d01add5ad8568151fce39614c.tar.gz
misskey-867e31c9ffefb57d01add5ad8568151fce39614c.tar.bz2
misskey-867e31c9ffefb57d01add5ad8568151fce39614c.zip
enhance: Push notification of Antenna note (#9338)
* wip * wip * wip * fix * fix * :art:
Diffstat (limited to 'packages/sw/src')
-rw-r--r--packages/sw/src/scripts/create-notification.ts9
-rw-r--r--packages/sw/src/scripts/operations.ts5
-rw-r--r--packages/sw/src/sw.ts47
-rw-r--r--packages/sw/src/types.ts8
4 files changed, 52 insertions, 17 deletions
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<K extends keyof pushNotificationDataMap>(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', <K extends keyof pushNotificationData
const { action, notification } = ev;
const data: pushNotificationDataMap[K] = notification.data;
- const { userId: id } = data;
+ const { userId: loginId } = data;
let client: WindowClient | null = null;
switch (data.type) {
case 'notification':
switch (action) {
case 'follow':
- if ('userId' in data.body) await swos.api('following/create', id, { userId: data.body.userId });
+ if ('userId' in data.body) await swos.api('following/create', loginId, { userId: data.body.userId });
break;
case 'showUser':
- if ('user' in data.body) client = await swos.openUser(getAcct(data.body.user), id);
+ if ('user' in data.body) client = await swos.openUser(getAcct(data.body.user), loginId);
break;
case 'reply':
- if ('note' in data.body) client = await swos.openPost({ reply: data.body.note }, id);
+ if ('note' in data.body) client = await swos.openPost({ reply: data.body.note }, loginId);
break;
case 'renote':
- if ('note' in data.body) await swos.api('notes/create', id, { renoteId: data.body.note.id });
+ if ('note' in data.body) await swos.api('notes/create', loginId, { renoteId: data.body.note.id });
break;
case 'accept':
switch (data.body.type) {
case 'receiveFollowRequest':
- await swos.api('following/requests/accept', id, { userId: data.body.userId });
+ await swos.api('following/requests/accept', loginId, { userId: data.body.userId });
break;
case 'groupInvited':
- await swos.api('users/groups/invitations/accept', id, { invitationId: data.body.invitation.id });
+ await swos.api('users/groups/invitations/accept', loginId, { invitationId: data.body.invitation.id });
break;
}
break;
case 'reject':
switch (data.body.type) {
case 'receiveFollowRequest':
- await swos.api('following/requests/reject', id, { userId: data.body.userId });
+ await swos.api('following/requests/reject', loginId, { userId: data.body.userId });
break;
case 'groupInvited':
- await swos.api('users/groups/invitations/reject', id, { invitationId: data.body.invitation.id });
+ await swos.api('users/groups/invitations/reject', loginId, { invitationId: data.body.invitation.id });
break;
}
break;
case 'showFollowRequests':
- client = await swos.openClient('push', '/my/follow-requests', id);
+ client = await swos.openClient('push', '/my/follow-requests', loginId);
break;
default:
switch (data.body.type) {
case 'receiveFollowRequest':
- client = await swos.openClient('push', '/my/follow-requests', id);
+ client = await swos.openClient('push', '/my/follow-requests', loginId);
break;
case 'groupInvited':
- client = await swos.openClient('push', '/my/groups', id);
+ client = await swos.openClient('push', '/my/groups', loginId);
break;
case 'reaction':
- client = await swos.openNote(data.body.note.id, id);
+ client = await swos.openNote(data.body.note.id, loginId);
break;
default:
if ('note' in data.body) {
- client = await swos.openNote(data.body.note.id, id);
+ client = await swos.openNote(data.body.note.id, loginId);
} else if ('user' in data.body) {
- client = await swos.openUser(getAcct(data.body.user), id);
+ client = await swos.openUser(getAcct(data.body.user), loginId);
}
break;
}
}
break;
case 'unreadMessagingMessage':
- client = await swos.openChat(data.body, id);
+ client = await swos.openChat(data.body, loginId);
break;
+ case 'unreadAntennaNote':
+ client = await swos.openAntenna(data.body.antenna.id, loginId);
}
if (client) {
diff --git a/packages/sw/src/types.ts b/packages/sw/src/types.ts
index 8350fb80b8..2e23de8e1d 100644
--- a/packages/sw/src/types.ts
+++ b/packages/sw/src/types.ts
@@ -10,14 +10,20 @@ export type SwMessage = {
[x: string]: any;
};
-// Defined also @/core/push-notification.ts#L7-L14
+// Defined also @/core/PushNotificationService.ts#L12
type pushNotificationDataSourceMap = {
notification: Misskey.entities.Notification;
unreadMessagingMessage: Misskey.entities.MessagingMessage;
+ unreadAntennaNote: {
+ antenna: { id: string, name: string };
+ note: Misskey.entities.Note;
+ };
readNotifications: { notificationIds: string[] };
readAllNotifications: undefined;
readAllMessagingMessages: undefined;
readAllMessagingMessagesOfARoom: { userId: string } | { groupId: string };
+ readAntenna: { antennaId: string };
+ readAllAntennas: undefined;
};
export type pushNotificationData<K extends keyof pushNotificationDataSourceMap> = {