//HACK ATTACK: This is short term hack. Sorry. public static void AddCommentToTree(Comment comment) { var t = new Task(() => { try { string key = CacheHandler.Keys.CommentTree(comment.MessageId.Value); //not in any way thread safe, will be jacked in high concurrency situations var c = CommentBucketViewModel.Map(comment); CacheHandler.Replace <List <usp_CommentTree_Result> >(key, new Func <List <usp_CommentTree_Result>, List <usp_CommentTree_Result> >(currentData => { usp_CommentTree_Result parent = null; if (c.ParentId != null) { parent = currentData.FirstOrDefault(x => x.Id == c.ParentId); parent.ChildCount += 1; } currentData.Add(c); return(currentData); })); } catch (Exception ex) { /*no-op*/ } }); t.Start(); }
// GET: comments for a given submission public ActionResult BucketOfComments(int? id, int? startingcommentid, int? startingpos, string sort) { const int threadsToFetch = 5; if (id == null) return View("~/Views/Errors/Error.cshtml"); var submission = _db.Messages.Find(id); if (submission == null) return View("~/Views/Errors/Error_404.cshtml"); //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(id.Value); ViewData["StartingPos"] = startingpos; if (User.Identity.IsAuthenticated) { ViewData["CCP"] = Karma.CommentKarma(User.Identity.Name); } ViewBag.SelectedSubverse = submission.Subverses.name; ViewBag.SubverseAnonymized = submission.Subverses.anonymized_mode; if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (sort != null) { ViewBag.SortingMode = sort; } // load first comments IEnumerable<Comment> firstComments; if (sort == "new") { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby f.Date descending select f; } else { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby commentScore descending select f; } if (startingpos == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); var cbvm = new CommentBucketViewModel { FirstComments = firstComments.Skip((int)startingpos * threadsToFetch).Take(threadsToFetch), Submission = submission }; if (!cbvm.FirstComments.Any()) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return PartialView("~/Views/Shared/Comments/_CommentBucket.cshtml", cbvm); }
//url: "/comments/" + submission + "/" + parentId + "/" + command + "/" + startingIndex + "/" + count + "/" + nestingLevel + "/" + sort + "/", // GET: comments for a given submission public ActionResult BucketOfComments(int submissionId, int? parentId, string command, int startingIndex, string sort) { #region Validation if (submissionId <= 0) { return View("~/Views/Errors/Error.cshtml"); } var submission = DataCache.Submission.Retrieve(submissionId); if (submission == null) { return View("~/Views/Errors/Error_404.cshtml"); } var subverse = DataCache.Subverse.Retrieve(submission.Subverse); //var subverse = _db.Subverse.Find(subversetoshow); if (subverse == null) { return View("~/Views/Errors/Error_404.cshtml"); } //HACK: Disable subverse if (subverse.admin_disabled.HasValue && subverse.admin_disabled.Value) { ViewBag.Subverse = subverse.name; return View("~/Views/Errors/SubverseDisabled.cshtml"); } #endregion ViewBag.SelectedSubverse = subverse.name; ViewBag.SubverseAnonymized = subverse.anonymized_mode; //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(submissionId); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(submissionId); ViewBag.CCP = Karma.CommentKarma(User.Identity.Name); var SortingMode = (sort == null ? "top" : sort).ToLower(); ViewBag.SortingMode = SortingMode; var commentTree = DataCache.CommentTree.Retrieve<usp_CommentTree_Result>(submission.Id, null, null); var model = new CommentBucketViewModel() { StartingIndex = startingIndex, //NestingThreshold = nestingLevel, Subverse = subverse, Submission = submission, CommentTree = commentTree, ParentID = parentId, Sort = (CommentSort)Enum.Parse(typeof(CommentSort), SortingMode, true) }; model.CollapseSiblingThreshold = 5; IQueryable<usp_CommentTree_Result> displayTree = commentTree.AsQueryable(); displayTree = displayTree.Where(x => x.ParentId == parentId); model.TotalInDisplayBranch = displayTree.Count(); //calculate offsets model.EndingIndex = Math.Min(model.StartingIndex + model.CollapseSiblingThreshold, model.TotalInDisplayBranch); if (model.Sort == CommentSort.Top){ displayTree = displayTree.OrderByDescending(x => x.Likes - x.Dislikes); } else { displayTree = displayTree.OrderByDescending(x => x.Date); } displayTree = displayTree.Skip(model.StartingIndex).Take(model.Count); model.DisplayTree = displayTree; return PartialView("~/Views/Shared/Comments/_CommentBucket.cshtml", model); }
// GET: comments for a given submission public ActionResult Comments(int? id, string subversetoshow, int? startingcommentid, string sort, int? commentToHighLight) { #region Validation if (id == null) { return View("~/Views/Errors/Error.cshtml"); } var submission = _db.Messages.Find(id.Value); if (submission == null) { return View("~/Views/Errors/Error_404.cshtml"); } // make sure that the combination of selected subverse and submission subverse are linked if (!submission.Subverse.Equals(subversetoshow, StringComparison.OrdinalIgnoreCase)) { return View("~/Views/Errors/Error_404.cshtml"); } var subverse = DataCache.Subverse.Retrieve(subversetoshow); //var subverse = _db.Subverse.Find(subversetoshow); if (subverse == null) { return View("~/Views/Errors/Error_404.cshtml"); } //HACK: Disable subverse if (subverse.admin_disabled.HasValue && subverse.admin_disabled.Value) { ViewBag.Subverse = subverse.name; return View("~/Views/Errors/SubverseDisabled.cshtml"); } #endregion ViewBag.SelectedSubverse = subverse.name; ViewBag.SubverseAnonymized = subverse.anonymized_mode; //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(id.Value); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value); ViewBag.CCP = Karma.CommentKarma(User.Identity.Name); if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (commentToHighLight != null) { ViewBag.CommentToHighLight = commentToHighLight; } var SortingMode = (sort == null ? "top" : sort).ToLower(); ViewBag.SortingMode = SortingMode; // experimental: register a new session for this subverse string clientIpAddress = String.Empty; if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) { clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } else if (Request.UserHostAddress.Length != 0) { clientIpAddress = Request.UserHostAddress; } if (clientIpAddress != String.Empty) { // generate salted hash of client IP address string ipHash = IpHash.CreateHash(clientIpAddress); var currentSubverse = (string)RouteData.Values["subversetoshow"]; // register a new session for this subverse SessionTracker.Add(currentSubverse, ipHash); // register a new view for this thread // check if this hash is present for this submission id in viewstatistics table var existingView = _db.Viewstatistics.Find(submission.Id, ipHash); // this IP has already viwed this thread, skip registering a new view if (existingView == null) { // this is a new view, register it for this submission var view = new Viewstatistic { submissionId = submission.Id, viewerId = ipHash }; _db.Viewstatistics.Add(view); submission.Views++; _db.SaveChanges(); } } var commentTree = DataCache.CommentTree.Retrieve<usp_CommentTree_Result>(submission.Id, null, null); var model = new CommentBucketViewModel() { StartingIndex = 0, EndingIndex = 5, Subverse = subverse, Submission = submission, CommentTree = commentTree, //DisplayTree = displayTree, ParentID = null, Sort = (CommentSort)Enum.Parse(typeof(CommentSort), SortingMode, true) }; IQueryable<usp_CommentTree_Result> displayTree = commentTree.AsQueryable().Where(x => x.ParentId == null); model.TotalInDisplayBranch = displayTree.Count(); if (model.Sort == CommentSort.Top) { displayTree = displayTree.OrderByDescending(x => x.Likes - x.Dislikes).Take(model.EndingIndex); } else { displayTree = displayTree.OrderByDescending(x => x.Date).Take(model.EndingIndex); } model.DisplayTree = displayTree; return View("~/Views/Home/Comments.cshtml", model); }
// GET: comments for a given submission public ActionResult BucketOfComments(int? id, int? startingcommentid, int? startingpos, string sort) { const int threadsToFetch = 5; if (id == null) return View("~/Views/Errors/Error.cshtml"); if (startingpos == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); var submission = _db.Messages.Find(id); if (submission == null) return View("~/Views/Errors/Error_404.cshtml"); //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(id.Value); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value); ViewData["StartingPos"] = startingpos; if (User.Identity.IsAuthenticated) { ViewData["CCP"] = Karma.CommentKarma(User.Identity.Name); } ViewBag.SelectedSubverse = submission.Subverses.name; ViewBag.SubverseAnonymized = submission.Subverses.anonymized_mode; if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (sort != null) { ViewBag.SortingMode = sort; } string cacheKey = String.Format("comments.bucket.{0}.{1}.{2}.{3}", id, startingcommentid, startingpos, sort); CommentBucketViewModel cbvm = CacheHandler.Retrieve<CommentBucketViewModel>(cacheKey); if (cbvm == null) { //This can not be recached cbvm = CacheHandler.Register<CommentBucketViewModel>(cacheKey, new Func<CommentBucketViewModel>(() => { // load first comments IEnumerable<Comment> firstComments; if (sort == "new") { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby f.Date descending select f; } else { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby commentScore descending select f; } var x = new CommentBucketViewModel { FirstComments = firstComments.Skip((int)startingpos * threadsToFetch).Take(threadsToFetch), Submission = submission }; return x; }), TimeSpan.FromSeconds(60)); } if (!cbvm.FirstComments.Any()) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return PartialView("~/Views/Shared/Comments/_CommentBucket.cshtml", cbvm); }
public async Task <ActionResult> SubmitComment([Bind(Include = "ID, Content, SubmissionID, ParentID")] Comment commentModel) { commentModel.CreationDate = DateTime.Now; commentModel.UserName = User.Identity.Name; commentModel.Votes = 0; commentModel.UpCount = 0; if (ModelState.IsValid) { // flag the comment as anonymized if it was submitted to a sub which has active anonymized_mode var submission = DataCache.Submission.Retrieve(commentModel.SubmissionID.Value); var subverse = DataCache.Subverse.Retrieve(submission.Subverse); commentModel.IsAnonymized = submission.IsAnonymized || subverse.IsAnonymized; // if user CCP is < 50, allow only X comment submissions per 24 hours var userCcp = Karma.CommentKarma(User.Identity.Name); if (userCcp <= -50) { var quotaUsed = UserHelper.UserDailyCommentPostingQuotaForNegativeScoreUsed(User.Identity.Name); if (quotaUsed) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "You have reached your daily comment quota. Your current quota is " + Settings.DailyCommentPostingQuotaForNegativeScore.ToString() + " comment(s) per 24 hours.")); //ModelState.AddModelError("", "You have reached your daily comment quota. Your current quota is " + Settings.DailyCommentPostingQuotaForNegativeScore + " comment(s) per 24 hours."); //return View(); } } // check if author is banned, don't save the comment or send notifications if true if (!UserHelper.IsUserGloballyBanned(User.Identity.Name) && !UserHelper.IsUserBannedFromSubverse(User.Identity.Name, submission.Subverse)) { bool containsBannedDomain = BanningUtility.ContentContainsBannedDomain(subverse.Name, commentModel.Content); if (containsBannedDomain) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Comment contains links to banned domain(s).")); } if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave)) { commentModel.Content = ContentProcessor.Instance.Process(commentModel.Content, ProcessingStage.InboundPreSave, commentModel); } //save fully formatted content var formattedComment = Formatting.FormatMessage(commentModel.Content); commentModel.FormattedContent = formattedComment; _db.Comments.Add(commentModel); await _db.SaveChangesAsync(); DataCache.CommentTree.AddCommentToTree(commentModel); if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave)) { ContentProcessor.Instance.Process(commentModel.Content, ProcessingStage.InboundPostSave, commentModel); } // send comment reply notification to parent comment author if the comment is not a new root comment await NotificationManager.SendCommentNotification(commentModel, new Action <string>(recipient => { //get count of unread notifications int unreadNotifications = UserHelper.UnreadTotalNotificationsCount(recipient); // send SignalR realtime notification to recipient var hubContext = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <MessagingHub>(); hubContext.Clients.User(recipient).setNotificationsPending(unreadNotifications); }) ); } if (Request.IsAjaxRequest()) { var comment = commentModel; ViewBag.CommentId = comment.ID; //why? ViewBag.rootComment = comment.ParentID == null; //why? if (submission.IsAnonymized || subverse.IsAnonymized) { comment.UserName = comment.ID.ToString(CultureInfo.InvariantCulture); } var model = new CommentBucketViewModel(comment); return(PartialView("~/Views/Shared/Submissions/_SubmissionComment.cshtml", model)); //return new HttpStatusCodeResult(HttpStatusCode.OK); } if (Request.UrlReferrer != null) { var url = Request.UrlReferrer.AbsolutePath; return(Redirect(url)); } } if (Request.IsAjaxRequest()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ModelState.AddModelError(String.Empty, "Sorry, you are either banned from this sub or doing that too fast. Please try again in 2 minutes."); return(View("~/Views/Help/SpeedyGonzales.cshtml")); }
// url: "/comments/" + submission + "/" + parentId + "/" + command + "/" + startingIndex + "/" + count + "/" + nestingLevel + "/" + sort + "/", // GET: comments for a given submission public ActionResult BucketOfComments(int submissionId, int?parentId, string command, int startingIndex, string sort) { #region Validation if (submissionId <= 0) { return(View("~/Views/Errors/Error.cshtml")); } var submission = DataCache.Submission.Retrieve(submissionId); if (submission == null) { return(View("~/Views/Errors/Error_404.cshtml")); } var subverse = DataCache.Subverse.Retrieve(submission.Subverse); //var subverse = _db.Subverse.Find(subversetoshow); if (subverse == null) { return(View("~/Views/Errors/Error_404.cshtml")); } //HACK: Disable subverse if (subverse.IsAdminDisabled.HasValue && subverse.IsAdminDisabled.Value) { ViewBag.Subverse = subverse.Name; return(View("~/Views/Errors/SubverseDisabled.cshtml")); } #endregion ViewBag.SelectedSubverse = subverse.Name; ViewBag.SubverseAnonymized = subverse.IsAnonymized; //Temp cache user votes for this thread ViewBag.VoteCache = UserCommentVotesBySubmission(submissionId); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(submissionId); ViewBag.CCP = Karma.CommentKarma(User.Identity.Name); var SortingMode = (sort == null ? "top" : sort).ToLower(); ViewBag.SortingMode = SortingMode; var commentTree = DataCache.CommentTree.Retrieve <usp_CommentTree_Result>(submission.ID, null, null); var model = new CommentBucketViewModel() { StartingIndex = startingIndex, //NestingThreshold = nestingLevel, Subverse = subverse, Submission = submission, CommentTree = commentTree, ParentID = parentId, Sort = (CommentSort)Enum.Parse(typeof(CommentSort), SortingMode, true) }; model.CollapseSiblingThreshold = 5; IQueryable <usp_CommentTree_Result> displayTree = commentTree.AsQueryable(); displayTree = displayTree.Where(x => x.ParentID == parentId); model.TotalInDisplayBranch = displayTree.Count(); //calculate offsets model.EndingIndex = Math.Min(model.StartingIndex + model.CollapseSiblingThreshold, model.TotalInDisplayBranch); if (model.Sort == CommentSort.Top) { displayTree = displayTree.OrderByDescending(x => x.UpCount - x.DownCount); } else { displayTree = displayTree.OrderByDescending(x => x.CreationDate); } displayTree = displayTree.Skip(model.StartingIndex).Take(model.Count); model.DisplayTree = displayTree; return(PartialView("~/Views/Shared/Comments/_CommentBucket.cshtml", model)); }
// GET: comments for a given submission public ActionResult Comments(int?id, string subversetoshow, int?startingcommentid, string sort, int?commentToHighLight) { #region Validation if (id == null) { return(View("~/Views/Errors/Error.cshtml")); } var submission = _db.Submissions.Find(id.Value); if (submission == null) { return(View("~/Views/Errors/Error_404.cshtml")); } // make sure that the combination of selected subverse and submission subverse are linked if (!submission.Subverse.Equals(subversetoshow, StringComparison.OrdinalIgnoreCase)) { return(View("~/Views/Errors/Error_404.cshtml")); } var subverse = DataCache.Subverse.Retrieve(subversetoshow); //var subverse = _db.Subverse.Find(subversetoshow); if (subverse == null) { return(View("~/Views/Errors/Error_404.cshtml")); } //HACK: Disable subverse if (subverse.IsAdminDisabled.HasValue && subverse.IsAdminDisabled.Value) { ViewBag.Subverse = subverse.Name; return(View("~/Views/Errors/SubverseDisabled.cshtml")); } #endregion ViewBag.SelectedSubverse = subverse.Name; ViewBag.SubverseAnonymized = subverse.IsAnonymized; //Temp cache user votes for this thread ViewBag.VoteCache = UserCommentVotesBySubmission(id.Value); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value); ViewBag.CCP = Karma.CommentKarma(User.Identity.Name); if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (commentToHighLight != null) { ViewBag.CommentToHighLight = commentToHighLight; } var SortingMode = (sort == null ? "top" : sort).ToLower(); ViewBag.SortingMode = SortingMode; // experimental: register a new session for this subverse string clientIpAddress = String.Empty; if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) { clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } else if (Request.UserHostAddress.Length != 0) { clientIpAddress = Request.UserHostAddress; } if (clientIpAddress != String.Empty) { // generate salted hash of client IP address string ipHash = IpHash.CreateHash(clientIpAddress); var currentSubverse = (string)RouteData.Values["subversetoshow"]; // register a new session for this subverse SessionHelper.Add(currentSubverse, ipHash); // register a new view for this thread // check if this hash is present for this submission id in viewstatistics table var existingView = _db.ViewStatistics.Find(submission.ID, ipHash); // this IP has already viwed this thread, skip registering a new view if (existingView == null) { // this is a new view, register it for this submission var view = new ViewStatistic { SubmissionID = submission.ID, ViewerID = ipHash }; _db.ViewStatistics.Add(view); submission.Views++; _db.SaveChanges(); } } var commentTree = DataCache.CommentTree.Retrieve <usp_CommentTree_Result>(submission.ID, null, null); var model = new CommentBucketViewModel() { StartingIndex = 0, EndingIndex = 5, Subverse = subverse, Submission = submission, CommentTree = commentTree, //DisplayTree = displayTree, ParentID = null, Sort = (CommentSort)Enum.Parse(typeof(CommentSort), SortingMode, true) }; IQueryable <usp_CommentTree_Result> displayTree = commentTree.AsQueryable().Where(x => x.ParentID == null); model.TotalInDisplayBranch = displayTree.Count(); if (model.Sort == CommentSort.Top) { displayTree = displayTree.OrderByDescending(x => x.UpCount - x.DownCount).Take(model.EndingIndex); } else { displayTree = displayTree.OrderByDescending(x => x.CreationDate).Take(model.EndingIndex); } model.DisplayTree = displayTree; return(View("~/Views/Home/Comments.cshtml", model)); }
// GET: comments for a given submission public ActionResult BucketOfComments(int?id, int?startingcommentid, int?startingpos, string sort) { const int threadsToFetch = 5; if (id == null) { return(View("~/Views/Errors/Error.cshtml")); } if (startingpos == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var submission = _db.Messages.Find(id); if (submission == null) { return(View("~/Views/Errors/Error_404.cshtml")); } //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(id.Value); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value); ViewData["StartingPos"] = startingpos; if (User.Identity.IsAuthenticated) { ViewData["CCP"] = Karma.CommentKarma(User.Identity.Name); } ViewBag.SelectedSubverse = submission.Subverses.name; ViewBag.SubverseAnonymized = submission.Subverses.anonymized_mode; if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (sort != null) { ViewBag.SortingMode = sort; } string cacheKey = String.Format("comments.bucket.{0}.{1}.{2}.{3}", id, startingcommentid, startingpos, sort); CommentBucketViewModel cbvm = CacheHandler.Retrieve <CommentBucketViewModel>(cacheKey); if (cbvm == null) { //This can not be recached cbvm = CacheHandler.Register <CommentBucketViewModel>(cacheKey, new Func <CommentBucketViewModel>(() => { // load first comments IEnumerable <Comment> firstComments; if (sort == "new") { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby f.Date descending select f; } else { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby commentScore descending select f; } var x = new CommentBucketViewModel { FirstComments = firstComments.Skip((int)startingpos * threadsToFetch).Take(threadsToFetch), Submission = submission }; return(x); }), TimeSpan.FromSeconds(60)); } if (!cbvm.FirstComments.Any()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(PartialView("~/Views/Shared/Comments/_CommentBucket.cshtml", cbvm)); }
// GET: comments for a given submission public ActionResult BucketOfComments(int?id, int?startingcommentid, int?startingpos, string sort) { const int threadsToFetch = 5; if (id == null) { return(View("~/Views/Errors/Error.cshtml")); } var submission = _db.Messages.Find(id); if (submission == null) { return(View("~/Views/Errors/Error_404.cshtml")); } //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(id.Value); ViewData["StartingPos"] = startingpos; if (User.Identity.IsAuthenticated) { ViewData["CCP"] = Karma.CommentKarma(User.Identity.Name); } ViewBag.SelectedSubverse = submission.Subverses.name; ViewBag.SubverseAnonymized = submission.Subverses.anonymized_mode; if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (sort != null) { ViewBag.SortingMode = sort; } // load first comments IEnumerable <Comment> firstComments; if (sort == "new") { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby f.Date descending select f; } else { firstComments = from f in submission.Comments let commentScore = f.Likes - f.Dislikes where f.ParentId == null orderby commentScore descending select f; } if (startingpos == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var cbvm = new CommentBucketViewModel { FirstComments = firstComments.Skip((int)startingpos * threadsToFetch).Take(threadsToFetch), Submission = submission }; if (!cbvm.FirstComments.Any()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(PartialView("~/Views/Shared/Comments/_CommentBucket.cshtml", cbvm)); }
// GET: latest single submission comment for given user public ActionResult SingleMostRecentCommentByUser(string userName, int? messageId) { if (userName == null || messageId == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //var comment = _db.Comments // .Where(c => c.Name == userName && c.MessageId == messageId) // .OrderByDescending(c => c.Id) // .FirstOrDefault(); //if (comment == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //ViewBag.CommentId = comment.Id; //if (comment.Message.Anonymized || comment.Message.Subverse.anonymized_mode) //{ // comment.Name = comment.Id.ToString(CultureInfo.InvariantCulture); //} //if (comment.ParentId != null) //{ // return PartialView("~/Views/AjaxViews/_SingleSubmissionComment.cshtml", comment); //} //ViewBag.rootComment = true; //return PartialView("~/Views/AjaxViews/_SingleSubmissionComment.cshtml", comment); var comment = _db.Comments .Where(c => c.Name == userName && c.MessageId == messageId) .OrderByDescending(c => c.Id) .FirstOrDefault(); if (comment == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ViewBag.CommentId = comment.Id; //why? ViewBag.rootComment = comment.ParentId == null; //why? var submission = DataCache.Submission.Retrieve(comment.MessageId.Value); var subverse = DataCache.Subverse.Retrieve(submission.Subverse); if (submission.Anonymized || subverse.anonymized_mode) { comment.Name = comment.Id.ToString(CultureInfo.InvariantCulture); } //COPYPASTA EVERYWHERE!!!!!!!!!!!!!!! Left, right, up down. EVERYWHERE. var model = new CommentBucketViewModel(comment); return PartialView("~/Views/Shared/Submissions/_SubmissionComment.cshtml", model); }