@@ -15,7 +15,8 @@ import {
1515 MgtTemplatedComponent ,
1616 BetaGraph ,
1717 customElement ,
18- mgtHtml
18+ mgtHtml ,
19+ CollectionResponse
1920} from '@microsoft/mgt-element' ;
2021import '../../styles/style-helper' ;
2122import '../sub-components/mgt-spinner/mgt-spinner' ;
@@ -142,22 +143,6 @@ interface ChannelPickerItemState {
142143 parent : ChannelPickerItemState ;
143144}
144145
145- /**
146- * Configuration object for the TeamsChannelPicker component
147- *
148- * @export
149- * @interface MgtTeamsChannelPickerConfig
150- */
151- export interface MgtTeamsChannelPickerConfig {
152- /**
153- * Sets or gets whether the teams channel picker component should use
154- * the Teams based scopes instead of the User and Group based scopes
155- *
156- * @type {boolean }
157- */
158- useTeamsBasedScopes : boolean ;
159- }
160-
161146/**
162147 * Web component used to select channels from a User's Microsoft Teams profile
163148 *
@@ -209,21 +194,6 @@ export class MgtTeamsChannelPicker extends MgtTemplatedComponent {
209194 return strings ;
210195 }
211196
212- /**
213- * Global Configuration object for all
214- * teams channel picker components
215- *
216- * @static
217- * @type {MgtTeamsChannelPickerConfig }
218- * @memberof MgtTeamsChannelPicker
219- */
220- public static get config ( ) : MgtTeamsChannelPickerConfig {
221- return this . _config ;
222- }
223-
224- private static readonly _config = {
225- useTeamsBasedScopes : false
226- } ;
227197 private teamsPhotos = { } ;
228198
229199 /**
@@ -249,11 +219,7 @@ export class MgtTeamsChannelPicker extends MgtTemplatedComponent {
249219 * @memberof MgtTeamsChannelPicker
250220 */
251221 public static get requiredScopes ( ) : string [ ] {
252- if ( this . config . useTeamsBasedScopes ) {
253- return [ 'team.readbasic.all' , 'channel.readbasic.all' ] ;
254- } else {
255- return [ 'user.read.all' , 'group.read.all' ] ;
256- }
222+ return [ 'team.readbasic.all' , 'channel.readbasic.all' ] ;
257223 }
258224
259225 private set items ( value ) {
@@ -695,49 +661,31 @@ export class MgtTeamsChannelPicker extends MgtTemplatedComponent {
695661 if ( provider && provider . state === ProviderState . SignedIn ) {
696662 const graph = provider . graph . forComponent ( this ) ;
697663
698- // make sure we have the needed scopes
699- if ( ! ( await provider . getAccessTokenForScopes ( ...MgtTeamsChannelPicker . requiredScopes ) ) ) {
700- return ;
701- }
702-
703- teams = await getAllMyTeams ( graph ) ;
664+ teams = await getAllMyTeams ( graph , MgtTeamsChannelPicker . requiredScopes ) ;
704665 teams = teams . filter ( t => ! t . isArchived ) ;
705666
706- const teamsIds = teams . map ( t => t . id ) ;
707-
708667 const beta = BetaGraph . fromGraph ( graph ) ;
709668
669+ const teamsIds = teams . map ( t => t . id ) ;
710670 this . teamsPhotos = await getTeamsPhotosforPhotoIds ( beta , teamsIds ) ;
711671
712- const batch = graph . createBatch ( ) ;
713- const scopes = [ 'team.readbasic.all' ] ;
672+ const batch = graph . createBatch < CollectionResponse < MicrosoftGraph . Channel > > ( ) ;
714673
715674 for ( const team of teams ) {
716- batch . get ( team . id , `teams/${ team . id } /channels` , scopes ) ;
675+ batch . get ( team . id , `teams/${ team . id } /channels` , MgtTeamsChannelPicker . requiredScopes ) ;
717676 }
718677
719678 const responses = await batch . executeAll ( ) ;
720-
679+ this . _items = [ ] ;
721680 for ( const team of teams ) {
722- const response = responses . get ( team . id ) ;
723-
724- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
725- if ( response ?. content ?. value ) {
726- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
727- team . channels = response . content . value . map ( ( c : MicrosoftGraph . Team ) => {
728- return {
729- item : c
730- } ;
731- } ) ;
732- }
681+ const channelsForTeam = responses . get ( team . id ) ;
682+ // skip over any teams that don't have channels
683+ if ( ! channelsForTeam . content ?. value ?. length ) continue ;
684+ this . items . push ( {
685+ item : team ,
686+ channels : channelsForTeam . content . value . map ( c => ( { item : c } ) )
687+ } ) ;
733688 }
734-
735- this . items = teams . map ( t => {
736- return {
737- channels : t . channels as DropdownItem [ ] ,
738- item : t
739- } ;
740- } ) ;
741689 }
742690 this . filterList ( ) ;
743691 this . resetFocusState ( ) ;
0 commit comments