summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/NotificationService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core/NotificationService.ts')
-rw-r--r--packages/backend/src/core/NotificationService.ts43
1 files changed, 22 insertions, 21 deletions
diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts
index 8e25f82284..258ae44f7d 100644
--- a/packages/backend/src/core/NotificationService.ts
+++ b/packages/backend/src/core/NotificationService.ts
@@ -1,38 +1,39 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
import { setTimeout } from 'node:timers/promises';
import * as Redis from 'ioredis';
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { In } from 'typeorm';
import { DI } from '@/di-symbols.js';
-import type { MutingsRepository, UserProfile, UserProfilesRepository, UsersRepository } from '@/models/index.js';
-import type { User } from '@/models/entities/User.js';
-import type { Notification } from '@/models/entities/Notification.js';
-import { UserEntityService } from '@/core/entities/UserEntityService.js';
+import type { UsersRepository } from '@/models/_.js';
+import type { MiUser } from '@/models/User.js';
+import type { MiNotification } from '@/models/Notification.js';
import { bindThis } from '@/decorators.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import { PushNotificationService } from '@/core/PushNotificationService.js';
import { NotificationEntityService } from '@/core/entities/NotificationEntityService.js';
import { IdService } from '@/core/IdService.js';
import { CacheService } from '@/core/CacheService.js';
+import type { Config } from '@/config.js';
@Injectable()
export class NotificationService implements OnApplicationShutdown {
#shutdownController = new AbortController();
constructor(
+ @Inject(DI.config)
+ private config: Config,
+
@Inject(DI.redis)
private redisClient: Redis.Redis,
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
- @Inject(DI.userProfilesRepository)
- private userProfilesRepository: UserProfilesRepository,
-
- @Inject(DI.mutingsRepository)
- private mutingsRepository: MutingsRepository,
-
private notificationEntityService: NotificationEntityService,
- private userEntityService: UserEntityService,
private idService: IdService,
private globalEventService: GlobalEventService,
private pushNotificationService: PushNotificationService,
@@ -42,7 +43,7 @@ export class NotificationService implements OnApplicationShutdown {
@bindThis
public async readAllNotification(
- userId: User['id'],
+ userId: MiUser['id'],
force = false,
) {
const latestReadNotificationId = await this.redisClient.get(`latestReadNotification:${userId}`);
@@ -64,17 +65,17 @@ export class NotificationService implements OnApplicationShutdown {
}
@bindThis
- private postReadAllNotifications(userId: User['id']) {
+ private postReadAllNotifications(userId: MiUser['id']) {
this.globalEventService.publishMainStream(userId, 'readAllNotifications');
this.pushNotificationService.pushNotification(userId, 'readAllNotifications', undefined);
}
@bindThis
public async createNotification(
- notifieeId: User['id'],
- type: Notification['type'],
- data: Partial<Notification>,
- ): Promise<Notification | null> {
+ notifieeId: MiUser['id'],
+ type: MiNotification['type'],
+ data: Partial<MiNotification>,
+ ): Promise<MiNotification | null> {
const profile = await this.cacheService.userProfileCache.fetch(notifieeId);
const isMuted = profile.mutingNotificationTypes.includes(type);
if (isMuted) return null;
@@ -95,11 +96,11 @@ export class NotificationService implements OnApplicationShutdown {
createdAt: new Date(),
type: type,
...data,
- } as Notification;
+ } as MiNotification;
const redisIdPromise = this.redisClient.xadd(
`notificationTimeline:${notifieeId}`,
- 'MAXLEN', '~', '300',
+ 'MAXLEN', '~', this.config.perUserNotificationsMaxCount.toString(),
'*',
'data', JSON.stringify(notification));
@@ -129,7 +130,7 @@ export class NotificationService implements OnApplicationShutdown {
// TODO: locale ファイルをクライアント用とサーバー用で分けたい
@bindThis
- private async emailNotificationFollow(userId: User['id'], follower: User) {
+ private async emailNotificationFollow(userId: MiUser['id'], follower: MiUser) {
/*
const userProfile = await UserProfiles.findOneByOrFail({ userId: userId });
if (!userProfile.email || !userProfile.emailNotificationTypes.includes('follow')) return;
@@ -141,7 +142,7 @@ export class NotificationService implements OnApplicationShutdown {
}
@bindThis
- private async emailNotificationReceiveFollowRequest(userId: User['id'], follower: User) {
+ private async emailNotificationReceiveFollowRequest(userId: MiUser['id'], follower: MiUser) {
/*
const userProfile = await UserProfiles.findOneByOrFail({ userId: userId });
if (!userProfile.email || !userProfile.emailNotificationTypes.includes('receiveFollowRequest')) return;