Exemple #1
0
        public ActionResult CreatePost(string contextPath, string text, string rnd)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            AssertPermission();

            SetCurrentWorkspace(contextPath);
            var post       = DataLayer.CreateManualPost(contextPath, text);
            var postInfo   = new PostInfo(post);
            var postMarkup = WallHelper.GetPostMarkup(postInfo, contextPath);

            return(Json(postMarkup, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public ActionResult GetLikeList(string itemId, string contextPath, string rnd)
        {
            if (!HasPermission())
            {
                return(Json(SNSR.GetString(SNSR.Wall.PleaseLogIn), JsonRequestBehavior.AllowGet));
            }

            SetCurrentWorkspace(contextPath);
            var id = PostInfo.GetIdFromClientId(itemId);

            // create like markup
            var likeInfo = new LikeInfo(id);
            var likelist = new StringBuilder();

            foreach (var likeitem in likeInfo.LikeUsers)
            {
                var likeuser = likeitem as User;
                likelist.Append(WallHelper.GetLikeListItemMarkup(likeuser));
            }

            return(Json(likelist.ToString(), JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        // =============================================================================== Constructors
        public static PostInfo CreateFromCommentOrLike(Node commentOrLike)
        {
            var targetContent = commentOrLike.Parent.Parent;

            // comment likes should not appear, only content likes
            if (targetContent.NodeType.Name == "Comment")
            {
                return(null);
            }

            var postInfo = new PostInfo();

            postInfo.CreationDate = commentOrLike.CreationDate;
            postInfo.CreatedBy    = commentOrLike.CreatedBy as User;
            //postInfo.Action = commentOrLike.NodeType.Name == "Comment" ? "commented on a Content" : "likes a Content";
            postInfo.Action        = SNSR.GetString(commentOrLike.NodeType.Name == "Comment" ? SNSR.Wall.CommentedOnAContent : SNSR.Wall.LikesAContent);
            postInfo.Id            = targetContent.Id;
            postInfo.Path          = targetContent.Path;
            postInfo.ClientId      = postInfo.Id.ToString();
            postInfo.Type          = PostType.BigPost;
            postInfo.SharedContent = targetContent;
            return(postInfo);
        }
Exemple #4
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 settings = new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled, Sort = new SortInfo[] { new SortInfo {
                                                                                       FieldName = "CreationDate", Reverse = true
                                                                                   } }
            };
            var posts = ContentQuery.Query(ContentRepository.SafeQueries.InTreeAndTypeIs, settings,
                                           contextPath, "Post").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();

            #region Gather journal posts: removed
            //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));
            #endregion

            // gather likes and comments corresponding to content under this workspace
            var postsFolderPath = RepositoryPath.Combine(contextPath, "Posts");
            var contentComments = ContentQuery.Query("+InTree:@0 +(Type:Comment Type:Like) -InTree:@1", settings,
                                                     contextPath, postsFolderPath).Nodes.Select(n => PostInfo.CreateFromCommentOrLike(n)).Where(p => p != null).Distinct(new CommentsLikesComparer());

            return(posts.Union(contentComments).OrderByDescending(p => p.CreationDate));
        }
Exemple #5
0
 /// <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));
 }
Exemple #6
0
        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());
        }
Exemple #7
0
        public static string GetPostMarkup(string markupStr, string commentSectionStr, PostInfo postInfo, string contextPath, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, bool drawBoundary)
        {
            if (markupStr == null)
            {
                return(null);
            }

            if (commentSectionStr == null)
            {
                return(null);
            }

            markupStr = ReplaceResources(markupStr);

            markupStr = markupStr.Replace("{{commentsection}}", commentSectionStr);
            markupStr = markupStr.Replace("{{postid}}", postInfo.ClientId.ToString());
            markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(postInfo.CreatedBy));
            markupStr = markupStr.Replace("{{username}}", postInfo.CreatedBy.FullName);
            markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(postInfo.CreatedBy), "Profile"));

            var text = postInfo.Text;

            if (text != null)
            {
                text = text.Replace("{{path}}", postInfo.LastPath ?? string.Empty);
            }

            var haspermission = WallHelper.HasWallPermission(contextPath);

            markupStr = markupStr.Replace("{{text}}", text);
            markupStr = markupStr.Replace("{{date}}", postInfo.CreationDate.ToString());
            markupStr = markupStr.Replace("{{friendlydate}}", UITools.GetFriendlyDate(postInfo.CreationDate));
            markupStr = markupStr.Replace("{{hiddencomments}}", hiddenCommentsMarkup);
            markupStr = markupStr.Replace("{{comments}}", commentsMarkup);
            markupStr = markupStr.Replace("{{commentboxdisplay}}", (commentCount > 0) && haspermission ? "block" : "none");
            markupStr = markupStr.Replace("{{hiddencommentboxdisplay}}", commentCount > 2 ? "block" : "none");
            markupStr = markupStr.Replace("{{commentcount}}", commentCount.ToString());
            markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "block" : "none");
            markupStr = markupStr.Replace("{{likes}}", likeInfo.GetLongMarkup());
            markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none");
            markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none");

            // content card - only manualposts count here, journals don't have this markup
            if (postInfo.Type == PostType.BigPost && postInfo.SharedContent != null)
            {
                markupStr = markupStr.Replace("{{contentcard}}", WallHelper.GetContentCardMarkup(postInfo.SharedContent, contextPath));
            }
            else
            {
                markupStr = markupStr.Replace("{{contentcard}}", string.Empty);
            }

            // small post icon
            var smallposticon = "/Root/Global/images/icons/16/add.png";

            if (postInfo.Type == PostType.JournalModified)
            {
                smallposticon = "/Root/Global/images/icons/16/edit.png";
            }
            if (postInfo.Type == PostType.JournalDeletedPhysically)
            {
                smallposticon = "/Root/Global/images/icons/16/delete.png";
            }
            if (postInfo.Type == PostType.JournalMoved)
            {
                smallposticon = "/Root/Global/images/icons/16/move.png";
            }
            if (postInfo.Type == PostType.JournalCopied)
            {
                smallposticon = "/Root/Global/images/icons/16/copy.png";
            }
            markupStr = markupStr.Replace("{{smallposticon}}", smallposticon);

            markupStr = markupStr.Replace("{{postboundaryclass}}", drawBoundary ? "sn-post-boundary" : string.Empty);

            markupStr = markupStr.Replace("{{action}}", postInfo.Action);

            // small post details
            markupStr = markupStr.Replace("{{detailsdisplay}}", string.IsNullOrEmpty(postInfo.Details) ? "none" : "inline");
            markupStr = markupStr.Replace("{{detailssection}}", ReplaceResources(postInfo.Details));

            // user interaction allowed
            markupStr = markupStr.Replace("{{interactdisplay}}", haspermission ? "inline" : "none");

            return(markupStr);
        }