summaryrefslogtreecommitdiff
path: root/src/services/create-notification.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-13 12:23:49 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-13 12:23:49 +0900
commit2795fe457909c687f668d020ef65d52abc3182fb (patch)
tree0a52e4e4d854333496fcc487560c93c3de5d5eb5 /src/services/create-notification.ts
parentMerge branch 'develop' (diff)
parent12.96.0 (diff)
downloadmisskey-2795fe457909c687f668d020ef65d52abc3182fb.tar.gz
misskey-2795fe457909c687f668d020ef65d52abc3182fb.tar.bz2
misskey-2795fe457909c687f668d020ef65d52abc3182fb.zip
Merge branch 'develop'
Diffstat (limited to 'src/services/create-notification.ts')
-rw-r--r--src/services/create-notification.ts61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/services/create-notification.ts b/src/services/create-notification.ts
deleted file mode 100644
index 5398d486c0..0000000000
--- a/src/services/create-notification.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import { publishMainStream } from '@/services/stream';
-import pushSw from './push-notification';
-import { Notifications, Mutings, UserProfiles, Users } from '@/models/index';
-import { genId } from '@/misc/gen-id';
-import { User } from '@/models/entities/user';
-import { Notification } from '@/models/entities/notification';
-import { sendEmailNotification } from './send-email-notification';
-
-export async function createNotification(
- notifieeId: User['id'],
- type: Notification['type'],
- data: Partial<Notification>
-) {
- if (data.notifierId && (notifieeId === data.notifierId)) {
- return null;
- }
-
- const profile = await UserProfiles.findOne({ userId: notifieeId });
-
- const isMuted = profile?.mutingNotificationTypes.includes(type);
-
- // Create notification
- const notification = await Notifications.save({
- id: genId(),
- createdAt: new Date(),
- notifieeId: notifieeId,
- type: type,
- // 相手がこの通知をミュートしているようなら、既読を予めつけておく
- isRead: isMuted,
- ...data
- } as Partial<Notification>);
-
- const packed = await Notifications.pack(notification, {});
-
- // Publish notification event
- publishMainStream(notifieeId, 'notification', packed);
-
- // 2秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
- setTimeout(async () => {
- const fresh = await Notifications.findOne(notification.id);
- if (fresh == null) return; // 既に削除されているかもしれない
- if (fresh.isRead) return;
-
- //#region ただしミュートしているユーザーからの通知なら無視
- const mutings = await Mutings.find({
- muterId: notifieeId
- });
- if (data.notifierId && mutings.map(m => m.muteeId).includes(data.notifierId)) {
- return;
- }
- //#endregion
-
- publishMainStream(notifieeId, 'unreadNotification', packed);
-
- pushSw(notifieeId, 'notification', packed);
- if (type === 'follow') sendEmailNotification.follow(notifieeId, await Users.findOneOrFail(data.notifierId!));
- if (type === 'receiveFollowRequest') sendEmailNotification.receiveFollowRequest(notifieeId, await Users.findOneOrFail(data.notifierId!));
- }, 2000);
-
- return notification;
-}