From 4007f93cc4e77ab13c494ccca312fcef590f8462 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 4 Aug 2026 18:32:26 +0330 Subject: [PATCH] #495 comment ratings --- GanjooRazor/Pages/GanjoorPage.cshtml.cs | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/GanjooRazor/Pages/GanjoorPage.cshtml.cs b/GanjooRazor/Pages/GanjoorPage.cshtml.cs index 018cfbb7..a0fdfafe 100644 --- a/GanjooRazor/Pages/GanjoorPage.cshtml.cs +++ b/GanjooRazor/Pages/GanjoorPage.cshtml.cs @@ -328,6 +328,41 @@ namespace GanjooRazor.Pages } } } + + if (GanjoorPage.Poem.Comments.Length > 0) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorPage.Poem.Id}/comments/myratings"); + if (response.IsSuccessStatusCode) + { + var ratings = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + if (ratings.Length > 0) + { + var ratingsDic = ratings.ToDictionary(r => r.CommentId, r => r.Value); + foreach (GanjoorCommentSummaryViewModel comment in GanjoorPage.Poem.Comments) + { + _applyCommentRatings(comment, ratingsDic); + } + } + } + } + } + } + } + + private void _applyCommentRatings(GanjoorCommentSummaryViewModel comment, Dictionary ratings) + { + if (ratings.TryGetValue(comment.Id, out short value)) + { + comment.CurrentUserRatingValue = value; + } + foreach (var reply in comment.Replies) + { + _applyCommentRatings(reply, ratings); + } } private void _markMyReplies(GanjoorCommentSummaryViewModel parent, Guid userId, GanjoorUserBookmarkViewModel[] bookmarks) @@ -905,6 +940,20 @@ namespace GanjooRazor.Pages comment.IsBookmarked = bookmarks.Where(b => b.CoupletIndex == -comment.Id).Any(); _markMyReplies(comment, userId, bookmarks); } + + HttpResponseMessage responseRatings = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/comments/myratings"); + if (responseRatings.IsSuccessStatusCode) + { + var ratings = JsonConvert.DeserializeObject(await responseRatings.Content.ReadAsStringAsync()); + if (ratings.Length > 0) + { + var ratingsDic = ratings.ToDictionary(r => r.CommentId, r => r.Value); + foreach (GanjoorCommentSummaryViewModel comment in comments) + { + _applyCommentRatings(comment, ratingsDic); + } + } + } } } }