//for backwards compatibility with EF models public CommentSegment(Data.Models.Comment comment, string subverse) { Comments = new List <NestedComment>() { DomainMaps.MapToNestedComment(comment, subverse) }; }
public static PostDetailCommentViewModel FromModel(Data.Models.Comment model) => new PostDetailCommentViewModel { Content = model.Content, Author = model.Author, Email = model.Email, Date = model.Date.ToString("yyyy-MM-dd") };
public static usp_CommentTree_Result MapToTree(this Data.Models.Comment comment) { usp_CommentTree_Result result = null; if (comment != null) { result = new usp_CommentTree_Result() { ChildCount = 0, Depth = 0, Path = "", Subverse = "", ID = comment.ID, ParentID = comment.ParentID, Content = comment.Content, FormattedContent = comment.FormattedContent, CreationDate = comment.CreationDate, LastEditDate = comment.LastEditDate, SubmissionID = comment.SubmissionID, UpCount = comment.UpCount, DownCount = comment.DownCount, IsDistinguished = comment.IsDistinguished, IsDeleted = comment.IsDeleted, IsAnonymized = comment.IsAnonymized, UserName = comment.UserName }; } return(result); }
public static Domain.Models.Comment Map(this Data.Models.Comment comment, IPrincipal user, string subverse, bool populateUserState = false) { Domain.Models.Comment result = null; if (comment != null) { result = MapToNestedComment(comment, user, subverse, populateUserState); } return(result); }
public async Task PostService_AddComment_WithNonExistingSlug_ShouldReturnFalseAndMessage() { // Arrange var comment = new Data.Models.Comment(); // Act var(result, message) = await _service.AddComment("whatever", comment); // Assert Assert.IsFalse(result); Assert.IsNotNull(message); }
public async Task PostService_AddComment_WithExistingSlug_ShouldAddCommentAndReturnNullMessage() { // Arrange var post = _storage.Last(); var comment = new Data.Models.Comment(); // Act var(result, message) = await _service.AddComment(post.Slug, comment); // Assert Assert.IsTrue(result); Assert.IsNull(message); Assert.AreSame(comment, post.Comments.First()); }
protected override RuleOutcome EvaluateRule(VoatRuleContext context) { Data.Models.Comment comment = context.PropertyBag.Comment; if (comment.IsDeleted) { return(base.CreateOutcome(RuleResult.Denied, "Deleted comments can not be edited")); } if (comment.UserName != context.UserName) { return(base.CreateOutcome(RuleResult.Denied, "User does not have permissions to perform requested action")); } //rules checkd in base class return(base.EvaluateRule(context)); }
public async Task <ActionResult> SubmitComment([Bind(Include = "ID, Content, SubmissionID, ParentID")] Data.Models.Comment commentModel) { if (!ModelState.IsValid) { //Model isn't valid, can include throttling if (Request.IsAjaxRequest()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ModelState.GetFirstErrorMessage())); } else { 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")); } } else { var cmd = new CreateCommentCommand(commentModel.SubmissionID.Value, commentModel.ParentID, commentModel.Content); var result = await cmd.Execute(); if (result.Success) { //if good return formatted comment if (Request.IsAjaxRequest()) { var comment = result.Response; comment.IsOwner = true; ViewBag.CommentId = comment.ID; //why? ViewBag.rootComment = comment.ParentID == null; //why? return(PartialView("~/Views/Shared/Comments/_SubmissionComment.cshtml", comment)); } else if (Request.UrlReferrer != null) { var url = Request.UrlReferrer.AbsolutePath; return(Redirect(url)); } else { return(new EmptyResult()); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message)); } } }
public IActionResult AddComment([FromBody] BlogAddCommentDto blogAddComment) { Data.Models.Comment blog = new Data.Models.Comment() { BlogId = blogAddComment.BlogId, CreateDate = DateTime.UtcNow, Content = blogAddComment.Comment, Deleted = false, Email = blogAddComment.Email, Nickname = blogAddComment.Nickname, ParentCommentId = blogAddComment.ParetnCommentId, Voteup = 0, VoteDown = 0 }; _blogContext.Comments.Add(blog); _blogContext.SaveChanges(); return(new JsonResult("ok")); }
public static NestedComment MapToNestedComment(this Data.Models.Comment comment, IPrincipal user, string subverse, bool populateUserState = false) { NestedComment result = null; if (comment != null) { result = new NestedComment(); result.ID = comment.ID; result.ParentID = comment.ParentID; result.ChildCount = 0; result.Content = comment.Content; result.FormattedContent = comment.FormattedContent; result.UserName = comment.UserName; result.UpCount = (int)comment.UpCount; result.DownCount = (int)comment.DownCount; result.CreationDate = comment.CreationDate; result.IsAnonymized = comment.IsAnonymized; result.IsDeleted = comment.IsDeleted; result.IsDistinguished = comment.IsDistinguished; result.LastEditDate = comment.LastEditDate; result.SubmissionID = comment.SubmissionID; //Just a note, the entire Subverse in Data models for comments is a bit hacky as this info is needed in the app but data models don't contain it. if (String.IsNullOrEmpty(subverse)) { //TODO: need to convert pipeline to support this or pull this data out of the db result.Subverse = "TODO"; } else { result.Subverse = subverse; } //Set User State and secure comment HydrateUserData(user, result, populateUserState); } return(result); }
public async Task <ActionResult> EditComment([Bind(Include = "ID, Content")] Data.Models.Comment commentModel) { if (ModelState.IsValid) { var cmd = new EditCommentCommand(commentModel.ID, commentModel.Content); var result = await cmd.Execute(); if (result.Success) { return(Json(new { response = result.Response.FormattedContent })); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // var existingComment = _db.Comments.Find(commentModel.ID); // if (existingComment != null) // { // if (existingComment.UserName.Trim() == User.Identity.Name && !existingComment.IsDeleted) // { // bool containsBannedDomain = BanningUtility.ContentContainsBannedDomain(existingComment.Submission.Subverse, commentModel.Content); // if (containsBannedDomain) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Comment contains links to banned domain(s)."); // } // existingComment.LastEditDate = Repository.CurrentDate; // existingComment.Content = commentModel.Content; // if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave)) // { // existingComment.Content = ContentProcessor.Instance.Process(existingComment.Content, ProcessingStage.InboundPreSave, existingComment); // } // //save fully formatted content // var formattedComment = Voat.Utilities.Formatting.FormatMessage(existingComment.Content); // existingComment.FormattedContent = formattedComment; // await _db.SaveChangesAsync(); // //HACK: Update comment in cache - to be replaced with EditCommentCommand in future // string key = CachingKey.CommentTree(existingComment.SubmissionID.Value); // if (CacheHandler.Instance.Exists(key)) // { // CacheHandler.Instance.Replace<usp_CommentTree_Result>(key, existingComment.ID, x => { // x.Content = existingComment.Content; // x.FormattedContent = existingComment.FormattedContent; // return x; // }); // } // if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave)) // { // ContentProcessor.Instance.Process(existingComment.Content, ProcessingStage.InboundPostSave, existingComment); // } // //return the formatted comment so that it can replace the existing html comment which just got modified // return Json(new { response = formattedComment }); // } // return Json("Unauthorized edit.", JsonRequestBehavior.AllowGet); // } //} //if (Request.IsAjaxRequest()) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //return Json("Unauthorized edit or comment not found - comment ID was.", JsonRequestBehavior.AllowGet); }
public static async Task OnCommentPosted(IPrincipal user, Data.Models.Submission submission, Data.Models.Comment comment) { if (comment.ParentID != null && comment.Content != null) { await SendCommentReplyNotification(user, submission, comment); } else { await SendSubmissionReplyNotification(user, submission, comment); } var users = FindMentions(comment.Content); if (users.Any()) { await SendUserMentionNotification(comment, users); } }
internal static async Task SendSubmissionReplyNotification(IPrincipal user, Data.Models.Submission submission, Data.Models.Comment comment) { try { // comment reply is sent to a root comment which has no parent id, trigger post reply notification //var submission = DataCache.Submission.Retrieve(comment.SubmissionID); //var q = new QuerySubmission(comment.SubmissionID.Value); //var submission = await q.ExecuteAsync().ConfigureAwait(CONSTANTS.AWAIT_CAPTURE_CONTEXT); if (submission != null) { // check if recipient exists if (UserHelper.UserExists(submission.UserName)) { // do not send notification if author is the same as comment author if (submission.UserName != comment.UserName) { //BlockedUser Implementation - Submission Reply if (!MesssagingUtility.IsSenderBlocked(comment.UserName, submission.UserName)) { var message = new Domain.Models.Message(); message.IsAnonymized = submission.IsAnonymized; message.Recipient = submission.UserName; message.RecipientType = Domain.Models.IdentityType.User; message.Sender = comment.UserName; message.SenderType = Domain.Models.IdentityType.User; message.Subverse = submission.Subverse; message.SubmissionID = submission.ID; message.CommentID = comment.ID; message.Type = Domain.Models.MessageType.SubmissionReply; message.CreationDate = Repository.CurrentDate; using (var repo = new Repository(user)) { var response = await repo.SendMessage(message); if (response.Success) { EventNotification.Instance.SendMessageNotice(message.Recipient, message.Sender, Domain.Models.MessageTypeFlag.CommentReply, Domain.Models.ContentType.Comment, comment.ID); } } } } } } } catch (Exception ex) { throw ex; } }
internal static async Task SendCommentReplyNotification(IPrincipal user, Data.Models.Submission submission, Data.Models.Comment comment) { try { using (var _db = new VoatOutOfRepositoryDataContextAccessor()) { Random _rnd = new Random(); if (comment.ParentID != null && comment.Content != null) { // find the parent comment and its author var parentComment = _db.Comment.Find(comment.ParentID); if (parentComment != null) { // check if recipient exists if (UserHelper.UserExists(parentComment.UserName)) { // do not send notification if author is the same as comment author if (parentComment.UserName != comment.UserName) { // send the message //BlockedUser Implementation - Comment Reply if (!MesssagingUtility.IsSenderBlocked(comment.UserName, parentComment.UserName)) { //var submission = DataCache.Submission.Retrieve(comment.SubmissionID); //var q = new QuerySubmission(comment.SubmissionID.Value); //var submission = await q.ExecuteAsync().ConfigureAwait(CONSTANTS.AWAIT_CAPTURE_CONTEXT); if (submission != null) { //var subverse = DataCache.Subverse.Retrieve(submission.Subverse); var message = new Domain.Models.Message(); message.IsAnonymized = submission.IsAnonymized; message.Recipient = parentComment.UserName; message.RecipientType = Domain.Models.IdentityType.User; message.Sender = comment.UserName; message.SenderType = Domain.Models.IdentityType.User; message.Subverse = submission.Subverse; message.SubmissionID = submission.ID; message.CommentID = comment.ID; message.Type = Domain.Models.MessageType.CommentReply; message.CreationDate = Repository.CurrentDate; using (var repo = new Repository(user)) { var response = await repo.SendMessage(message); if (response.Success) { EventNotification.Instance.SendMessageNotice(message.Recipient, message.Sender, Domain.Models.MessageTypeFlag.CommentReply, Domain.Models.ContentType.Comment, comment.ID); } } } } } } } } } } catch (Exception ex) { throw ex; } }