/// <summary> /// Initializes a new instance of the <see cref="CommentViewModel"/> class. /// </summary> /// <param name="commentService">The comment service</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="pullRequestId">The pull request id of the comment.</param> /// <param name="commentId">The GraphQL ID of the comment.</param> /// <param name="databaseId">The database id of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="author">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="webUrl"></param> protected CommentViewModel( ICommentService commentService, ICommentThreadViewModel thread, IActorViewModel currentUser, int pullRequestId, string commentId, int databaseId, string body, CommentEditState state, IActorViewModel author, DateTimeOffset updatedAt, Uri webUrl) { this.commentService = commentService; Guard.ArgumentNotNull(thread, nameof(thread)); Guard.ArgumentNotNull(currentUser, nameof(currentUser)); Guard.ArgumentNotNull(author, nameof(author)); Thread = thread; CurrentUser = currentUser; Id = commentId; DatabaseId = databaseId; PullRequestId = pullRequestId; Body = body; EditState = state; Author = author; UpdatedAt = updatedAt; WebUrl = webUrl; var canDeleteObservable = this.WhenAnyValue( x => x.EditState, x => x == CommentEditState.None && author.Login == currentUser.Login); canDelete = canDeleteObservable.ToProperty(this, x => x.CanDelete); Delete = ReactiveCommand.CreateAsyncTask(canDeleteObservable, DoDelete); var canEdit = this.WhenAnyValue( x => x.EditState, x => x == CommentEditState.Placeholder || (x == CommentEditState.None && author.Login == currentUser.Login)); BeginEdit = ReactiveCommand.Create(canEdit); BeginEdit.Subscribe(DoBeginEdit); AddErrorHandler(BeginEdit); CommitEdit = ReactiveCommand.CreateAsyncTask( Observable.CombineLatest( this.WhenAnyValue(x => x.IsReadOnly), this.WhenAnyValue(x => x.Body, x => !string.IsNullOrWhiteSpace(x)), this.WhenAnyObservable(x => x.Thread.PostComment.CanExecuteObservable), (readOnly, hasBody, canPost) => !readOnly && hasBody && canPost), DoCommitEdit); AddErrorHandler(CommitEdit); CancelEdit = ReactiveCommand.Create(CommitEdit.IsExecuting.Select(x => !x)); CancelEdit.Subscribe(DoCancelEdit); AddErrorHandler(CancelEdit); OpenOnGitHub = ReactiveCommand.Create(this.WhenAnyValue(x => x.Id).Select(x => x != null)); }
/// <summary> /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="commentId">The REST ID of the comment.</param> /// <param name="commentNodeId">The GraphQL ID of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="user">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="isPending">Whether this is a pending comment.</param> public PullRequestReviewCommentViewModel( IPullRequestSession session, ICommentThreadViewModel thread, IAccount currentUser, int commentId, string commentNodeId, string body, CommentEditState state, IAccount user, DateTimeOffset updatedAt, bool isPending) : base(thread, currentUser, commentId, commentNodeId, body, state, user, updatedAt) { Guard.ArgumentNotNull(session, nameof(session)); this.session = session; IsPending = isPending; canStartReview = session.WhenAnyValue(x => x.HasPendingReview, x => !x) .ToProperty(this, x => x.CanStartReview); commitCaption = session.WhenAnyValue( x => x.HasPendingReview, x => x ? Resources.AddReviewComment : Resources.AddSingleComment) .ToProperty(this, x => x.CommitCaption); StartReview = ReactiveCommand.CreateAsyncTask( CommitEdit.CanExecuteObservable, DoStartReview); AddErrorHandler(StartReview); }
/// <summary> /// Initializes a new instance of the <see cref="CommentViewModel"/> class. /// </summary> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="commentId">The ID of the comment.</param> /// <param name="commentNodeId">The GraphQL ID of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="user">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> protected CommentViewModel( ICommentThreadViewModel thread, IAccount currentUser, int commentId, string commentNodeId, string body, CommentEditState state, IAccount user, DateTimeOffset updatedAt) { Guard.ArgumentNotNull(thread, nameof(thread)); Guard.ArgumentNotNull(currentUser, nameof(currentUser)); Guard.ArgumentNotNull(body, nameof(body)); Guard.ArgumentNotNull(user, nameof(user)); Thread = thread; CurrentUser = currentUser; Id = commentId; NodeId = commentNodeId; Body = body; EditState = state; User = user; UpdatedAt = updatedAt; var canDelete = this.WhenAnyValue( x => x.EditState, x => x == CommentEditState.None && user.Login.Equals(currentUser.Login)); canDelete.ToProperty(this, x => x.CanDelete); Delete = ReactiveCommand.CreateAsyncTask(canDelete, DoDelete); var canEdit = this.WhenAnyValue( x => x.EditState, x => x == CommentEditState.Placeholder || (x == CommentEditState.None && user.Login.Equals(currentUser.Login))); BeginEdit = ReactiveCommand.Create(canEdit); BeginEdit.Subscribe(DoBeginEdit); AddErrorHandler(BeginEdit); CommitEdit = ReactiveCommand.CreateAsyncTask( Observable.CombineLatest( this.WhenAnyValue(x => x.IsReadOnly), this.WhenAnyValue(x => x.Body, x => !string.IsNullOrWhiteSpace(x)), this.WhenAnyObservable(x => x.Thread.PostComment.CanExecuteObservable), (readOnly, hasBody, canPost) => !readOnly && hasBody && canPost), DoCommitEdit); AddErrorHandler(CommitEdit); CancelEdit = ReactiveCommand.Create(CommitEdit.IsExecuting.Select(x => !x)); CancelEdit.Subscribe(DoCancelEdit); AddErrorHandler(CancelEdit); OpenOnGitHub = ReactiveCommand.Create(this.WhenAnyValue(x => x.Id, x => x != 0)); }
/// <inheritdoc/> public async Task InitializeAsync( IPullRequestSession session, ICommentThreadViewModel thread, PullRequestReviewModel review, PullRequestReviewCommentModel comment, CommentEditState state) { Guard.ArgumentNotNull(session, nameof(session)); await InitializeAsync(thread, session.User, comment, state).ConfigureAwait(true); this.session = session; IsPending = review.State == PullRequestReviewState.Pending; }
/// <summary> /// Initializes a new instance of the <see cref="CommentViewModel"/> class. /// </summary> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="commentId">The ID of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="user">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> public InlineCommentViewModel( ICommentThreadViewModel thread, IAccount currentUser, int commentId, string body, CommentEditState state, IAccount user, DateTimeOffset updatedAt, string commitSha, int diffLine) : base(thread, currentUser, commentId, body, state, user, updatedAt) { Guard.ArgumentNotNull(commitSha, nameof(commitSha)); CommitSha = commitSha; DiffLine = diffLine; }
void PlaceholderChanged(ICommentViewModel placeholder, CommentEditState state) { if (state == CommentEditState.Editing) { if (!draftThrottles.TryGetValue(placeholder, out var throttle)) { var subject = new Subject <ICommentViewModel>(); subject.Throttle(TimeSpan.FromSeconds(1), timerScheduler).Subscribe(UpdateDraft); draftThrottles.Add(placeholder, subject); throttle = subject; } throttle.OnNext(placeholder); } else if (state != CommentEditState.Editing) { DeleteDraft(placeholder).Forget(); } }
async Task <CommentViewModel> CreateAndInitializeTarget( CommentModel comment, ICommentService commentService = null, ICommentThreadViewModel thread = null, ActorModel currentUser = null, CommentEditState state = CommentEditState.Editing) { thread = thread ?? Substitute.For <ICommentThreadViewModel>(); currentUser = currentUser ?? new ActorModel { Login = "******" }; var target = CreateTarget(commentService); await target.InitializeAsync( thread, currentUser, comment, state); return(target); }
/// <summary> /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="commentService">The comment service</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="pullRequestId">The pull request id of the comment.</param> /// <param name="commentId">The GraphQL ID of the comment.</param> /// <param name="databaseId">The database id of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="author">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="isPending">Whether this is a pending comment.</param> /// <param name="webUrl"></param> public PullRequestReviewCommentViewModel( IPullRequestSession session, ICommentService commentService, ICommentThreadViewModel thread, IActorViewModel currentUser, int pullRequestId, string commentId, int databaseId, string body, CommentEditState state, IActorViewModel author, DateTimeOffset updatedAt, bool isPending, Uri webUrl) : base(commentService, thread, currentUser, pullRequestId, commentId, databaseId, body, state, author, updatedAt, webUrl) { Guard.ArgumentNotNull(session, nameof(session)); this.session = session; IsPending = isPending; var pendingReviewAndIdObservable = Observable.CombineLatest( session.WhenAnyValue(x => x.HasPendingReview, x => !x), this.WhenAnyValue(model => model.Id).Select(i => i == null), (hasPendingReview, isNewComment) => new { hasPendingReview, isNewComment }); canStartReview = pendingReviewAndIdObservable .Select(arg => arg.hasPendingReview && arg.isNewComment) .ToProperty(this, x => x.CanStartReview); commitCaption = pendingReviewAndIdObservable .Select(arg => !arg.isNewComment ? Resources.UpdateComment : arg.hasPendingReview ? Resources.AddSingleComment : Resources.AddReviewComment) .ToProperty(this, x => x.CommitCaption); StartReview = ReactiveCommand.CreateAsyncTask( CommitEdit.CanExecuteObservable, DoStartReview); AddErrorHandler(StartReview); }
public Task InitializeAsync(ICommentThreadViewModel thread, ActorModel currentUser, CommentModel comment, CommentEditState state) { return(Task.CompletedTask); }