[backend/streaming] Enforce notification blocks/mutes in StreamingConnectionAggregate

This commit is contained in:
Laura Hausmann 2024-05-06 23:19:56 +02:00
parent b97c21a87b
commit 32a4875162
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -124,6 +124,7 @@ public sealed class StreamingConnectionAggregate : IDisposable
try try
{ {
if (notification.NotifieeId != _userId) return; if (notification.NotifieeId != _userId) return;
if (notification.Notifier != null && IsFiltered(notification.Notifier)) return;
await using var scope = GetTempScope(); await using var scope = GetTempScope();
var renderer = scope.ServiceProvider.GetRequiredService<NotificationRenderer>(); var renderer = scope.ServiceProvider.GetRequiredService<NotificationRenderer>();
@ -199,14 +200,12 @@ public sealed class StreamingConnectionAggregate : IDisposable
} }
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")]
private bool IsFiltered(Note note) private bool IsFiltered(Note note) =>
{ IsFiltered(note.User) || _blocking.Intersects(note.Mentions) || _muting.Intersects(note.Mentions);
if (!_blockedBy.Contains(note.User.Id) &&
!_blocking.Contains(note.User.Id) &&
!_muting.Contains(note.User.Id)) return true;
return _blocking.Intersects(note.Mentions) || _muting.Intersects(note.Mentions); [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")]
} private bool IsFiltered(User user) =>
!_blockedBy.Contains(user.Id) && !_blocking.Contains(user.Id) && !_muting.Contains(user.Id);
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")]
private bool IsFollowingOrSelf(User user) => user.Id == _userId || _following.Contains(user.Id); private bool IsFollowingOrSelf(User user) => user.Id == _userId || _following.Contains(user.Id);