Ejemplo n.º 1
0
        private CommentShell MakeCommentShell(Comment comment, int depth, CommentShell priorSibling)
        {
            var result = new CommentShell
            {
                Comment = new CommentViewModel(this, comment, comment.LinkId, depth),
				Id = comment.Id,
                Parent = comment.ParentId.StartsWith("t1_") ? comment.ParentId.Substring("t1_".Length) : null,
                PriorSibling = priorSibling != null ? priorSibling.Id : null,
                InsertionWaveIndex = _commentOriginStack.Count - 1,
                OriginType = _commentOriginStack.Last()
            };
            return result;
        }
Ejemplo n.º 2
0
 private void MergeComment(CommentShell priorSibling, Comment thingData)
 {
     priorSibling.OriginType = CommentOriginType.Edited;
     priorSibling.InsertionWaveIndex = _commentOriginStack.Count - 1;
     priorSibling.Comment.Thing = thingData;
 }
Ejemplo n.º 3
0
 private CommentShell LastSibling(CommentShell shell)
 {
     var currentShell = shell;
     while (currentShell.NextSibling != null)
     {
         //this is the end as far as we're concerned
         CommentShell tmpShell;
         if (!_comments.TryGetValue(currentShell.NextSibling, out tmpShell))
         {
             return tmpShell;
         }
         else
             currentShell = tmpShell;
     }
     return null;
 }
Ejemplo n.º 4
0
        private void MergeComments(CommentShell parent, IEnumerable<Thing> things, int depth = 0)
        {
            CommentShell priorSibling = parent != null ? LastChild(parent) : null;
			MoreViewModel priorMore = null;
            foreach (var child in things)
            {
				if(child.Data is More && ((More)child.Data).Children.Count > 0)
                {
					if(priorMore != null)
					{
						priorMore.Ids.AddRange(((More)child.Data).Children);
						priorMore.Count += ((More)child.Data).Count;
					}
					else
					{
						var firstId = ((More)child.Data).Children.First();
						if (priorSibling == null) //need to attach to parent
						{
							parent.FirstChild = firstId;
						}
						else
						{
							priorSibling.NextSibling = firstId;
						}
						if (!_knownUnloaded.ContainsKey(firstId))
						{
							priorMore = new MoreViewModel(this, parent != null ? parent.Id : null, firstId, ((More)child.Data).Children,((More)child.Data).Count, depth );
							_knownUnloaded.Add(firstId, priorMore);
						}
					}
                }
                else if (child.Data is Comment)
                {
					priorMore = null;
                    var commentId = ((Comment)child.Data).Id;

                    if (priorSibling == null && parent == null)
                    {
                        if (_firstChild != null)
                        {
                            priorSibling = LastSibling(_comments[_firstChild]);
                        }
                        else
                        {
                            _firstChild = commentId;
                        }
                    }


                    if (priorSibling == null && parent != null) //need to attach to parent
                    {
                        parent.FirstChild = commentId;
                    }
                    else if (priorSibling != null)
                    {
                        priorSibling.NextSibling = commentId;
                    }

                    if (!_comments.ContainsKey(commentId))
                    {
                        priorSibling = MakeCommentShell(child.Data as Comment, depth, priorSibling);
                        _comments.Add(commentId, priorSibling);
                    }
                    else
                    {
                        var current = _comments[commentId];
                        current.PriorSibling = priorSibling != null ? priorSibling.Id : null;
                        current.NextSibling = null;
                        priorSibling = current;
                        MergeComment(priorSibling, child.Data as Comment);
                    }

                    var replies = ((Comment)child.Data).Replies;
                    if (replies != null)
                        MergeComments(priorSibling, replies.Data.Children, depth + 1);
                }
            }
        }
Ejemplo n.º 5
0
 private CommentShell LastChild(CommentShell shell)
 {
     if (shell.FirstChild != null)
     {
         CommentShell currentShell;
         if (_comments.TryGetValue(shell.FirstChild, out currentShell))
         {
             return LastSibling(currentShell);
         }
     }
     return null;
 }