From 96c34c83a71314da7c9c61e7db236bfeedf7caa1 Mon Sep 17 00:00:00 2001 From: Zaprit Date: Sat, 11 Feb 2023 22:30:27 +0000 Subject: [PATCH] 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 --- .../Controllers/CommentController.cs | 19 ++++++++++--------- .../Pages/SlotPage.cshtml.cs | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index c7bd5e52..4484a0d6 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -71,16 +71,17 @@ public class CommentController : ControllerBase if (targetId == 0) return this.NotFound(); - List blockedUsers = await ( - from blockedProfile in this.database.BlockedProfiles - where blockedProfile.UserId == token.UserId - select blockedProfile.BlockedUserId - ).ToListAsync(); - + List blockedUsers = await ( + from blockedProfile in this.database.BlockedProfiles + where blockedProfile.UserId == token.UserId + select blockedProfile.BlockedUserId).ToListAsync(); + List comments = await this.database.Comments.Include(c => c.Poster) - .Where(c => c.TargetId == targetId && c.Type == type && !c.Poster.IsBanned) - .Where(c => !blockedUsers.Contains(c.PosterUserId)) - .OrderByDescending(c => c.Timestamp) + .OrderByDescending(p => p.Timestamp) + .Where(p => p.TargetId == targetId && p.Type == type) + .ToAsyncEnumerable() + .Where(p => !p.Poster.IsBanned) + .Where(p => !blockedUsers.Contains(p.PosterUserId)) .Skip(Math.Max(0, pageStart - 1)) .Take(Math.Min(pageSize, 30)) .ToListAsync(); diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs index b3f8ef70..f312ee48 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs @@ -60,12 +60,20 @@ public class SlotPage : BaseLayout this.Slot = slot; + List blockedUsers = this.User == null + ? new List() + : 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; if (this.CommentsEnabled) { this.Comments = await this.Database.Comments.Include(p => p.Poster) .OrderByDescending(p => p.Timestamp) .Where(c => c.TargetId == id && c.Type == CommentType.Level) + .Where(c => !blockedUsers.Contains(c.PosterUserId)) .Take(50) .ToListAsync(); } @@ -80,6 +88,7 @@ public class SlotPage : BaseLayout .OrderByDescending(r => r.ThumbsUp - r.ThumbsDown) .ThenByDescending(r => r.Timestamp) .Where(r => r.SlotId == id) + .Where(r => !blockedUsers.Contains(r.ReviewerId)) .Take(50) .ToListAsync(); }