/// <summary> /// Initializes a new instance of the <see cref="InlineCommentThreadViewModel"/> class. /// </summary> /// <param name="session">The current PR review session.</param> /// <param name="comments">The comments to display in this inline review.</param> public InlineCommentThreadViewModel( IPullRequestSession session, IEnumerable <IPullRequestReviewCommentModel> comments) : base(session.User) { Guard.ArgumentNotNull(session, nameof(session)); Session = session; PostComment = ReactiveCommand.CreateAsyncTask( Observable.Return(true), DoPostComment); EditComment = ReactiveCommand.CreateAsyncTask( Observable.Return(true), DoEditComment); DeleteComment = ReactiveCommand.CreateAsyncTask( Observable.Return(true), DoDeleteComment); foreach (var comment in comments) { Comments.Add(new PullRequestReviewCommentViewModel(session, this, CurrentUser, comment)); } Comments.Add(PullRequestReviewCommentViewModel.CreatePlaceholder(session, this, CurrentUser)); }
/// <summary> /// Initializes a new instance of the <see cref="InlineCommentThreadViewModel"/> class. /// </summary> /// <param name="commentService">The comment service</param> /// <param name="session">The current PR review session.</param> /// <param name="comments">The comments to display in this inline review.</param> public InlineCommentThreadViewModel(ICommentService commentService, IPullRequestSession session, IEnumerable <InlineCommentModel> comments) : base(session.User) { Guard.ArgumentNotNull(session, nameof(session)); Session = session; PostComment = ReactiveCommand.CreateFromTask <string>(DoPostComment); EditComment = ReactiveCommand.CreateFromTask <Tuple <string, string> >(DoEditComment); DeleteComment = ReactiveCommand.CreateFromTask <Tuple <int, int> >(DoDeleteComment); foreach (var comment in comments) { Comments.Add(new PullRequestReviewCommentViewModel( session, commentService, this, CurrentUser, comment.Review, comment.Comment)); } Comments.Add(PullRequestReviewCommentViewModel.CreatePlaceholder(session, commentService, this, CurrentUser)); }
/// <summary> /// Initializes a new instance of the <see cref="InlineCommentThreadViewModel"/> class. /// </summary> /// <param name="session">The current PR review session.</param> /// <param name="file">The file being commented on.</param> /// <param name="lineNumber">The 0-based line number in the file.</param> /// <param name="leftComparisonBuffer"> /// True if the comment is being left on the left-hand-side of a diff; otherwise false. /// </param> public NewInlineCommentThreadViewModel( IPullRequestSession session, IPullRequestSessionFile file, int lineNumber, bool leftComparisonBuffer) : base(session.User) { Guard.ArgumentNotNull(session, nameof(session)); Guard.ArgumentNotNull(file, nameof(file)); Session = session; File = file; LineNumber = lineNumber; LeftComparisonBuffer = leftComparisonBuffer; PostComment = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.NeedsPush, x => !x), DoPostComment); EditComment = ReactiveCommand.CreateAsyncTask <Unit>( Observable.Return(false), o => null); DeleteComment = ReactiveCommand.CreateAsyncTask <Unit>( Observable.Return(false), o => null); var placeholder = PullRequestReviewCommentViewModel.CreatePlaceholder(session, this, CurrentUser); placeholder.BeginEdit.Execute(null); this.WhenAnyValue(x => x.NeedsPush).Subscribe(x => placeholder.IsReadOnly = x); Comments.Add(placeholder); file.WhenAnyValue(x => x.CommitSha).Subscribe(x => NeedsPush = x == null); }
/// <summary> /// Initializes a new instance of the <see cref="InlineCommentThreadViewModel"/> class. /// </summary> /// <param name="commentService">The comment service</param> /// <param name="session">The current PR review session.</param> /// <param name="file">The file being commented on.</param> /// <param name="lineNumber">The 0-based line number in the file.</param> /// <param name="leftComparisonBuffer"> /// True if the comment is being left on the left-hand-side of a diff; otherwise false. /// </param> public NewInlineCommentThreadViewModel(ICommentService commentService, IPullRequestSession session, IPullRequestSessionFile file, int lineNumber, bool leftComparisonBuffer) : base(session.User) { Guard.ArgumentNotNull(session, nameof(session)); Guard.ArgumentNotNull(file, nameof(file)); Session = session; File = file; LineNumber = lineNumber; LeftComparisonBuffer = leftComparisonBuffer; PostComment = ReactiveCommand.CreateFromTask <string>( DoPostComment, this.WhenAnyValue(x => x.NeedsPush, x => !x)); EditComment = ReactiveCommand.Create <Tuple <string, string> >(_ => { }); DeleteComment = ReactiveCommand.Create <Tuple <int, int> >(_ => { }); var placeholder = PullRequestReviewCommentViewModel.CreatePlaceholder(session, commentService, this, CurrentUser); placeholder.BeginEdit.Execute().Subscribe(); this.WhenAnyValue(x => x.NeedsPush).Subscribe(x => placeholder.IsReadOnly = x); Comments.Add(placeholder); file.WhenAnyValue(x => x.CommitSha).Subscribe(x => NeedsPush = x == null); }