summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/common/read-notification.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-06-11 19:31:03 +0900
committerGitHub <noreply@github.com>2022-06-11 19:31:03 +0900
commit182a1bf653ecfbcf76e4530b3077c6252b0d4827 (patch)
tree45d1472747d4cac017e96616f844292f5785ccdd /packages/backend/src/server/api/common/read-notification.ts
parent12.110.1 (diff)
parent12.111.0 (diff)
downloadsharkey-182a1bf653ecfbcf76e4530b3077c6252b0d4827.tar.gz
sharkey-182a1bf653ecfbcf76e4530b3077c6252b0d4827.tar.bz2
sharkey-182a1bf653ecfbcf76e4530b3077c6252b0d4827.zip
Merge pull request #8783 from misskey-dev/develop
Release: 12.111.0
Diffstat (limited to 'packages/backend/src/server/api/common/read-notification.ts')
-rw-r--r--packages/backend/src/server/api/common/read-notification.ts26
1 files changed, 14 insertions, 12 deletions
diff --git a/packages/backend/src/server/api/common/read-notification.ts b/packages/backend/src/server/api/common/read-notification.ts
index 1f575042a0..0dad35bcc2 100644
--- a/packages/backend/src/server/api/common/read-notification.ts
+++ b/packages/backend/src/server/api/common/read-notification.ts
@@ -1,4 +1,5 @@
import { publishMainStream } from '@/services/stream.js';
+import { pushNotification } from '@/services/push-notification.js';
import { User } from '@/models/entities/user.js';
import { Notification } from '@/models/entities/notification.js';
import { Notifications, Users } from '@/models/index.js';
@@ -16,28 +17,29 @@ export async function readNotification(
isRead: true,
});
- post(userId);
+ if (!await Users.getHasUnreadNotification(userId)) return postReadAllNotifications(userId);
+ else return postReadNotifications(userId, notificationIds);
}
export async function readNotificationByQuery(
userId: User['id'],
query: Record<string, any>
) {
- // Update documents
- await Notifications.update({
+ const notificationIds = await Notifications.find({
...query,
notifieeId: userId,
isRead: false,
- }, {
- isRead: true,
- });
+ }).then(notifications => notifications.map(notification => notification.id));
+
+ return readNotification(userId, notificationIds);
+}
- post(userId);
+function postReadAllNotifications(userId: User['id']) {
+ publishMainStream(userId, 'readAllNotifications');
+ return pushNotification(userId, 'readAllNotifications', undefined);
}
-async function post(userId: User['id']) {
- if (!await Users.getHasUnreadNotification(userId)) {
- // 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
- publishMainStream(userId, 'readAllNotifications');
- }
+function postReadNotifications(userId: User['id'], notificationIds: Notification['id'][]) {
+ publishMainStream(userId, 'readNotifications', notificationIds);
+ return pushNotification(userId, 'readNotifications', { notificationIds });
}