fix(NotificationService): remove blocked user on notifications
This commit is contained in:
parent
55d750c3e8
commit
23eeddf70b
2 changed files with 10 additions and 1 deletions
|
@ -111,6 +111,11 @@ export class NotificationService implements OnApplicationShutdown {
|
|||
return null;
|
||||
}
|
||||
|
||||
const blockings = await this.cacheService.userBlockingCache.fetch(notifieeId);
|
||||
if (blockings.has(notifierId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (recieveConfig?.type === 'following') {
|
||||
const isFollowing = await this.cacheService.userFollowingsCache.fetch(notifieeId).then(followings => Object.hasOwn(followings, notifierId));
|
||||
if (!isFollowing) {
|
||||
|
|
|
@ -270,11 +270,13 @@ export class NotificationEntityService implements OnModuleInit {
|
|||
#validateNotifier <T extends MiNotification | MiGroupedNotification> (
|
||||
notification: T,
|
||||
userIdsWhoMeMutingWithNotification: Set<MiUser['id']>,
|
||||
userIdsWhoMeBlocking: Set<MiUser['id']>,
|
||||
userMutedInstances: Set<string>,
|
||||
notifiers: MiUser[],
|
||||
): boolean {
|
||||
if (!('notifierId' in notification)) return true;
|
||||
if (userIdsWhoMeMutingWithNotification.has(notification.notifierId)) return false;
|
||||
if (userIdsWhoMeBlocking.has(notification.notifierId)) return false;
|
||||
|
||||
const notifier = notifiers.find(x => x.id === notification.notifierId) ?? null;
|
||||
|
||||
|
@ -304,9 +306,11 @@ export class NotificationEntityService implements OnModuleInit {
|
|||
): Promise<T[]> {
|
||||
const [
|
||||
userIdsWhoMeMutingWithNotification,
|
||||
userIdsWhoMeBlocking,
|
||||
userMutedInstances,
|
||||
] = (await Promise.allSettled([
|
||||
this.cacheService.userMutingsWithNotificationCache.fetch(meId),
|
||||
this.cacheService.userBlockingCache.fetch(meId),
|
||||
this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)),
|
||||
])).map(result => result.status === 'fulfilled' ? result.value : new Set<string>());
|
||||
|
||||
|
@ -316,7 +320,7 @@ export class NotificationEntityService implements OnModuleInit {
|
|||
}) : [];
|
||||
|
||||
return ((await Promise.allSettled(notifications.map(async (notification) => {
|
||||
const isValid = this.#validateNotifier(notification, userIdsWhoMeMutingWithNotification, userMutedInstances, notifiers);
|
||||
const isValid = this.#validateNotifier(notification, userIdsWhoMeMutingWithNotification, userIdsWhoMeBlocking, userMutedInstances, notifiers);
|
||||
return isValid ? notification : null;
|
||||
}))).filter(result => result.status === 'fulfilled' && isNotNull(result.value))
|
||||
.map(result => (result as PromiseFulfilledResult<T>).value));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue