/// <summary> /// Initializes a new instance of the <see cref="InlineCommentPeekViewModel"/> class. /// </summary> public InlineCommentPeekViewModel( IInlineCommentPeekService peekService, IPeekSession peekSession, IPullRequestSessionManager sessionManager, INextInlineCommentCommand nextCommentCommand, IPreviousInlineCommentCommand previousCommentCommand) { Guard.ArgumentNotNull(peekService, nameof(peekService)); Guard.ArgumentNotNull(peekSession, nameof(peekSession)); Guard.ArgumentNotNull(sessionManager, nameof(sessionManager)); Guard.ArgumentNotNull(nextCommentCommand, nameof(nextCommentCommand)); Guard.ArgumentNotNull(previousCommentCommand, nameof(previousCommentCommand)); this.peekService = peekService; this.peekSession = peekSession; this.sessionManager = sessionManager; triggerPoint = peekSession.GetTriggerPoint(peekSession.TextView.TextBuffer); peekSession.Dismissed += (s, e) => Dispose(); NextComment = ReactiveCommand.CreateAsyncTask( Observable.Return(nextCommentCommand.Enabled), _ => nextCommentCommand.Execute(new InlineCommentNavigationParams { FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1, })); PreviousComment = ReactiveCommand.CreateAsyncTask( Observable.Return(previousCommentCommand.Enabled), _ => previousCommentCommand.Execute(new InlineCommentNavigationParams { FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1, })); }
async void LinesChanged(IReadOnlyList <Tuple <int, DiffSide> > lines) { try { var lineNumber = peekService.GetLineNumber(peekSession, triggerPoint).Item1; if (lines.Contains(Tuple.Create(lineNumber, side))) { await UpdateThread(); } } catch (Exception e) { log.Error(e, "Error updating InlineCommentViewModel"); } }
/// <summary> /// Initializes a new instance of the <see cref="InlineCommentPeekViewModel"/> class. /// </summary> public InlineCommentPeekViewModel(IInlineCommentPeekService peekService, IPeekSession peekSession, IPullRequestSessionManager sessionManager, INextInlineCommentCommand nextCommentCommand, IPreviousInlineCommentCommand previousCommentCommand, IViewViewModelFactory factory) { Guard.ArgumentNotNull(peekService, nameof(peekService)); Guard.ArgumentNotNull(peekSession, nameof(peekSession)); Guard.ArgumentNotNull(sessionManager, nameof(sessionManager)); Guard.ArgumentNotNull(nextCommentCommand, nameof(nextCommentCommand)); Guard.ArgumentNotNull(previousCommentCommand, nameof(previousCommentCommand)); Guard.ArgumentNotNull(factory, nameof(factory)); this.peekService = peekService; this.peekSession = peekSession; this.sessionManager = sessionManager; this.factory = factory; triggerPoint = peekSession.GetTriggerPoint(peekSession.TextView.TextBuffer); peekSession.Dismissed += (s, e) => Dispose(); Close = this.WhenAnyValue(x => x.Thread) .Where(x => x != null) .SelectMany(x => x.IsNewThread ? x.Comments.Single().CancelEdit.SelectUnit() : Observable.Never <Unit>()); NextComment = ReactiveCommand.CreateFromTask( () => nextCommentCommand.Execute(new InlineCommentNavigationParams { FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1, }), Observable.Return(nextCommentCommand.Enabled)); PreviousComment = ReactiveCommand.CreateFromTask( () => previousCommentCommand.Execute(new InlineCommentNavigationParams { FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1, }), Observable.Return(previousCommentCommand.Enabled)); }
async Task UpdateThread() { var placeholderBody = await GetPlaceholderBodyToPreserve(); Thread = null; threadSubscription?.Dispose(); if (file == null) { return; } var lineAndLeftBuffer = peekService.GetLineNumber(peekSession, triggerPoint); var lineNumber = lineAndLeftBuffer.Item1; var leftBuffer = lineAndLeftBuffer.Item2; var thread = file.InlineCommentThreads.FirstOrDefault(x => x.LineNumber == lineNumber && ((leftBuffer && x.DiffLineType == DiffChangeType.Delete) || (!leftBuffer && x.DiffLineType != DiffChangeType.Delete))); var apiClient = await CreateApiClient(session.LocalRepository); if (thread != null) { Thread = new InlineCommentThreadViewModel(apiClient, session, thread.Comments); } else { var newThread = new NewInlineCommentThreadViewModel(apiClient, session, file, lineNumber, leftBuffer); threadSubscription = newThread.Finished.Subscribe(_ => UpdateThread().Forget()); Thread = newThread; } if (!string.IsNullOrWhiteSpace(placeholderBody)) { var placeholder = Thread.Comments.LastOrDefault(); if (placeholder?.EditState == CommentEditState.Placeholder) { await placeholder.BeginEdit.ExecuteAsync(null); placeholder.Body = placeholderBody; } } }