CreateFromCommentOrLike() public static method

public static CreateFromCommentOrLike ( Node commentOrLike ) : PostInfo
commentOrLike Node
return PostInfo
Example #1
0
        // ================================================================================================ Public methods
        /// <summary>
        /// Retrieves all posts under given contextPath.
        /// </summary>
        /// <param name="contextPath">Path of context, ie. workspace.</param>
        /// <returns></returns>
        public static IEnumerable <PostInfo> GetPostsForWorkspace(string contextPath)
        {
            var queryText = string.Format("+InTree:\"{0}\" +Type:Post", contextPath);
            var settings  = new QuerySettings {
                EnableAutofilters = false, Sort = new SortInfo[] { new SortInfo {
                                                                       FieldName = "CreationDate", Reverse = true
                                                                   } }
            };
            var posts = ContentQuery.Query(queryText, settings).Nodes.Select(n => new PostInfo(n));

            // gather all journalid-s: these are ids to which post has already been created in the Content Repository
            var journalIds = posts.Select(p => p.JournalId).Distinct();

            var journalItems = Journals.GetItemsForWorkspace(contextPath);

            // get last paths of journals. Get all journals grouped by nodeids
            var lastPaths = (from j in journalItems
                             group j by j.NodeId into grp
                             select grp.First()).ToDictionary(j => j.NodeId, j => j.Wherewith);

            // gather crudposts, where createdby is a valid user (not SYSTEMUSER)
            // and it has not been persisted to the content repository yet (journalid is not contained in journalids above)
            var crudPosts = journalItems.Select(j => new PostInfo(j, lastPaths[j.NodeId])).Where(p => p.CreatedBy != null && !journalIds.Contains(p.JournalId));

            // gather likes and comments corresponding to content under this workspace
            var postsFolderPath = RepositoryPath.Combine(contextPath, "Posts");

            queryText = string.Format("+InTree:\"{0}\" +(Type:Comment Type:Like) -InTree:\"{1}\"", contextPath, postsFolderPath);
            var contentComments = ContentQuery.Query(queryText, settings).Nodes.Select(n => PostInfo.CreateFromCommentOrLike(n)).Where(p => p != null).Distinct(new CommentsLikesComparer());

            return(posts.Union(crudPosts).Union(contentComments).OrderByDescending(p => p.CreationDate));
        }