11using System ;
22using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Reactive . Linq ;
53using GitHub . Extensions ;
64using GitHub . Logging ;
75using GitHub . Models ;
86using GitHub . Services ;
7+ using ReactiveUI ;
98using Serilog ;
109
1110namespace GitHub . ViewModels . GitHubPane
@@ -19,44 +18,38 @@ public class PullRequestReviewViewModel : ViewModelBase, IPullRequestReviewViewM
1918
2019 readonly IPullRequestEditorService editorService ;
2120 readonly IPullRequestSession session ;
21+ bool isExpanded ;
2222
2323 /// <summary>
2424 /// Initializes a new instance of the <see cref="PullRequestReviewViewModel"/> class.
2525 /// </summary>
26- /// <param name="localRepository ">The local repository .</param>
27- /// <param name="owner ">The pull request's repository owner .</param>
26+ /// <param name="editorService ">The pull request editor service .</param>
27+ /// <param name="session ">The pull request session .</param>
2828 /// <param name="pullRequest">The pull request model.</param>
29- /// <param name="pullRequestReviewId ">The pull request review ID .</param>
29+ /// <param name="model ">The pull request review model .</param>
3030 public PullRequestReviewViewModel (
3131 IPullRequestEditorService editorService ,
3232 IPullRequestSession session ,
33- ILocalRepositoryModel localRepository ,
34- string owner ,
3533 IPullRequestModel pullRequest ,
36- long pullRequestReviewId )
34+ IPullRequestReviewModel model )
3735 {
3836 Guard . ArgumentNotNull ( editorService , nameof ( editorService ) ) ;
3937 Guard . ArgumentNotNull ( session , nameof ( session ) ) ;
40- Guard . ArgumentNotNull ( localRepository , nameof ( localRepository ) ) ;
41- Guard . ArgumentNotNull ( owner , nameof ( owner ) ) ;
42- Guard . ArgumentNotNull ( pullRequest , nameof ( pullRequest ) ) ;
38+ Guard . ArgumentNotNull ( model , nameof ( model ) ) ;
4339
4440 this . editorService = editorService ;
4541 this . session = session ;
4642
47- LocalRepository = localRepository ;
48- RemoteRepositoryOwner = owner ;
49- Model = GetModel ( pullRequest , pullRequestReviewId ) ;
50- PullRequestModel = pullRequest ;
43+ Model = model ;
5144 Body = string . IsNullOrWhiteSpace ( Model . Body ) ? null : Model . Body ;
5245 StateDisplay = ToString ( Model . State ) ;
5346
5447 var comments = new List < IPullRequestReviewFileCommentViewModel > ( ) ;
5548 var outdated = new List < IPullRequestReviewFileCommentViewModel > ( ) ;
5649
57- foreach ( var comment in PullRequestModel . ReviewComments )
50+ foreach ( var comment in pullRequest . ReviewComments )
5851 {
59- if ( comment . PullRequestReviewId == pullRequestReviewId )
52+ if ( comment . PullRequestReviewId == model . Id )
6053 {
6154 var vm = new PullRequestReviewFileCommentViewModel (
6255 editorService ,
@@ -76,29 +69,23 @@ public PullRequestReviewViewModel(
7669 HasDetails = Body != null ||
7770 FileComments . Count > 0 ||
7871 OutdatedFileComments . Count > 0 ;
79- IsExpanded = HasDetails && CalculateIsLatest ( pullRequest , Model ) ;
8072 }
8173
82- /// <inheritdoc/>
83- public ILocalRepositoryModel LocalRepository { get ; private set ; }
84-
85- /// <inheritdoc/>
86- public string RemoteRepositoryOwner { get ; private set ; }
87-
8874 /// <inheritdoc/>
8975 public IPullRequestReviewModel Model { get ; }
9076
91- /// <inheritdoc/>
92- public IPullRequestModel PullRequestModel { get ; }
93-
9477 /// <inheritdoc/>
9578 public string Body { get ; }
9679
9780 /// <inheritdoc/>
9881 public string StateDisplay { get ; }
9982
10083 /// <inheritdoc/>
101- public bool IsExpanded { get ; }
84+ public bool IsExpanded
85+ {
86+ get { return isExpanded ; }
87+ set { this . RaiseAndSetIfChanged ( ref isExpanded , value ) ; }
88+ }
10289
10390 /// <inheritdoc/>
10491 public bool HasDetails { get ; }
@@ -109,26 +96,6 @@ public PullRequestReviewViewModel(
10996 /// <inheritdoc/>
11097 public IReadOnlyList < IPullRequestReviewFileCommentViewModel > OutdatedFileComments { get ; }
11198
112- static bool CalculateIsLatest ( IPullRequestModel pullRequest , IPullRequestReviewModel model )
113- {
114- return ! pullRequest . Reviews . Any ( x =>
115- x . User . Login == model . User . Login &&
116- x . SubmittedAt > model . SubmittedAt ) ;
117- }
118-
119- static IPullRequestReviewModel GetModel ( IPullRequestModel pullRequest , long pullRequestReviewId )
120- {
121- var result = pullRequest . Reviews . FirstOrDefault ( x => x . Id == pullRequestReviewId ) ;
122-
123- if ( result == null )
124- {
125- throw new KeyNotFoundException (
126- $ "Unable to find review { pullRequestReviewId } in pull request #{ pullRequest . Number } ") ;
127- }
128-
129- return result ;
130- }
131-
13299 static string ToString ( PullRequestReviewState state )
133100 {
134101 switch ( state )
0 commit comments