@@ -68,13 +68,22 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
6868
6969 Observable . CombineLatest (
7070 modelService . GetAccounts ( ) ,
71+ modelService . GetRepository ( repository . Owner , repository . Name ) ,
7172 modelService . GetForks ( repository ) . ToList ( ) ,
72- ( a , f ) => new { Accounts = a , Forks = f } )
73+ ( a , r , f ) => new { Accounts = a , Respoitory = r , Forks = f } )
7374 . Finally ( ( ) => IsLoading = false )
7475 . Subscribe ( x =>
7576 {
76- Accounts = BuildAccounts ( x . Accounts , x . Forks , repository . Owner ) ;
77- ExistingForks = BuildExistingForks ( x . Accounts , x . Forks ) ;
77+ var forksAndParents = new List < IRemoteRepositoryModel > ( x . Forks ) ;
78+ var current = x . Respoitory ;
79+ while ( current . Parent != null )
80+ {
81+ forksAndParents . Add ( current . Parent ) ;
82+ current = current . Parent ;
83+ }
84+
85+ Accounts = BuildAccounts ( x . Accounts , forksAndParents , repository . Owner ) ;
86+ ExistingForks = forksAndParents ;
7887
7988 log . Verbose ( "Loaded Data Accounts:{Accounts} Forks:{Forks}" , Accounts . Count , ExistingForks . Count ) ;
8089 } ) ;
@@ -87,18 +96,12 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
8796 }
8897 }
8998
90- IReadOnlyList < IAccount > BuildAccounts ( IReadOnlyList < IAccount > accounts , IList < IRemoteRepositoryModel > forks , string currentRepositoryOwner )
99+ IReadOnlyList < IAccount > BuildAccounts ( IEnumerable < IAccount > accessibleAccounts , IList < IRemoteRepositoryModel > forksAndParents , string currentRepositoryOwner )
91100 {
92- var forksByOwner = forks . ToDictionary ( x => x . Owner , x => x ) ;
93- return accounts
101+ var forksByOwner = forksAndParents . ToDictionary ( x => x . Owner , x => x ) ;
102+ return accessibleAccounts
94103 . Where ( x => x . Login != currentRepositoryOwner )
95104 . Where ( x => ! forksByOwner . ContainsKey ( x . Login ) ) . ToList ( ) ;
96105 }
97-
98- IReadOnlyList < IRemoteRepositoryModel > BuildExistingForks ( IReadOnlyList < IAccount > accounts , IList < IRemoteRepositoryModel > forks )
99- {
100- var accountsByLogin = accounts . ToDictionary ( x => x . Login , x => x ) ;
101- return forks . Where ( x => accountsByLogin . ContainsKey ( x . Owner ) ) . ToList ( ) ;
102- }
103106 }
104107}
0 commit comments