@@ -20,8 +20,8 @@ const organizationsCacheExpiration = 24 * 60 * 60 * 1000; // 1 day
2020export class OrganizationService implements Disposable {
2121 private _disposable : Disposable ;
2222 private _organizations : Organization [ ] | null | undefined ;
23- private _fullOrganizations : Map < FullOrganization [ 'id' ] , FullOrganization > | undefined ;
2423 private _organizationSettings : Map < FullOrganization [ 'id' ] , OrganizationSettings > | undefined ;
24+ private _organizationMembers : Map < Organization [ 'id' ] , OrganizationMember [ ] > | undefined ;
2525
2626 constructor (
2727 private readonly container : Container ,
@@ -147,43 +147,34 @@ export class OrganizationService implements Disposable {
147147 }
148148
149149 @gate ( )
150- private async getFullOrganization (
151- id : string ,
152- options ?: { force ?: boolean } ,
153- ) : Promise < FullOrganization | undefined > {
154- if ( ! this . _fullOrganizations ?. has ( id ) || options ?. force === true ) {
155- const rsp = await this . connection . fetchGkApi ( `organization/${ id } ` , { method : 'GET' } ) ;
150+ async getMembers ( id ?: string | undefined , options ?: { force ?: boolean } ) : Promise < OrganizationMember [ ] > {
151+ if ( id == null ) {
152+ id = await this . getActiveOrganizationId ( ) ;
153+ if ( id == null ) return [ ] ;
154+ }
155+
156+ if ( ! this . _organizationMembers ?. has ( id ) || options ?. force === true ) {
157+ type MemberResponse = {
158+ members : OrganizationMember [ ] ;
159+ } ;
160+ const rsp = await this . connection . fetchGkApi ( `organization/${ id } /members` , { method : 'GET' } ) ;
156161 if ( ! rsp . ok ) {
157162 Logger . error (
158163 '' ,
159164 getLogScope ( ) ,
160- `Unable to get organization; status=(${ rsp . status } ): ${ rsp . statusText } ` ,
165+ `Unable to get organization members ; status=(${ rsp . status } ): ${ rsp . statusText } ` ,
161166 ) ;
162- return undefined ;
167+ return [ ] ;
163168 }
164169
165- const organization = ( await rsp . json ( ) ) as FullOrganization ;
166- if ( this . _fullOrganizations == null ) {
167- this . _fullOrganizations = new Map ( ) ;
168- }
169- organization . members . sort ( ( a , b ) => ( a . name ?? a . username ) . localeCompare ( b . name ?? b . username ) ) ;
170- this . _fullOrganizations . set ( id , organization ) ;
171- }
172- return this . _fullOrganizations . get ( id ) ;
173- }
170+ const members : OrganizationMember [ ] = ( ( await rsp . json ( ) ) as MemberResponse ) . members ;
171+ sortOrgMembers ( members ) ;
174172
175- @gate ( )
176- async getMembers (
177- organizationId ?: string | undefined ,
178- options ?: { force ?: boolean } ,
179- ) : Promise < OrganizationMember [ ] > {
180- if ( organizationId == null ) {
181- organizationId = await this . getActiveOrganizationId ( ) ;
182- if ( organizationId == null ) return [ ] ;
173+ this . _organizationMembers ??= new Map ( ) ;
174+ this . _organizationMembers . set ( id , members ) ;
183175 }
184176
185- const organization = await this . getFullOrganization ( organizationId , options ) ;
186- return organization ?. members ?? [ ] ;
177+ return this . _organizationMembers . get ( id ) ?? [ ] ;
187178 }
188179
189180 async getMemberById ( id : string , organizationId : string ) : Promise < OrganizationMember | undefined > {
@@ -245,3 +236,7 @@ export class OrganizationService implements Disposable {
245236 return this . _organizationSettings . get ( id ) ;
246237 }
247238}
239+
240+ function sortOrgMembers ( members : OrganizationMember [ ] ) : OrganizationMember [ ] {
241+ return members . sort ( ( a , b ) => ( a . name ?? a . username ) . localeCompare ( b . name ?? b . username ) ) ;
242+ }
0 commit comments