diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2022-05-01 15:08:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-01 15:08:25 +0900 |
| commit | c5048ee9935869e793bc941fda326d83d18ebbe8 (patch) | |
| tree | 5c1df069741ecbd3548a702da683baf53d3bae5c /packages/backend/src/server/api/common/read-notification.ts | |
| parent | ressurect deepcopy (diff) | |
| parent | refactor(client): refactor import-export to use Composition API (#8579) (diff) | |
| download | sharkey-c5048ee9935869e793bc941fda326d83d18ebbe8.tar.gz sharkey-c5048ee9935869e793bc941fda326d83d18ebbe8.tar.bz2 sharkey-c5048ee9935869e793bc941fda326d83d18ebbe8.zip | |
Merge branch 'develop' into pizzax-indexeddb
Diffstat (limited to 'packages/backend/src/server/api/common/read-notification.ts')
| -rw-r--r-- | packages/backend/src/server/api/common/read-notification.ts | 26 |
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 }); } |