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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const blockings = await this.cacheService.userBlockingCache.fetch(notifieeId);
|
||||||
|
if (blockings.has(notifierId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (recieveConfig?.type === 'following') {
|
if (recieveConfig?.type === 'following') {
|
||||||
const isFollowing = await this.cacheService.userFollowingsCache.fetch(notifieeId).then(followings => Object.hasOwn(followings, notifierId));
|
const isFollowing = await this.cacheService.userFollowingsCache.fetch(notifieeId).then(followings => Object.hasOwn(followings, notifierId));
|
||||||
if (!isFollowing) {
|
if (!isFollowing) {
|
||||||
|
|
|
@ -270,11 +270,13 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
#validateNotifier <T extends MiNotification | MiGroupedNotification> (
|
#validateNotifier <T extends MiNotification | MiGroupedNotification> (
|
||||||
notification: T,
|
notification: T,
|
||||||
userIdsWhoMeMutingWithNotification: Set<MiUser['id']>,
|
userIdsWhoMeMutingWithNotification: Set<MiUser['id']>,
|
||||||
|
userIdsWhoMeBlocking: Set<MiUser['id']>,
|
||||||
userMutedInstances: Set<string>,
|
userMutedInstances: Set<string>,
|
||||||
notifiers: MiUser[],
|
notifiers: MiUser[],
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!('notifierId' in notification)) return true;
|
if (!('notifierId' in notification)) return true;
|
||||||
if (userIdsWhoMeMutingWithNotification.has(notification.notifierId)) return false;
|
if (userIdsWhoMeMutingWithNotification.has(notification.notifierId)) return false;
|
||||||
|
if (userIdsWhoMeBlocking.has(notification.notifierId)) return false;
|
||||||
|
|
||||||
const notifier = notifiers.find(x => x.id === notification.notifierId) ?? null;
|
const notifier = notifiers.find(x => x.id === notification.notifierId) ?? null;
|
||||||
|
|
||||||
|
@ -304,9 +306,11 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
): Promise<T[]> {
|
): Promise<T[]> {
|
||||||
const [
|
const [
|
||||||
userIdsWhoMeMutingWithNotification,
|
userIdsWhoMeMutingWithNotification,
|
||||||
|
userIdsWhoMeBlocking,
|
||||||
userMutedInstances,
|
userMutedInstances,
|
||||||
] = (await Promise.allSettled([
|
] = (await Promise.allSettled([
|
||||||
this.cacheService.userMutingsWithNotificationCache.fetch(meId),
|
this.cacheService.userMutingsWithNotificationCache.fetch(meId),
|
||||||
|
this.cacheService.userBlockingCache.fetch(meId),
|
||||||
this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)),
|
this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)),
|
||||||
])).map(result => result.status === 'fulfilled' ? result.value : new Set<string>());
|
])).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) => {
|
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;
|
return isValid ? notification : null;
|
||||||
}))).filter(result => result.status === 'fulfilled' && isNotNull(result.value))
|
}))).filter(result => result.status === 'fulfilled' && isNotNull(result.value))
|
||||||
.map(result => (result as PromiseFulfilledResult<T>).value));
|
.map(result => (result as PromiseFulfilledResult<T>).value));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue