Feature/user blocking hotfix 1 (#668)

* Changed CommentController to use an AsyncEnumerable to attempt to fix the current issue

* Made comments & reviews from blocked users on levels not appear
This commit is contained in:
Zaprit 2023-02-11 22:30:27 +00:00 committed by GitHub
parent 3fcfaaf5cc
commit 96c34c83a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View file

@ -74,13 +74,14 @@ public class CommentController : ControllerBase
List<int> blockedUsers = await ( List<int> blockedUsers = await (
from blockedProfile in this.database.BlockedProfiles from blockedProfile in this.database.BlockedProfiles
where blockedProfile.UserId == token.UserId where blockedProfile.UserId == token.UserId
select blockedProfile.BlockedUserId select blockedProfile.BlockedUserId).ToListAsync();
).ToListAsync();
List<Comment> comments = await this.database.Comments.Include(c => c.Poster) List<Comment> comments = await this.database.Comments.Include(c => c.Poster)
.Where(c => c.TargetId == targetId && c.Type == type && !c.Poster.IsBanned) .OrderByDescending(p => p.Timestamp)
.Where(c => !blockedUsers.Contains(c.PosterUserId)) .Where(p => p.TargetId == targetId && p.Type == type)
.OrderByDescending(c => c.Timestamp) .ToAsyncEnumerable()
.Where(p => !p.Poster.IsBanned)
.Where(p => !blockedUsers.Contains(p.PosterUserId))
.Skip(Math.Max(0, pageStart - 1)) .Skip(Math.Max(0, pageStart - 1))
.Take(Math.Min(pageSize, 30)) .Take(Math.Min(pageSize, 30))
.ToListAsync(); .ToListAsync();

View file

@ -60,12 +60,20 @@ public class SlotPage : BaseLayout
this.Slot = slot; this.Slot = slot;
List<int> blockedUsers = this.User == null
? new List<int>()
: await (
from blockedProfile in this.Database.BlockedProfiles
where blockedProfile.UserId == this.User.UserId
select blockedProfile.BlockedUserId).ToListAsync();
this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && this.Slot.CommentsEnabled; this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && this.Slot.CommentsEnabled;
if (this.CommentsEnabled) if (this.CommentsEnabled)
{ {
this.Comments = await this.Database.Comments.Include(p => p.Poster) this.Comments = await this.Database.Comments.Include(p => p.Poster)
.OrderByDescending(p => p.Timestamp) .OrderByDescending(p => p.Timestamp)
.Where(c => c.TargetId == id && c.Type == CommentType.Level) .Where(c => c.TargetId == id && c.Type == CommentType.Level)
.Where(c => !blockedUsers.Contains(c.PosterUserId))
.Take(50) .Take(50)
.ToListAsync(); .ToListAsync();
} }
@ -80,6 +88,7 @@ public class SlotPage : BaseLayout
.OrderByDescending(r => r.ThumbsUp - r.ThumbsDown) .OrderByDescending(r => r.ThumbsUp - r.ThumbsDown)
.ThenByDescending(r => r.Timestamp) .ThenByDescending(r => r.Timestamp)
.Where(r => r.SlotId == id) .Where(r => r.SlotId == id)
.Where(r => !blockedUsers.Contains(r.ReviewerId))
.Take(50) .Take(50)
.ToListAsync(); .ToListAsync();
} }