コード例 #1
0
        /// <summary>
        /// Open all comments page.
        /// </summary>
        /// <param name="sender">The control/object that raised the event</param>
        /// <param name="e">Event Data</param>
        private void CommentsButton_Click(object sender, RoutedEventArgs e)
        {
            CommentsPage commentsPage = new CommentsPage()
            {
                CurrentLoggedInUser = this.CurrentLoggedInUser
            };

            ContentFrame.Navigate(commentsPage);
        }
コード例 #2
0
        public async Task <IActionResult> Comments(string id)
        {
            RedditPost post = await _context.Posts.FindAsync(id);

            post.created_string = SecondsToAgoString((Int64)post.created_utc);

            List <RedditComment> RList = _context.Comments
                                         .Where(a => a.postID == id)
                                         .ToList();

            RList.Reverse();

            string      current_id  = post.id;
            CommentTree commentTree = new CommentTree();

            commentTree.children = new List <CommentTree>();
            commentTree.comment  = null;
            List <RedditComment> TopLevelComments = RList.Where(a => a.parentID.ToString() == current_id).ToList();

            foreach (var TopLevelComment in TopLevelComments)
            {
                CommentTree child_comment_tree = GetCommentTree(RList, TopLevelComment, true);
                commentTree.children.Add(child_comment_tree);
            }

            foreach (var item in RList)
            {
                item.createdString = SecondsToAgoString(item.unixTimestamp);
            }

            string subreddit = post.subreddit;

            CommentsPage commentsPage = new CommentsPage()
            {
                post        = post,
                commentTree = commentTree
            };

            return(View(commentsPage));
        }
コード例 #3
0
ファイル: Pixiv.cs プロジェクト: dreamlive0815/RazorApp
        /// <summary>
        ///
        /// </summary>
        /// <param name="illustId"></param>
        /// <param name="offset">从0开始</param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public CommentsPage GetComments(string illustId, int offset, int limit)
        {
            if (offset < 0)
            {
                offset = 0;
            }
            if (limit < 1)
            {
                limit = 1;
            }

            var url = GetCommentsUrl(illustId, offset, limit);
            var s   = _client.GetString(_client.BuildRequest(url));

            var obj = GetJObject(s);

            if (obj == null)
            {
                throw new Exception("解析插画评论集合信息时出错");
            }
            AssertOKJsonResult(obj);

            var page = new CommentsPage()
            {
                HasNext = obj.JsonPathSingle("$.body").Val <bool>("hasNext"),
                Limit   = limit.ToString(),
                Offset  = offset.ToString(),
            };

            var comments = obj.JsonPath("$.body.comments[*]");

            foreach (var comment in comments)
            {
                var emojiId       = comment.Val <string>("stampId");
                var replyToUserId = comment.Val <string>("replyToUserId");
                var c             = new Comment()
                {
                    HasReplies = comment.Val <bool>("hasReplies"),
                    Id         = comment.Val <string>("id"),
                    IsEmoji    = emojiId != null,
                    ParentId   = comment.Val <string>("commentParentId"),
                    RootId     = comment.Val <string>("commentRootId"),
                    Time       = comment.Val <string>("commentDate"),
                    Text       = comment.Val <string>("comment"),
                    User       = new User()
                    {
                        Avatar = comment.Val <string>("img"),
                        Id     = comment.Val <string>("userId"),
                        Name   = comment.Val <string>("userName"),
                    },
                };
                if (replyToUserId != null)
                {
                    c.ReplyTo = new User()
                    {
                        Id   = replyToUserId,
                        Name = comment.Val <string>("replyToUserName"),
                    }
                }
                ;
                if (c.IsEmoji)
                {
                    c.Text = emojiId;
                }
                page.Comments.Add(c);
            }

            return(page);
        }