summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-04-15 18:27:45 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-04-15 18:27:45 +0900
commitfc6037af461412d914cd35a00fa004ad26d19c0f (patch)
tree8551e0789e2a68a8a3ce05e3253a32d0fbcc86c8 /packages
parentdocs: バックアップとログアウトの設定クリアについて書... (diff)
downloadsharkey-fc6037af461412d914cd35a00fa004ad26d19c0f.tar.gz
sharkey-fc6037af461412d914cd35a00fa004ad26d19c0f.tar.bz2
sharkey-fc6037af461412d914cd35a00fa004ad26d19c0f.zip
enhance(backend): push notification for chat message
Resolve #15831
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/src/core/ChatService.ts4
-rw-r--r--packages/backend/src/core/PushNotificationService.ts1
-rw-r--r--packages/sw/src/scripts/create-notification.ts18
-rw-r--r--packages/sw/src/scripts/operations.ts10
-rw-r--r--packages/sw/src/sw.ts4
-rw-r--r--packages/sw/src/types.ts1
6 files changed, 35 insertions, 3 deletions
diff --git a/packages/backend/src/core/ChatService.ts b/packages/backend/src/core/ChatService.ts
index b0e8cfb61c..9d294a80cb 100644
--- a/packages/backend/src/core/ChatService.ts
+++ b/packages/backend/src/core/ChatService.ts
@@ -232,7 +232,7 @@ export class ChatService {
const packedMessageForTo = await this.chatEntityService.packMessageDetailed(inserted, toUser);
this.globalEventService.publishMainStream(toUser.id, 'newChatMessage', packedMessageForTo);
- //this.pushNotificationService.pushNotification(toUser.id, 'newChatMessage', packedMessageForTo);
+ this.pushNotificationService.pushNotification(toUser.id, 'newChatMessage', packedMessageForTo);
}, 3000);
}
@@ -302,7 +302,7 @@ export class ChatService {
if (marker == null) continue;
this.globalEventService.publishMainStream(membershipsOtherThanMe[i].userId, 'newChatMessage', packedMessageForTo);
- //this.pushNotificationService.pushNotification(membershipsOtherThanMe[i].userId, 'newChatMessage', packedMessageForTo);
+ this.pushNotificationService.pushNotification(membershipsOtherThanMe[i].userId, 'newChatMessage', packedMessageForTo);
}
}, 3000);
diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts
index 1479bb00d9..9333c1ebc5 100644
--- a/packages/backend/src/core/PushNotificationService.ts
+++ b/packages/backend/src/core/PushNotificationService.ts
@@ -22,6 +22,7 @@ type PushNotificationsTypes = {
note: Packed<'Note'>;
};
'readAllNotifications': undefined;
+ newChatMessage: Packed<'ChatMessage'>;
};
// Reduce length because push message servers have character limits
diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts
index 364328d4b0..77b3f88791 100644
--- a/packages/sw/src/scripts/create-notification.ts
+++ b/packages/sw/src/scripts/create-notification.ts
@@ -268,6 +268,24 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
data,
renotify: true,
}];
+ case 'newChatMessage':
+ if (data.body.toRoom != null) {
+ return [`${data.body.toRoom.name}: ${getUserName(data.body.fromUser)}: ${data.body.text}`, {
+ icon: data.body.fromUser.avatarUrl,
+ badge: iconUrl('messages'),
+ tag: `chat:room:${data.body.toRoomId}`,
+ data,
+ renotify: true,
+ }];
+ } else {
+ return [`${getUserName(data.body.fromUser)}: ${data.body.text}`, {
+ icon: data.body.fromUser.avatarUrl,
+ badge: iconUrl('messages'),
+ tag: `chat:user:${data.body.fromUserId}`,
+ data,
+ renotify: true,
+ }];
+ }
default:
return null;
}
diff --git a/packages/sw/src/scripts/operations.ts b/packages/sw/src/scripts/operations.ts
index 8862c6faa5..3e72b7e7c2 100644
--- a/packages/sw/src/scripts/operations.ts
+++ b/packages/sw/src/scripts/operations.ts
@@ -16,7 +16,7 @@ export const cli = new Misskey.api.APIClient({ origin, fetch: (...args): Promise
export async function api<
E extends keyof Misskey.Endpoints,
- P extends Misskey.Endpoints[E]['req']
+ P extends Misskey.Endpoints[E]['req'],
>(endpoint: E, userId?: string, params?: P): Promise<Misskey.api.SwitchCaseResponseType<E, P> | undefined> {
let account: Pick<Misskey.entities.SignupResponse, 'id' | 'token'> | undefined;
@@ -60,6 +60,14 @@ export function openAntenna(antennaId: string, loginId: string): ReturnType<type
return openClient('push', `/timeline/antenna/${antennaId}`, loginId, { antennaId });
}
+export function openChat(body: any, loginId: string): ReturnType<typeof openClient> {
+ if (body.toRoomId != null) {
+ return openClient('push', `/chat/room/${body.toRoomId}`, loginId, { body });
+ } else {
+ return openClient('push', `/chat/user/${body.toUserId}`, loginId, { body });
+ }
+}
+
// post-formのオプションから投稿フォームを開く
export async function openPost(options: { initialText?: string; reply?: Misskey.entities.Note; renote?: Misskey.entities.Note }, loginId?: string): ReturnType<typeof openClient> {
// クエリを作成しておく
diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts
index bf980b83a4..298af4b4b6 100644
--- a/packages/sw/src/sw.ts
+++ b/packages/sw/src/sw.ts
@@ -76,6 +76,7 @@ globalThis.addEventListener('push', ev => {
// case 'driveFileCreated':
case 'notification':
case 'unreadAntennaNote':
+ case 'newChatMessage':
// 1日以上経過している場合は無視
if (Date.now() - data.dateTime > 1000 * 60 * 60 * 24) break;
@@ -155,6 +156,9 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv
case 'unreadAntennaNote':
client = await swos.openAntenna(data.body.antenna.id, loginId);
break;
+ case 'newChatMessage':
+ client = await swos.openChat(data.body, loginId);
+ break;
default:
switch (action) {
case 'markAllAsRead':
diff --git a/packages/sw/src/types.ts b/packages/sw/src/types.ts
index 4f82779808..549220396c 100644
--- a/packages/sw/src/types.ts
+++ b/packages/sw/src/types.ts
@@ -23,6 +23,7 @@ type PushNotificationDataSourceMap = {
note: Misskey.entities.Note;
};
readAllNotifications: undefined;
+ newChatMessage: Misskey.entities.ChatMessage;
};
export type PushNotificationData<K extends keyof PushNotificationDataSourceMap> = {