@@ -392,12 +392,14 @@ export class ChannelService {
392392 * @param filters
393393 * @param sort
394394 * @param options
395+ * @param shouldSetActiveChannel Decides if the firs channel in the result should be made as active channel, or no channel should be marked as active
395396 * @returns the list of channels found by the query
396397 */
397398 async init (
398399 filters : ChannelFilters ,
399400 sort ?: ChannelSort ,
400- options ?: ChannelOptions
401+ options ?: ChannelOptions ,
402+ shouldSetActiveChannel : boolean = true
401403 ) {
402404 this . filters = filters ;
403405 this . options = options || {
@@ -409,7 +411,7 @@ export class ChannelService {
409411 message_limit : this . messagePageSize ,
410412 } ;
411413 this . sort = sort || { last_message_at : - 1 , updated_at : - 1 } ;
412- const result = await this . queryChannels ( ) ;
414+ const result = await this . queryChannels ( shouldSetActiveChannel ) ;
413415 this . chatClientService . notification$ . subscribe (
414416 ( notification ) => void this . handleNotification ( notification )
415417 ) ;
@@ -434,7 +436,7 @@ export class ChannelService {
434436 */
435437 async loadMoreChannels ( ) {
436438 this . options ! . offset = this . channels . length ! ;
437- await this . queryChannels ( ) ;
439+ await this . queryChannels ( false ) ;
438440 }
439441
440442 /**
@@ -950,7 +952,7 @@ export class ChannelService {
950952 this . activeChannelSubscriptions = [ ] ;
951953 }
952954
953- private async queryChannels ( ) {
955+ private async queryChannels ( shouldSetActiveChannel : boolean ) {
954956 try {
955957 const channels = await this . chatClientService . chatClient . queryChannels (
956958 this . filters ! ,
@@ -960,7 +962,11 @@ export class ChannelService {
960962 channels . forEach ( ( c ) => this . watchForChannelEvents ( c ) ) ;
961963 const prevChannels = this . channelsSubject . getValue ( ) || [ ] ;
962964 this . channelsSubject . next ( [ ...prevChannels , ...channels ] ) ;
963- if ( channels . length > 0 && ! this . activeChannelSubject . getValue ( ) ) {
965+ if (
966+ channels . length > 0 &&
967+ ! this . activeChannelSubject . getValue ( ) &&
968+ shouldSetActiveChannel
969+ ) {
964970 this . setAsActiveChannel ( channels [ 0 ] ) ;
965971 }
966972 this . hasMoreChannelsSubject . next ( channels . length >= this . options ! . limit ! ) ;
0 commit comments