summaryrefslogtreecommitdiff
path: root/packages/backend/src/services/create-notification.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-09-18 03:27:08 +0900
committerGitHub <noreply@github.com>2022-09-18 03:27:08 +0900
commitb75184ec8e3436200bacdcd832e3324702553d20 (patch)
tree8b7e316f29e95df921db57289c8b8da476d18f07 /packages/backend/src/services/create-notification.ts
parentUpdate ROADMAP.md (diff)
downloadsharkey-b75184ec8e3436200bacdcd832e3324702553d20.tar.gz
sharkey-b75184ec8e3436200bacdcd832e3324702553d20.tar.bz2
sharkey-b75184ec8e3436200bacdcd832e3324702553d20.zip
なんかもうめっちゃ変えた
Diffstat (limited to 'packages/backend/src/services/create-notification.ts')
-rw-r--r--packages/backend/src/services/create-notification.ts62
1 files changed, 0 insertions, 62 deletions
diff --git a/packages/backend/src/services/create-notification.ts b/packages/backend/src/services/create-notification.ts
deleted file mode 100644
index d53a4235b8..0000000000
--- a/packages/backend/src/services/create-notification.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { publishMainStream } from '@/services/stream.js';
-import { pushNotification } from '@/services/push-notification.js';
-import { Notifications, Mutings, UserProfiles, Users } from '@/models/index.js';
-import { genId } from '@/misc/gen-id.js';
-import { User } from '@/models/entities/user.js';
-import { Notification } from '@/models/entities/notification.js';
-import { sendEmailNotification } from './send-email-notification.js';
-
-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.findOneBy({ userId: notifieeId });
-
- const isMuted = profile?.mutingNotificationTypes.includes(type);
-
- // Create notification
- const notification = await Notifications.insert({
- id: genId(),
- createdAt: new Date(),
- notifieeId: notifieeId,
- type: type,
- // 相手がこの通知をミュートしているようなら、既読を予めつけておく
- isRead: isMuted,
- ...data,
- } as Partial<Notification>)
- .then(x => Notifications.findOneByOrFail(x.identifiers[0]));
-
- const packed = await Notifications.pack(notification, {});
-
- // Publish notification event
- publishMainStream(notifieeId, 'notification', packed);
-
- // 2秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
- setTimeout(async () => {
- const fresh = await Notifications.findOneBy({ id: notification.id });
- if (fresh == null) return; // 既に削除されているかもしれない
- if (fresh.isRead) return;
-
- //#region ただしミュートしているユーザーからの通知なら無視
- const mutings = await Mutings.findBy({
- muterId: notifieeId,
- });
- if (data.notifierId && mutings.map(m => m.muteeId).includes(data.notifierId)) {
- return;
- }
- //#endregion
-
- publishMainStream(notifieeId, 'unreadNotification', packed);
- pushNotification(notifieeId, 'notification', packed);
-
- if (type === 'follow') sendEmailNotification.follow(notifieeId, await Users.findOneByOrFail({ id: data.notifierId! }));
- if (type === 'receiveFollowRequest') sendEmailNotification.receiveFollowRequest(notifieeId, await Users.findOneByOrFail({ id: data.notifierId! }));
- }, 2000);
-
- return notification;
-}