From 90f8fe7e538bb7e52d2558152a0390e693f39b11 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Thu, 29 Mar 2018 01:20:40 +0900 Subject: Introduce processor --- src/api/common/notify.ts | 50 ------------------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 src/api/common/notify.ts (limited to 'src/api/common/notify.ts') diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts deleted file mode 100644 index ae5669b84c..0000000000 --- a/src/api/common/notify.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as mongo from 'mongodb'; -import Notification from '../models/notification'; -import Mute from '../models/mute'; -import event from '../event'; -import { pack } from '../models/notification'; - -export default ( - notifiee: mongo.ObjectID, - notifier: mongo.ObjectID, - type: string, - content?: any -) => new Promise(async (resolve, reject) => { - if (notifiee.equals(notifier)) { - return resolve(); - } - - // Create notification - const notification = await Notification.insert(Object.assign({ - created_at: new Date(), - notifiee_id: notifiee, - notifier_id: notifier, - type: type, - is_read: false - }, content)); - - resolve(notification); - - // Publish notification event - event(notifiee, 'notification', - await pack(notification)); - - // 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する - setTimeout(async () => { - const fresh = await Notification.findOne({ _id: notification._id }, { is_read: true }); - if (!fresh.is_read) { - //#region ただしミュートしているユーザーからの通知なら無視 - const mute = await Mute.find({ - muter_id: notifiee, - deleted_at: { $exists: false } - }); - const mutedUserIds = mute.map(m => m.mutee_id.toString()); - if (mutedUserIds.indexOf(notifier.toString()) != -1) { - return; - } - //#endregion - - event(notifiee, 'unread_notification', await pack(notification)); - } - }, 3000); -}); -- cgit v1.2.3-freya