diff --git a/GanjooRazor/Pages/GanjoorPage.cshtml b/GanjooRazor/Pages/GanjoorPage.cshtml index a178d900..cf1e9e1d 100644 --- a/GanjooRazor/Pages/GanjoorPage.cshtml +++ b/GanjooRazor/Pages/GanjoorPage.cshtml @@ -34,6 +34,8 @@ btshmr(@Model.GanjoorPage.Id); } checkIfBookmarked(@Model.GanjoorPage.Id); + paginateComments(); + revealCommentFromUrlHash(); }); } diff --git a/GanjooRazor/Pages/GanjoorPage.cshtml.cs b/GanjooRazor/Pages/GanjoorPage.cshtml.cs index a0fdfafe..97421d90 100644 --- a/GanjooRazor/Pages/GanjoorPage.cshtml.cs +++ b/GanjooRazor/Pages/GanjoorPage.cshtml.cs @@ -130,6 +130,67 @@ namespace GanjooRazor.Pages }; } + /// + /// re-fetch a poem's comments sorted by rating or by date (AJAX, called from sortComments() in bk.js) + /// + public async Task OnGetCommentsPartialAsync(int poemId, bool sortByRanking = true) + { + var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/comments?sortByRanking={sortByRanking}"); + if (!response.IsSuccessStatusCode) + { + return BadRequest(await ReadErrorMessageAsync(response)); + } + var comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject(); + + LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]); + + if (!string.IsNullOrEmpty(Request.Cookies["UserId"]) + && Guid.TryParse(Request.Cookies["UserId"], out Guid userId) + && userId != Guid.Empty) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + GanjoorUserBookmarkViewModel[] bookmarks = Array.Empty(); + HttpResponseMessage bookmarksResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/bookmark/{poemId}"); + if (bookmarksResponse.IsSuccessStatusCode) + { + bookmarks = JsonConvert.DeserializeObject(await bookmarksResponse.Content.ReadAsStringAsync()); + } + + foreach (GanjoorCommentSummaryViewModel comment in comments) + { + comment.MyComment = comment.UserId == userId; + comment.IsBookmarked = bookmarks.Where(b => b.CoupletIndex == -comment.Id).Any(); + _markMyReplies(comment, userId, bookmarks); + } + + HttpResponseMessage ratingsResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/comments/myratings"); + if (ratingsResponse.IsSuccessStatusCode) + { + var ratings = JsonConvert.DeserializeObject(await ratingsResponse.Content.ReadAsStringAsync()); + if (ratings.Length > 0) + { + var ratingsDic = ratings.ToDictionary(r => r.CommentId, r => r.Value); + foreach (GanjoorCommentSummaryViewModel comment in comments) + { + _applyCommentRatings(comment, ratingsDic); + } + } + } + } + } + } + + return Partial("~/Pages/Partials/GanjoorPage/_CommentsListPartial.cshtml", new _CommentsListPartialModel() + { + Comments = comments, + PoemId = poemId, + LoggedIn = LoggedIn, + }); + } + public Task OnPostReply(string replyCommentText, int refPoemId, int refCommentId) { return OnPostComment(replyCommentText, refPoemId, refCommentId, -1); diff --git a/GanjooRazor/Pages/Map.cshtml b/GanjooRazor/Pages/Map.cshtml index 66dd1fc5..91d0e4f7 100644 --- a/GanjooRazor/Pages/Map.cshtml +++ b/GanjooRazor/Pages/Map.cshtml @@ -23,7 +23,7 @@ font-family: 'Vazirmatn' } - + diff --git a/GanjooRazor/Pages/Misc/Photos.cshtml b/GanjooRazor/Pages/Misc/Photos.cshtml index 56c69f1e..bd0b31c3 100644 --- a/GanjooRazor/Pages/Misc/Photos.cshtml +++ b/GanjooRazor/Pages/Misc/Photos.cshtml @@ -15,7 +15,7 @@ - + - + diff --git a/GanjooRazor/Pages/Recitations/ReportRecitation.cshtml b/GanjooRazor/Pages/Recitations/ReportRecitation.cshtml index 3fc51aca..65cb167d 100644 --- a/GanjooRazor/Pages/Recitations/ReportRecitation.cshtml +++ b/GanjooRazor/Pages/Recitations/ReportRecitation.cshtml @@ -238,7 +238,7 @@ - + diff --git a/GanjooRazor/Pages/Shared/_AdminLayout.cshtml b/GanjooRazor/Pages/Shared/_AdminLayout.cshtml index c3c01f62..6afeeae3 100644 --- a/GanjooRazor/Pages/Shared/_AdminLayout.cshtml +++ b/GanjooRazor/Pages/Shared/_AdminLayout.cshtml @@ -35,7 +35,7 @@ }); - + - + - +