public static GetPostMarkup ( |
||
postInfo | ||
contextPath | string | |
return | string |
public ActionResult CreatePost(string contextPath, string text, string rnd) { if (string.IsNullOrEmpty(text)) { return(null); } AssertPermission(); var post = DataLayer.CreateManualPost(contextPath, text); var postInfo = new PostInfo(post); var postMarkup = WallHelper.GetPostMarkup(postInfo, contextPath); return(Json(postMarkup, JsonRequestBehavior.AllowGet)); }
public static string CreatePost(Content content, string text) { AssertPermission(PlaceholderPath); if (string.IsNullOrEmpty(text)) { return(null); } SetCurrentWorkspace(content.Path); var post = DataLayer.CreateManualPost(content.Path, text); var postInfo = new PostInfo(post); var postMarkup = WallHelper.GetPostMarkup(postInfo, content.Path); return(postMarkup); }
/// <summary> /// Gets markup for a new post, when there are no comments and likes yet. /// </summary> /// <returns></returns> public static string GetPostMarkup(PostInfo postInfo, string contextPath) { return(WallHelper.GetPostMarkup(postInfo, contextPath, string.Empty, string.Empty, 0, new LikeInfo(), false)); }
public static string GetWallPostsMarkup(string contextPath, List <PostInfo> posts) { if (posts.Count == 0) { return(string.Empty); } // create query for comments and likes var csb = new StringBuilder(); var paths = new List <string>(); foreach (var postInfo in posts) { if (postInfo.IsJournal) { continue; } paths.Add(postInfo.Path); } List <Node> allComments; List <Node> allLikes; if (paths.Count == 0) // only non-persisted journal posts are there to show (no comments or likes) { allComments = new List <Node>(); allLikes = new List <Node>(); } else { var settings = new QuerySettings() { EnableAutofilters = FilterStatus.Disabled }; var allCommentsAndLikes = ContentQuery.Query(ContentRepository.SafeQueries.InTreeAndTypeIs, settings, paths, new[] { "Comment", "Like" }).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; allComments = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); allLikes = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); } var bigPostMarkupStr = GetBigPostMarkupStr(); var smallPostMarkupStr = GetSmallPostMarkupStr(); var commentMarkupStr = GetCommentMarkupStr(); var commentSectionStr = GetCommentSectionMarkupStr(); PostInfo prevPost = null; var sb = new StringBuilder(); foreach (var postInfo in posts) { // get comments and likes for post CommentInfo commentInfo; LikeInfo likeInfo; if (postInfo.IsJournal) { commentInfo = new CommentInfo(); likeInfo = new LikeInfo(); } else { var commentsForPost = allComments.Where(c => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(c.Path)) == postInfo.Path).ToList(); var likesForPostAndComments = allLikes.Where(l => l.Path.StartsWith(postInfo.Path)).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == postInfo.Path).ToList(); commentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); likeInfo = new LikeInfo(likesForPost, postInfo.Id); } var drawBoundary = (prevPost != null) && (prevPost.Type != PostType.BigPost) && (postInfo.Type == PostType.BigPost); var markup = WallHelper.GetPostMarkup( postInfo.Type == PostType.BigPost ? bigPostMarkupStr : smallPostMarkupStr, commentSectionStr, postInfo, contextPath, commentInfo.HiddenCommentsMarkup, commentInfo.CommentsMarkup, commentInfo.CommentCount, likeInfo, drawBoundary); prevPost = postInfo; sb.Append(markup); } return(sb.ToString()); }