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.ts35
1 files changed, 33 insertions, 2 deletions
diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts
index ad7be83e5b..68ad92f396 100644
--- a/packages/backend/src/core/NotificationService.ts
+++ b/packages/backend/src/core/NotificationService.ts
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
@@ -20,6 +20,7 @@ import { CacheService } from '@/core/CacheService.js';
import type { Config } from '@/config.js';
import { UserListService } from '@/core/UserListService.js';
import type { FilterUnionByProperty } from '@/types.js';
+import { trackPromise } from '@/misc/promise-tracker.js';
@Injectable()
export class NotificationService implements OnApplicationShutdown {
@@ -74,7 +75,18 @@ export class NotificationService implements OnApplicationShutdown {
}
@bindThis
- public async createNotification<T extends MiNotification['type']>(
+ public createNotification<T extends MiNotification['type']>(
+ notifieeId: MiUser['id'],
+ type: T,
+ data: Omit<FilterUnionByProperty<MiNotification, 'type', T>, 'type' | 'id' | 'createdAt' | 'notifierId'>,
+ notifierId?: MiUser['id'] | null,
+ ) {
+ trackPromise(
+ this.#createNotificationInternal(notifieeId, type, data, notifierId),
+ );
+ }
+
+ async #createNotificationInternal<T extends MiNotification['type']>(
notifieeId: MiUser['id'],
type: T,
data: Omit<FilterUnionByProperty<MiNotification, 'type', T>, 'type' | 'id' | 'createdAt' | 'notifierId'>,
@@ -114,6 +126,14 @@ export class NotificationService implements OnApplicationShutdown {
this.cacheService.userFollowingsCache.fetch(notifieeId).then(followings => Object.hasOwn(followings, notifierId)),
this.cacheService.userFollowingsCache.fetch(notifierId).then(followings => Object.hasOwn(followings, notifieeId)),
]);
+ if (!(isFollowing && isFollower)) {
+ return null;
+ }
+ } else if (recieveConfig?.type === 'followingOrFollower') {
+ const [isFollowing, isFollower] = await Promise.all([
+ this.cacheService.userFollowingsCache.fetch(notifieeId).then(followings => Object.hasOwn(followings, notifierId)),
+ this.cacheService.userFollowingsCache.fetch(notifierId).then(followings => Object.hasOwn(followings, notifieeId)),
+ ]);
if (!isFollowing && !isFollower) {
return null;
}
@@ -143,6 +163,8 @@ export class NotificationService implements OnApplicationShutdown {
const packed = await this.notificationEntityService.pack(notification, notifieeId, {});
+ if (packed == null) return null;
+
// Publish notification event
this.globalEventService.publishMainStream(notifieeId, 'notification', packed);
@@ -193,6 +215,15 @@ export class NotificationService implements OnApplicationShutdown {
}
@bindThis
+ public async flushAllNotifications(userId: MiUser['id']) {
+ await Promise.all([
+ this.redisClient.del(`notificationTimeline:${userId}`),
+ this.redisClient.del(`latestReadNotification:${userId}`),
+ ]);
+ this.globalEventService.publishMainStream(userId, 'notificationFlushed');
+ }
+
+ @bindThis
public dispose(): void {
this.#shutdownController.abort();
}