[backend/core] Fix note thread mute handling inconsistencies
This commit is contained in:
parent
c556d6b701
commit
3132b6b8c9
4 changed files with 13 additions and 10 deletions
|
@ -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<NotificationRenderer>();
|
||||
|
||||
|
|
|
@ -366,10 +366,10 @@ public sealed class WebSocketConnection(
|
|||
(IsFiltered(note.Renote.Renote.User) ||
|
||||
IsFilteredMentions(note.Renote.Renote.Mentions)));
|
||||
|
||||
public async Task<bool> IsMutedThread(Note note, AsyncServiceScope scope)
|
||||
public async Task<bool> 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<DatabaseContext>();
|
||||
return await db.NoteThreadMutings.AnyAsync(p => p.UserId == Token.UserId && p.ThreadId == note.ThreadId);
|
||||
}
|
||||
|
|
|
@ -353,7 +353,8 @@ public static class QueryableExtensions
|
|||
|
||||
public static IQueryable<Note> FilterMutedThreads(this IQueryable<Note> 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<Notification> FilterMutedThreads(
|
||||
|
|
|
@ -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<NotificationRenderer>();
|
||||
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<bool> IsMutedThread(Note note, AsyncServiceScope scope)
|
||||
private async Task<bool> 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<DatabaseContext>();
|
||||
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")]
|
||||
|
|
Loading…
Add table
Reference in a new issue