From 3132b6b8c9209eaff0b70e9e13d80ae18135f50b Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 13 Aug 2024 03:11:09 +0200 Subject: [PATCH] [backend/core] Fix note thread mute handling inconsistencies --- .../Mastodon/Streaming/Channels/UserChannel.cs | 3 ++- .../Mastodon/Streaming/WebSocketConnection.cs | 6 +++--- .../Core/Extensions/QueryableExtensions.cs | 3 ++- .../SignalR/Helpers/StreamingConnectionAggregate.cs | 11 ++++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Streaming/Channels/UserChannel.cs b/Iceshrimp.Backend/Controllers/Mastodon/Streaming/Channels/UserChannel.cs index 6854cba1..bf7449e0 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Streaming/Channels/UserChannel.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Streaming/Channels/UserChannel.cs @@ -175,7 +175,8 @@ public class UserChannel(WebSocketConnection connection, bool notificationsOnly) if (IsFiltered(notification)) return; await using var scope = connection.ScopeFactory.CreateAsyncScope(); - if (notification.Note != null && await connection.IsMutedThread(notification.Note, scope)) return; + if (notification.Note != null && await connection.IsMutedThread(notification.Note, scope, true)) + return; var renderer = scope.ServiceProvider.GetRequiredService(); diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Streaming/WebSocketConnection.cs b/Iceshrimp.Backend/Controllers/Mastodon/Streaming/WebSocketConnection.cs index f9cd9f7b..cd945dff 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Streaming/WebSocketConnection.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Streaming/WebSocketConnection.cs @@ -366,10 +366,10 @@ public sealed class WebSocketConnection( (IsFiltered(note.Renote.Renote.User) || IsFilteredMentions(note.Renote.Renote.Mentions))); - public async Task IsMutedThread(Note note, AsyncServiceScope scope) + public async Task IsMutedThread(Note note, AsyncServiceScope scope, bool isNotification = false) { - if (note.Reply == null) return false; - if (note.User.Id == Token.UserId) return false; + if (!isNotification && note.Reply == null) return false; + if (!isNotification && note.User.Id == Token.UserId) return false; var db = scope.ServiceProvider.GetRequiredService(); return await db.NoteThreadMutings.AnyAsync(p => p.UserId == Token.UserId && p.ThreadId == note.ThreadId); } diff --git a/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs b/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs index 60601a9b..6fc0ab45 100644 --- a/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs @@ -353,7 +353,8 @@ public static class QueryableExtensions public static IQueryable FilterMutedThreads(this IQueryable query, User user, DatabaseContext db) { - return query.Where(p => !db.NoteThreadMutings.Any(m => m.User == user && m.ThreadId == p.ThreadIdOrId)); + return query.Where(p => p.User != user && + !db.NoteThreadMutings.Any(m => m.User == user && m.ThreadId == p.ThreadIdOrId)); } public static IQueryable FilterMutedThreads( diff --git a/Iceshrimp.Backend/SignalR/Helpers/StreamingConnectionAggregate.cs b/Iceshrimp.Backend/SignalR/Helpers/StreamingConnectionAggregate.cs index 490c115f..b52b67fd 100644 --- a/Iceshrimp.Backend/SignalR/Helpers/StreamingConnectionAggregate.cs +++ b/Iceshrimp.Backend/SignalR/Helpers/StreamingConnectionAggregate.cs @@ -73,7 +73,8 @@ public sealed class StreamingConnectionAggregate : IDisposable if (notification.Notifier != null && IsFiltered(notification.Notifier)) return; await using var scope = GetTempScope(); - if (notification.Note != null && await IsMutedThread(notification.Note, scope)) return; + if (notification.Note != null && await IsMutedThread(notification.Note, scope, true)) + return; var renderer = scope.ServiceProvider.GetRequiredService(); var rendered = await renderer.RenderOne(notification, _user); @@ -171,12 +172,12 @@ public sealed class StreamingConnectionAggregate : IDisposable return res is not { Note.IsPureRenote: true, Renote: null } ? res : null; } - private async Task IsMutedThread(Note note, AsyncServiceScope scope) + private async Task IsMutedThread(Note note, AsyncServiceScope scope, bool isNotification = false) { - if (note.Reply == null) return false; - if (note.User.Id == _userId) return false; + if (!isNotification && note.Reply == null) return false; + if (!isNotification && note.User.Id == _userId) return false; var db = scope.ServiceProvider.GetRequiredService(); - return await db.NoteThreadMutings.AnyAsync(p => p.UserId == _userId && p.ThreadId == note.ThreadId); + return await db.NoteThreadMutings.AnyAsync(p => p.UserId == _userId && p.ThreadId == note.ThreadIdOrId); } [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")]