Example #1
0
        public async Task <bool> refreshComments()
        {
            var newComments = await parser.refreshComments();

            if (newComments != null)
            {
                foreach (KeyValuePair <int, Comment> comment in newComments)
                {
                    var parentComment = comments.FindLast(x => x.id == comment.Key);
                    comment.Value.parentNode = parentComment;
                    parentComment.childNodes.Add(comment.Value);
                    if (comment.Key != 0)
                    {
                        int insertId;

                        if (comment.Value.parentNode.childNodes.Count != 0)
                        {
                            insertId = comments.FindLastIndex(x => x.id == comment.Value.parentNode.childNodes.Last().id) + 1;
                        }
                        else
                        {
                            insertId = comments.FindLastIndex(x => x.id == comment.Key) + 1;
                        }

                        comments.Insert(insertId, comment.Value);
                        CommentsBlock.Items.Insert(insertId, comment.Value);
                    }
                    else
                    {
                        comments.Add(comment.Value);
                        CommentsBlock.Items.Add(comment.Value);
                    }
                }
            }
            return(true);
        }