@@ -307,6 +307,12 @@ export class ChannelService {
307307 beforeUpdateMessage ?: (
308308 message : StreamMessage
309309 ) => StreamMessage | Promise < StreamMessage > ;
310+ /**
311+ * Since switching channels changes the state of multiple obserables, this observable can be used to check if all observables are updated.
312+ * - `end` means all observables are in stable state
313+ * - `start` means all observables are in unstable state
314+ */
315+ channelSwitchState$ : Observable < 'start' | 'end' > ;
310316 /**
311317 * @internal
312318 */
@@ -357,6 +363,9 @@ export class ChannelService {
357363 private channelQueryStateSubject = new BehaviorSubject <
358364 ChannelQueryState | undefined
359365 > ( undefined ) ;
366+ private channelSwitchStateSubject = new BehaviorSubject < 'start' | 'end' > (
367+ 'end'
368+ ) ;
360369 private channelQuery ?:
361370 | ChannelQuery
362371 | ( ( queryType : ChannelQueryType ) => Promise < ChannelQueryResult > ) ;
@@ -511,6 +520,9 @@ export class ChannelService {
511520 this . channelQueryState$ = this . channelQueryStateSubject
512521 . asObservable ( )
513522 . pipe ( shareReplay ( 1 ) ) ;
523+ this . channelSwitchState$ = this . channelSwitchStateSubject
524+ . asObservable ( )
525+ . pipe ( shareReplay ( 1 ) ) ;
514526 }
515527
516528 /**
@@ -557,6 +569,7 @@ export class ChannelService {
557569 * @param channel
558570 */
559571 setAsActiveChannel ( channel : Channel ) {
572+ this . channelSwitchStateSubject . next ( 'start' ) ;
560573 const prevActiveChannel = this . activeChannelSubject . getValue ( ) ;
561574 if ( prevActiveChannel ?. cid === channel . cid ) {
562575 return ;
@@ -585,12 +598,14 @@ export class ChannelService {
585598 ) ;
586599 }
587600 this . setChannelState ( channel ) ;
601+ this . channelSwitchStateSubject . next ( 'end' ) ;
588602 }
589603
590604 /**
591605 * Deselects the currently active (if any) channel
592606 */
593607 deselectActiveChannel ( ) {
608+ this . channelSwitchStateSubject . next ( 'start' ) ;
594609 const activeChannel = this . activeChannelSubject . getValue ( ) ;
595610 if ( ! activeChannel ) {
596611 return ;
@@ -611,6 +626,7 @@ export class ChannelService {
611626 this . activeChannelUnreadCount = undefined ;
612627 this . areReadEventsPaused = false ;
613628 this . isMessageLoadingInProgress = false ;
629+ this . channelSwitchStateSubject . next ( 'end' ) ;
614630 }
615631
616632 /**
@@ -1138,7 +1154,10 @@ export class ChannelService {
11381154 * Selects or deselects the current message to quote reply to
11391155 * @param message The message to select, if called with `undefined`, it deselects the message
11401156 */
1141- selectMessageToQuote ( message : StreamMessage | undefined ) {
1157+ selectMessageToQuote ( message : StreamMessage | undefined | MessageResponse ) {
1158+ if ( message && ! this . isStreamMessage ( message ) ) {
1159+ message = this . transformToStreamMessage ( message ) ;
1160+ }
11421161 this . messageToQuoteSubject . next ( message ) ;
11431162 }
11441163
0 commit comments