fix read-notification.ts
This commit is contained in:
parent
42d82ab379
commit
0ae98b4a07
1 changed files with 11 additions and 13 deletions
|
@ -17,7 +17,8 @@ export async function readNotification(
|
||||||
isRead: true
|
isRead: true
|
||||||
});
|
});
|
||||||
|
|
||||||
post(userId);
|
if (!await Users.getHasUnreadNotification(userId)) return postReadAllNotifications(userId);
|
||||||
|
else return postReadNotifications(userId, notificationIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function readNotificationByQuery(
|
export async function readNotificationByQuery(
|
||||||
|
@ -33,18 +34,15 @@ export async function readNotificationByQuery(
|
||||||
isRead: true
|
isRead: true
|
||||||
});
|
});
|
||||||
|
|
||||||
post(userId);
|
if (!await Users.getHasUnreadNotification(userId)) return postReadAllNotifications(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function post(userId: User['id']) {
|
function postReadAllNotifications(userId: User['id']) {
|
||||||
if (!await Users.getHasUnreadNotification(userId)) {
|
|
||||||
// ユーザーのすべての通知が既読だったら、
|
|
||||||
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
|
|
||||||
publishMainStream(userId, 'readAllNotifications');
|
publishMainStream(userId, 'readAllNotifications');
|
||||||
pushNotification(userId, 'readAllNotifications', undefined);
|
return pushNotification(userId, 'readAllNotifications', undefined);
|
||||||
} else {
|
}
|
||||||
// まだすべて既読になっていなければ、各クライアントにnotificationIdsを伝達
|
|
||||||
|
function postReadNotifications(userId: User['id'], notificationIds: Notification['id'][]) {
|
||||||
publishMainStream(userId, 'readNotifications', notificationIds);
|
publishMainStream(userId, 'readNotifications', notificationIds);
|
||||||
pushNotification(userId, 'readNotifications', { notificationIds });
|
return pushNotification(userId, 'readNotifications', { notificationIds });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue