示例#1
0
        public static CommentAttachment Create(Comment comment, ulong action_id)
        {
            CommentAttachment attachment = null;

            if (!string.IsNullOrEmpty(comment.attachment_type))
            {
                ActivityAttachment attach = new ActivityAttachment()
                {
                    id = (uint)comment.attachment_id, type = comment.attachment_type, mode = true
                };
                //var attach = ActivityAttachments.GetByTypeAndId((comment.attachment_type,(uint)comment.attachment_id)).FirstOrDefault();
                var feedAttachment = FeedAttachmentFactory.Create(attach, action_id);
                attachment = new CommentAttachment(feedAttachment);
            }

            return(attachment);
        }
示例#2
0
        public CommentInfo(Comment comment, ulong viewerId, bool?isLike = false, List <Comment> children = null, bool isReply = false)
        {
            Logger.Instance.Debug($"building comment info for comment {comment.comment_id}");
            var user = Users.GetById(comment.poster_id);

            action_id            = comment.resource_id;
            comment_id           = comment.comment_id;
            image                = comment.GetParam <string>("image");
            image_normal         = comment.GetParam <string>("image_normal");
            image_profile        = comment.GetParam <string>("image_profile");
            image_icon           = comment.GetParam <string>("image_icon");
            content_url          = comment.GetParam <string>("content_url");
            author_image         = comment.GetParam <string>("author_image");
            author_image_normal  = comment.GetParam <string>("author_image_normal");
            author_image_profile = comment.GetParam <string>("author_image_profile");
            author_image_icon    = comment.GetParam <string>("author_image_icon");
            author_title         = user.displayname;
            comment_body         = Encoding.UTF8.GetString(comment.body);
            user_id              = comment.poster_id;
            userTag              = string.Empty;
            //    //@params;
            comment_date = comment.creation_date.ToString("yyyy-MM-dd HH:mm:ss");
            attachment   = CommentAttachment.Create(comment, action_id);

            attachment_type = comment.attachment_type;
            attachment_id   = (ulong)comment.attachment_id;

            //build gutter menu
            List <CommentMenuItem> menu = new List <CommentMenuItem>();

            if (viewerId == comment.poster_id)
            {
                menu.Add(new CommentMenuItem("comment_delete", comment));
                menu.Add(new CommentMenuItem("comment_edit", comment));
            }
            menu.Add(new CommentMenuItem("comment_copy", comment));
            menu.Add(new CommentMenuItem("comment_cancel", comment));
            gutterMenu = menu.ToArray();

            if (!isReply)
            {
                if (children != null)
                {
                    List <CommentInfo> subCumments = new List <CommentInfo>();
                    children.ForEach(c => subCumments.Add(new CommentInfo(c, viewerId, null, null, true)));
                    reply_on_comment = subCumments.OrderByDescending(c => c.comment_id).ToArray();
                    reply_count      = reply_on_comment.Length;
                }
                reply = new CommentMenuItem("reply", comment);
            }

            this.isReply = isReply?0:1;

            if (!isLike.HasValue)
            {
                //find if user already like this commewnt
                isLike = Likes.GetByResourceAndPoster(comment.comment_id, "activity_comment", (uint)user_id, "user") != null;
            }


            if (isLike == true)
            {
                like = new CommentMenuItem("unlike", comment);
            }
            else
            {
                like = new CommentMenuItem("like", comment);
            }

            like_count = (uint)CoreLikes.CountByResource(comment.comment_id, "activity_comment").Count();
        }