11using System ;
22using System . Collections . Generic ;
33using System . ComponentModel . Composition ;
4+ using System . Reactive ;
45using System . Threading . Tasks ;
56using GitHub . Extensions ;
67using GitHub . Factories ;
@@ -19,7 +20,9 @@ namespace GitHub.ViewModels.Documents
1920 public class PullRequestPageViewModel : PullRequestViewModelBase , IPullRequestPageViewModel , ICommentThreadViewModel
2021 {
2122 readonly IViewViewModelFactory factory ;
23+ readonly IPullRequestService service ;
2224 readonly IPullRequestSessionManager sessionManager ;
25+ readonly ITeamExplorerServices teServices ;
2326
2427 /// <summary>
2528 /// Initializes a new instance of the <see cref="PullRequestPageViewModel"/> class.
@@ -28,13 +31,21 @@ public class PullRequestPageViewModel : PullRequestViewModelBase, IPullRequestPa
2831 [ ImportingConstructor ]
2932 public PullRequestPageViewModel (
3033 IViewViewModelFactory factory ,
31- IPullRequestSessionManager sessionManager )
34+ IPullRequestService service ,
35+ IPullRequestSessionManager sessionManager ,
36+ ITeamExplorerServices teServices )
3237 {
3338 Guard . ArgumentNotNull ( factory , nameof ( factory ) ) ;
39+ Guard . ArgumentNotNull ( service , nameof ( service ) ) ;
3440 Guard . ArgumentNotNull ( sessionManager , nameof ( sessionManager ) ) ;
41+ Guard . ArgumentNotNull ( teServices , nameof ( teServices ) ) ;
3542
3643 this . factory = factory ;
44+ this . service = service ;
3745 this . sessionManager = sessionManager ;
46+ this . teServices = teServices ;
47+
48+ ShowCommit = ReactiveCommand . CreateFromTask < string > ( DoShowCommit ) ;
3849 }
3950
4051 /// <inheritdoc/>
@@ -43,15 +54,20 @@ public PullRequestPageViewModel(
4354 /// <inheritdoc/>
4455 public IReadOnlyList < IViewModel > Timeline { get ; private set ; }
4556
57+ /// <inheritdoc/>
58+ public ReactiveCommand < string , Unit > ShowCommit { get ; }
59+
4660 /// <inheritdoc/>
4761 IReadOnlyReactiveList < ICommentViewModel > ICommentThreadViewModel . Comments => throw new NotImplementedException ( ) ;
4862
4963 /// <inheritdoc/>
5064 public async Task InitializeAsync (
65+ IRemoteRepositoryModel repository ,
66+ ILocalRepositoryModel localRepository ,
5167 ActorModel currentUser ,
5268 PullRequestDetailModel model )
5369 {
54- await base . InitializeAsync ( model ) . ConfigureAwait ( true ) ;
70+ await base . InitializeAsync ( repository , localRepository , model ) . ConfigureAwait ( true ) ;
5571
5672 CurrentUser = new ActorViewModel ( currentUser ) ;
5773
@@ -72,9 +88,11 @@ public async Task InitializeAsync(
7288 commits . Add ( new CommitSummaryViewModel ( commit ) ) ;
7389 break ;
7490 case CommentModel comment :
75- var vm = factory . CreateViewModel < ICommentViewModel > ( ) ;
76- await vm . InitializeAsync ( this , currentUser , comment , CommentEditState . None ) . ConfigureAwait ( true ) ;
77- timeline . Add ( vm ) ;
91+ {
92+ var vm = factory . CreateViewModel < ICommentViewModel > ( ) ;
93+ await vm . InitializeAsync ( this , currentUser , comment , CommentEditState . None ) . ConfigureAwait ( true ) ;
94+ timeline . Add ( vm ) ;
95+ }
7896 break ;
7997 }
8098 }
@@ -101,5 +119,11 @@ Task ICommentThreadViewModel.PostComment(string body)
101119 {
102120 throw new NotImplementedException ( ) ;
103121 }
122+
123+ async Task DoShowCommit ( string oid )
124+ {
125+ await service . FetchCommit ( LocalRepository , Repository , oid ) . ConfigureAwait ( true ) ;
126+ teServices . ShowCommitDetails ( oid ) ;
127+ }
104128 }
105129}
0 commit comments