This commit is contained in:
tamaina
2021-02-10 01:54:07 +09:00
parent c44a29ebb7
commit f95ca164d6
11 changed files with 259 additions and 176 deletions

View File

@@ -1,4 +1,5 @@
import { publishMainStream } from '../../../services/stream';
import { pushNotification } from '../../../services/push-notification';
import { User } from '../../../models/entities/user';
import { Notification } from '../../../models/entities/notification';
import { Notifications, Users } from '../../../models';
@@ -12,7 +13,7 @@ export async function readNotification(
notificationIds: Notification['id'][]
) {
// Update documents
const updatedNotificatons = await Notifications.update({
await Notifications.update({
id: In(notificationIds),
isRead: false
}, {
@@ -23,10 +24,10 @@ export async function readNotification(
// ユーザーのすべての通知が既読だったら、
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
publishMainStream(userId, 'readAllNotifications');
pushNotification(userId, 'readAllNotifications', undefined);
} else {
// まだすべて既読になっていなければ、
// アップデートしたという
const updatedNotificationsIds = updatedNotificatons.generatedMaps.map(e => e.id);
publishMainStream(userId, 'readNotifications', updatedNotificationsIds);
// まだすべて既読になっていなければ、各クライアントにnotificationIdsを伝達
publishMainStream(userId, 'readNotifications', notificationIds);
pushNotification(userId, 'readNotifications', { notificationIds });
}
}