From 0ae98b4a0711a1f60f64b6f43fe56ce6a8ba0bbc Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 4 Sep 2021 21:20:47 +0900 Subject: [PATCH] fix read-notification.ts --- src/server/api/common/read-notification.ts | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts index f4fb4d5744..3270662908 100644 --- a/src/server/api/common/read-notification.ts +++ b/src/server/api/common/read-notification.ts @@ -17,7 +17,8 @@ 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( @@ -33,18 +34,15 @@ export async function readNotificationByQuery( isRead: true }); - post(userId); + if (!await Users.getHasUnreadNotification(userId)) return postReadAllNotifications(userId); } -async function post(userId: User['id']) { - if (!await Users.getHasUnreadNotification(userId)) { - // ユーザーのすべての通知が既読だったら、 - // 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行 - publishMainStream(userId, 'readAllNotifications'); - pushNotification(userId, 'readAllNotifications', undefined); - } else { - // まだすべて既読になっていなければ、各クライアントにnotificationIdsを伝達 - publishMainStream(userId, 'readNotifications', notificationIds); - pushNotification(userId, 'readNotifications', { notificationIds }); - } +function postReadAllNotifications(userId: User['id']) { + publishMainStream(userId, 'readAllNotifications'); + return pushNotification(userId, 'readAllNotifications', undefined); +} + +function postReadNotifications(userId: User['id'], notificationIds: Notification['id'][]) { + publishMainStream(userId, 'readNotifications', notificationIds); + return pushNotification(userId, 'readNotifications', { notificationIds }); }