public AjaxResponse AddComment(string parentCommentId, string newsId, string text, string pid) { var resp = new AjaxResponse { rs1 = parentCommentId }; var comment = new FeedComment(long.Parse(newsId)); comment.Comment = text; var storage = FeedStorageFactory.Create(); if (!string.IsNullOrEmpty(parentCommentId)) { comment.ParentId = Convert.ToInt64(parentCommentId); } var feed = storage.GetFeed(long.Parse(newsId, CultureInfo.CurrentCulture)); comment = storage.SaveFeedComment(feed, comment); var commentInfo = GetCommentInfo(comment); var defComment = new CommentsList(); ConfigureComments(defComment, feed); var visibleCommentsCount = 0; storage.GetFeedComments(feed.Id).ForEach((cmm) => { visibleCommentsCount += (cmm.Inactive ? 0 : 1); }); resp.rs2 = CommentsHelper.GetOneCommentHtmlWithContainer( defComment, commentInfo, comment.IsRoot(), visibleCommentsCount % 2 == 1); return(resp); }
private void NotifyNewComment(FeedComment comment, Feed feed) { var feedType = feed.FeedType == FeedType.Poll ? "poll" : "feed"; var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.Creator, "")); try { NewsNotifyClient.NotifyClient.AddInterceptor(initatorInterceptor); NewsNotifyClient.NotifyClient.SendNoticeAsync( NewsConst.NewComment, feed.Id.ToString(CultureInfo.InvariantCulture), null, new TagValue(NewsConst.TagFEED_TYPE, feedType), //new TagValue(NewsConst.TagAnswers, feed.Variants.ConvertAll<string>(v => v.Name)), new TagValue(NewsConst.TagCaption, feed.Caption), new TagValue("CommentBody", HtmlUtility.GetFull(comment.Comment)), new TagValue(NewsConst.TagDate, comment.Date.ToShortString()), new TagValue(NewsConst.TagURL, CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id)), new TagValue("CommentURL", CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id + "#" + comment.Id.ToString(CultureInfo.InvariantCulture))), new TagValue(NewsConst.TagUserName, DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)), new TagValue(NewsConst.TagUserUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID))), GetReplyToTag(feed, comment) ); } finally { NewsNotifyClient.NotifyClient.RemoveInterceptor(initatorInterceptor.Name); } }
public string GetPreview(string text, string commentID) { var storage = FeedStorageFactory.Create(); var comment = new FeedComment(1) { Date = TenantUtil.DateTimeNow(), Creator = SecurityContext.CurrentAccount.ID.ToString() }; if (!string.IsNullOrEmpty(commentID)) { comment = storage.GetFeedComment(long.Parse(commentID, CultureInfo.CurrentCulture)); } comment.Comment = text; var info = GetCommentInfo(comment); info.IsEditPermissions = false; info.IsResponsePermissions = false; var defComment = new CommentsList(); ConfigureComments(defComment, null); return(CommentsHelper.GetOneCommentHtmlWithContainer( defComment, info, true, false)); }
public async Task MarkFeedCommentAsDeletedAsync(int feedCommentId, CancellationToken ct = default) { FeedComment comment = await _context.FeedPostComments.FindAsync(feedCommentId); comment.IsDeleted = true; _context.Update(comment); await _context.SaveChangesAsync(ct); }
public async Task <FeedComment> AddCommentToPostAsync(FeedComment comment, CancellationToken ct = default) { await _context.FeedPostComments.AddAsync(comment, ct); await _context.SaveChangesAsync(ct); return(await GetCommentByIdAsync(comment.FeedCommentId, ct)); }
public FeedComment SaveFeedComment(Feed feed, FeedComment comment) { SaveFeedComment(comment); if (feed != null) { NotifyNewComment(comment, feed); } return(comment); }
public EventCommentWrapper(FeedComment comment) { CreatedBy = EmployeeWraper.Get(Core.CoreContext.UserManager.GetUsers(new Guid(comment.Creator))); Updated = Created = (ApiDateTime)comment.Date; Id = comment.Id; Text = comment.Comment; ParentId = comment.ParentId; }
public async Task <FeedComment> GetCommentByIdAsync(int commentId, CancellationToken ct = default) { FeedComment comment = await _context.FeedPostComments .AsNoTracking() .Include(fc => fc.User) .FirstOrDefaultAsync(fc => fc.FeedCommentId == commentId, cancellationToken: ct); comment.UserDTO = comment.User.ConvertToDTO(); comment.User = null; return(comment); }
private static List <CommentInfo> BuildCommentsList(List <FeedComment> loaded, long parentId) { var result = new List <CommentInfo>(); foreach (var comment in FeedComment.SelectChildLevel(parentId, loaded)) { var info = GetCommentInfo(comment); info.CommentList = BuildCommentsList(loaded, comment.Id); result.Add(info); } return(result); }
public async Task <IActionResult> CommentOnPost([FromBody] FeedComment comment, CancellationToken ct = default) { if (!AuthenticationUtilities.IsAllowedFeed(User)) { return(BadRequest("User has been banned from Feed")); } if (!AuthenticationUtilities.IsSameUser(User, comment.UserUUID)) { return(Unauthorized("You do not have access to comment for this user")); } return(Ok(await _feedService.AddCommentToPostAsync(comment, ct))); }
private void SaveFeedComment(FeedComment comment) { if (comment == null) { throw new ArgumentNullException("comment"); } comment.Id = dbManager.ExecuteScalar <long>( Insert("events_comment").InColumns("Id", "Feed", "Comment", "Parent", "Date", "Creator", "Inactive") .Values(comment.Id, comment.FeedId, comment.Comment, comment.ParentId, TenantUtil.DateTimeToUtc(comment.Date), comment.Creator, comment.Inactive) .Identity(1, 0L, true) ); }
public async Task <FeedComment> CreateNewCommentForPost(int PostId, FeedComment comment, int userId) { using (var conn = new MySqlConnection(connString)) //Creates new temp connection { await conn.OpenAsync(); //Waits for connection to open using (var cmd = new MySqlCommand($"INSERT INTO feed_post_comments VALUES({0}," + //Inserts new row into the table $" {userId}, {PostId}, '{comment.Comment}', {comment.IsAdmin}, {comment.IsDeleted}, '{comment.DatePosted.ToString("yyyy-MM-dd hh:mm:ss")}');", conn)) //^ Inserts comment into table { await cmd.ExecuteNonQueryAsync(); //Executes the command return(await GetCommentById((int)cmd.LastInsertedId)); //Gets the last inserted auto-increment id and gets/returns the comment } } }
private void NotifyNewComment(FeedComment comment, Feed feed) { var feedType = feed.FeedType == FeedType.Poll ? "poll" : "feed"; var tags = new ITagValue[] { new TagValue(NewsConst.TagFEED_TYPE, feedType), //new TagValue(NewsConst.TagAnswers, feed.Variants.ConvertAll<string>(v => v.Name)), new TagValue(NewsConst.TagCaption, feed.Caption), new TagValue("CommentBody", HtmlUtility.GetFull(comment.Comment)), new TagValue(NewsConst.TagDate, comment.Date.ToShortString()), new TagValue(NewsConst.TagURL, CommonLinkUtility.GetFullAbsolutePath("~/Products/Community/Modules/News/Default.aspx?docid=" + feed.Id)), new TagValue("CommentURL", CommonLinkUtility.GetFullAbsolutePath("~/Products/Community/Modules/News/Default.aspx?docid=" + feed.Id + "#container_" + comment.Id.ToString(CultureInfo.InvariantCulture))), new TagValue(NewsConst.TagUserName, DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)), new TagValue(NewsConst.TagUserUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID))) }; var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.Creator, "")); try { NewsNotifyClient.NotifyClient.AddInterceptor(initatorInterceptor); var mentionedUsers = MentionProvider.GetMentionedUsers(comment.Comment); var mentionedUserIds = mentionedUsers.Select(u => u.ID.ToString()); var provider = NewsNotifySource.Instance.GetSubscriptionProvider(); var objectID = feed.Id.ToString(CultureInfo.InvariantCulture); var recipients = provider .GetRecipients(NewsConst.NewComment, objectID) .Where(r => !mentionedUserIds.Contains(r.ID)) .ToArray(); NewsNotifyClient.NotifyClient.SendNoticeToAsync(NewsConst.NewComment, objectID, recipients, false, tags); if (mentionedUsers.Length > 0) { NewsNotifyClient.NotifyClient.SendNoticeToAsync(NewsConst.MentionForFeedComment, objectID, mentionedUsers, false, tags); } } finally { NewsNotifyClient.NotifyClient.RemoveInterceptor(initatorInterceptor.Name); } }
public async Task <IActionResult> DeleteComment(int commentId, CancellationToken ct = default) { if (!AuthenticationUtilities.IsAllowedFeed(User)) { return(BadRequest("User has been banned from Feed")); } FeedComment comment = await _feedService.GetCommentByIdAsync(commentId, ct); if (!AuthenticationUtilities.IsSameUserOrPrivileged(User, comment.UserUUID)) { return(Unauthorized("You do not have access to delete this comment")); } await _feedService.MarkFeedCommentAsDeletedAsync(commentId, ct); return(Ok()); }
public EventCommentWrapper AddEventComments(int feedid, string content, long parentId) { if (parentId > 0 && FeedStorage.GetFeedComment(parentId) == null) { throw new ItemNotFoundException("parent comment not found"); } var comment = new FeedComment(feedid) { Comment = content, Creator = SecurityContext.CurrentAccount.ID.ToString(), FeedId = feedid, Date = DateTime.UtcNow, ParentId = parentId }; FeedStorage.SaveFeedComment(FeedStorage.GetFeed(feedid), comment); return(new EventCommentWrapper(comment)); }
private static CommentInfo GetCommentInfo(FeedComment comment) { var info = new CommentInfo { CommentID = comment.Id.ToString(CultureInfo.CurrentCulture), UserID = new Guid(comment.Creator), TimeStamp = comment.Date, TimeStampStr = comment.Date.Ago(), IsRead = true, Inactive = comment.Inactive, CommentBody = comment.Comment, UserFullName = DisplayUserSettings.GetFullUserName(new Guid(comment.Creator)), UserAvatar = GetHtmlImgUserAvatar(new Guid(comment.Creator)), IsEditPermissions = CommunitySecurity.CheckPermissions(comment, NewsConst.Action_Edit), IsResponsePermissions = CommunitySecurity.CheckPermissions(NewsConst.Action_Comment), UserPost = CoreContext.UserManager.GetUsers((new Guid(comment.Creator))).Title }; return(info); }
public CommentInfo AddEventComment(string parentcommentid, string entityid, string content) { if (String.IsNullOrEmpty(content)) { throw new ArgumentException(); } var comment = new FeedComment(long.Parse(entityid)); comment.Comment = content; var storage = FeedStorageFactory.Create(); if (!string.IsNullOrEmpty(parentcommentid)) { comment.ParentId = Convert.ToInt64(parentcommentid); } var feed = storage.GetFeed(long.Parse(entityid, CultureInfo.CurrentCulture)); comment = storage.SaveFeedComment(feed, comment); return(GetCommentInfo(comment)); }
public CommentInfo GetEventCommentPreview(string commentid, string htmltext) { var storage = FeedStorageFactory.Create(); var comment = new FeedComment(1) { Date = TenantUtil.DateTimeNow(), Creator = SecurityContext.CurrentAccount.ID.ToString() }; if (!string.IsNullOrEmpty(commentid)) { comment = storage.GetFeedComment(long.Parse(commentid, CultureInfo.CurrentCulture)); } comment.Comment = htmltext; var commentInfo = GetCommentInfo(comment); commentInfo.IsEditPermissions = false; commentInfo.IsResponsePermissions = false; return(commentInfo); }
public async Task <IActionResult> CreateCommentForPost(int postid, int userid, [FromBody] FeedComment comment) { return(Ok(await new FeedTasks().CreateNewCommentForPost(postid, comment, userid))); }
public void FeedTest() { var feed1 = new Feed(); feed1.FeedType = FeedType.News; feed1.Caption = "aaa"; feed1.Text = "bbb"; var feed1Id = feedStorage.SaveFeed(feed1, TODO, TODO).Id; feedStorage.SaveFeed(feed1, TODO, TODO); var feed2 = new Feed(); feed2.FeedType = FeedType.Order; feed2.Caption = "ccca"; feed2.Text = "ddd"; var feed2Id = feedStorage.SaveFeed(feed2, TODO, TODO).Id; var feeds = feedStorage.GetFeeds(FeedType.News, Guid.Empty, 0, 0); CollectionAssert.AreEquivalent(new[] { feed1 }, feeds); feeds = feedStorage.GetFeeds(FeedType.Order, Guid.Empty, 0, 0); CollectionAssert.AreEquivalent(new[] { feed2 }, feeds); feeds = feedStorage.GetFeeds(FeedType.Advert, Guid.Empty, 0, 0); CollectionAssert.IsEmpty(feeds); feeds = feedStorage.GetFeeds(FeedType.All, Guid.NewGuid(), 0, 0); CollectionAssert.IsEmpty(feeds); feeds = feedStorage.SearchFeeds("c", FeedType.All, Guid.Empty, 0, 0); CollectionAssert.AreEquivalent(new[] { feed2 }, feeds); feeds = feedStorage.SearchFeeds("a"); CollectionAssert.AreEquivalent(new[] { feed1, feed2 }, feeds); var feedTypes = feedStorage.GetUsedFeedTypes(); CollectionAssert.AreEquivalent(new[] { FeedType.News, FeedType.Order }, feedTypes); feed2 = feedStorage.GetFeed(feed2Id); Assert.IsAssignableFrom(typeof(FeedNews), feed2); Assert.AreEqual(FeedType.Order, feed2.FeedType); Assert.AreEqual("ccca", feed2.Caption); Assert.AreEqual("ddd", feed2.Text); var c1 = new FeedComment(feed1Id) { Comment = "c1", Inactive = true }; var c2 = new FeedComment(feed1Id) { Comment = "c2" }; var c3 = new FeedComment(feed2Id) { Comment = "c3" }; var c1Id = feedStorage.SaveFeedComment(c1).Id; var c2Id = feedStorage.SaveFeedComment(c2).Id; feedStorage.SaveFeedComment(c3); feedStorage.SaveFeedComment(c3); var comments = feedStorage.GetFeedComments(feed2Id); CollectionAssert.AreEquivalent(new[] { c3 }, comments); comments = feedStorage.GetFeedComments(feed1Id); CollectionAssert.AreEquivalent(new[] { c1, c2 }, comments); feedStorage.RemoveFeedComment(c2Id); comments = feedStorage.GetFeedComments(feed1Id); CollectionAssert.AreEquivalent(new[] { c1 }, comments); c1 = feedStorage.GetFeedComment(c1Id); Assert.AreEqual("c1", c1.Comment); Assert.IsTrue(c1.Inactive); feedStorage.ReadFeed(feed2Id, SecurityContext.CurrentAccount.ID.ToString()); feedStorage.RemoveFeed(feed2Id); feedStorage.RemoveFeed(feed1Id); feed1 = feedStorage.GetFeed(feed1Id); Assert.IsNull(feed1); comments = feedStorage.GetFeedComments(feed1Id); CollectionAssert.IsEmpty(comments); }
public static void AddFeedComment(FeedComment comment, Feed post, Guid author) { string action = string.Empty; if (post is FeedNews) { action = NewsResource.UserActivity_AddCommentNews; } else if (post is FeedPoll) { action = NewsResource.UserActivity_AddCommentFeed; } if (!string.IsNullOrEmpty(action)) { UserActivity ua = ApplyCustomeActivityParams(post, ComposeActivityByFeed(post), action, author, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity ); ua.HtmlPreview = comment.Comment; PublishInternal(ua); } }
public void UpdateFeedComment(FeedComment comment) { SaveFeedComment(comment); }
public void RemoveFeedComment(FeedComment comment) { SaveFeedComment(comment); }
public void UpdateFeedComment(FeedComment comment) { SaveFeedComment(comment); ActivityPublisher.EditFeedComment(GetFeed(comment.FeedId), SecurityContext.CurrentAccount.ID); }
public void FeedTest() { var feed1 = new Feed(); feed1.FeedType = FeedType.News; feed1.Caption = "aaa"; feed1.Text = "bbb"; var feed1Id = feedStorage.SaveFeed(feed1, TODO, TODO).Id; feedStorage.SaveFeed(feed1, TODO, TODO); var feed2 = new Feed(); feed2.FeedType = FeedType.Order; feed2.Caption = "ccca"; feed2.Text = "ddd"; var feed2Id = feedStorage.SaveFeed(feed2, TODO, TODO).Id; var feeds = feedStorage.GetFeeds(FeedType.News, Guid.Empty, 0, 0); CollectionAssert.AreEquivalent(new[] { feed1 }, feeds); feeds = feedStorage.GetFeeds(FeedType.Order, Guid.Empty, 0, 0); CollectionAssert.AreEquivalent(new[] { feed2 }, feeds); feeds = feedStorage.GetFeeds(FeedType.Advert, Guid.Empty, 0, 0); CollectionAssert.IsEmpty(feeds); feeds = feedStorage.GetFeeds(FeedType.All, Guid.NewGuid(), 0, 0); CollectionAssert.IsEmpty(feeds); feeds = feedStorage.SearchFeeds("c", FeedType.All, Guid.Empty, 0, 0); CollectionAssert.AreEquivalent(new[] { feed2 }, feeds); feeds = feedStorage.SearchFeeds("a"); CollectionAssert.AreEquivalent(new[] { feed1, feed2 }, feeds); var feedTypes = feedStorage.GetUsedFeedTypes(); CollectionAssert.AreEquivalent(new[] { FeedType.News, FeedType.Order }, feedTypes); feed2 = feedStorage.GetFeed(feed2Id); Assert.IsAssignableFrom(typeof(FeedNews), feed2); Assert.AreEqual(FeedType.Order, feed2.FeedType); Assert.AreEqual("ccca", feed2.Caption); Assert.AreEqual("ddd", feed2.Text); var c1 = new FeedComment(feed1Id) { Comment = "c1", Inactive = true }; var c2 = new FeedComment(feed1Id) { Comment = "c2" }; var c3 = new FeedComment(feed2Id) { Comment = "c3" }; var c1Id = feedStorage.SaveFeedComment(c1).Id; var c2Id = feedStorage.SaveFeedComment(c2).Id; feedStorage.SaveFeedComment(c3); feedStorage.SaveFeedComment(c3); var comments = feedStorage.GetFeedComments(feed2Id); CollectionAssert.AreEquivalent(new[] { c3 }, comments); comments = feedStorage.GetFeedComments(feed1Id); CollectionAssert.AreEquivalent(new[] { c1, c2 }, comments); feedStorage.RemoveFeedComment(c2Id); comments = feedStorage.GetFeedComments(feed1Id); CollectionAssert.AreEquivalent(new[] { c1 }, comments); c1 = feedStorage.GetFeedComment(c1Id); Assert.AreEqual("c1", c1.Comment); Assert.IsTrue(c1.Inactive); feedStorage.ReadFeed(feed2Id, SecurityContext.CurrentAccount.ID.ToString()); feedStorage.RemoveFeed(feed2Id); feedStorage.RemoveFeed(feed1Id); feed1 = feedStorage.GetFeed(feed1Id); Assert.IsNull(feed1); comments = feedStorage.GetFeedComments(feed1Id); CollectionAssert.IsEmpty(comments); }
public void RemoveFeedComment(FeedComment comment) { SaveFeedComment(comment); }
public void UpdateFeedComment(FeedComment comment) { SaveFeedComment(comment); }
private void SaveFeedComment(FeedComment comment) { if (comment == null) throw new ArgumentNullException("comment"); comment.Id = dbManager.ExecuteScalar<long>( Insert("events_comment").InColumns("Id", "Feed", "Comment", "Parent", "Date", "Creator", "Inactive") .Values(comment.Id, comment.FeedId, comment.Comment, comment.ParentId, TenantUtil.DateTimeToUtc(comment.Date), comment.Creator, comment.Inactive) .Identity(1, 0L, true) ); }
private static TagValue GetReplyToTag(Feed feed, FeedComment feedComment) { return(ReplyToTagProvider.Comment("event", feed.Id.ToString(CultureInfo.InvariantCulture), feedComment != null ? feedComment.Id.ToString(CultureInfo.InvariantCulture) : null)); }
private void NotifyNewComment(FeedComment comment, Feed feed) { var feedType = feed.FeedType == FeedType.Poll ? "poll" : "feed"; var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.Creator, "")); try { NewsNotifyClient.NotifyClient.AddInterceptor(initatorInterceptor); NewsNotifyClient.NotifyClient.SendNoticeAsync( NewsConst.NewComment, feed.Id.ToString(CultureInfo.InvariantCulture), null, new TagValue(NewsConst.TagFEED_TYPE, feedType), //new TagValue(NewsConst.TagAnswers, feed.Variants.ConvertAll<string>(v => v.Name)), new TagValue(NewsConst.TagCaption, feed.Caption), new TagValue("CommentBody", HtmlUtility.GetFull(comment.Comment, Product.CommunityProduct.ID)), new TagValue(NewsConst.TagDate, comment.Date.ToShortString()), new TagValue(NewsConst.TagURL, CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id)), new TagValue("CommentURL", CommonLinkUtility.GetFullAbsolutePath("~/products/community/modules/news/?docid=" + feed.Id + "#" + comment.Id.ToString(CultureInfo.InvariantCulture))), new TagValue(NewsConst.TagUserName, DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)), new TagValue(NewsConst.TagUserUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID))), GetReplyToTag(feed, comment) ); } finally { NewsNotifyClient.NotifyClient.RemoveInterceptor(initatorInterceptor.Name); } }
public FeedComment SaveFeedComment(Feed feed, FeedComment comment) { SaveFeedComment(comment); if (feed != null) { NotifyNewComment(comment, feed); } return comment; }
private static TagValue GetReplyToTag(Feed feed, FeedComment feedComment) { return ReplyToTagProvider.Comment("event", feed.Id.ToString(CultureInfo.InvariantCulture), feedComment != null ? feedComment.Id.ToString(CultureInfo.InvariantCulture) : null); }