@@ -412,33 +412,7 @@ export class ChannelService<
412412 this . watchForActiveChannelEvents ( channel ) ;
413413 this . addChannel ( channel ) ;
414414 this . activeChannelSubject . next ( channel ) ;
415- channel . state . messages . forEach ( ( m ) => {
416- m . readBy = getReadBy ( m , channel ) ;
417- m . translation = getMessageTranslation (
418- m ,
419- channel ,
420- this . chatClientService . chatClient . user
421- ) ;
422- if ( m . quoted_message ) {
423- m . quoted_message . translation = getMessageTranslation (
424- m . quoted_message ,
425- channel ,
426- this . chatClientService . chatClient . user
427- ) ;
428- }
429- } ) ;
430- if ( this . canSendReadEvents && this . shouldMarkActiveChannelAsRead ) {
431- void channel . markRead ( ) ;
432- }
433- this . activeChannelMessagesSubject . next ( [ ...channel . state . messages ] ) ;
434- this . activeChannelPinnedMessagesSubject . next ( [
435- ...channel . state . pinnedMessages ,
436- ] ) ;
437- this . activeParentMessageIdSubject . next ( undefined ) ;
438- this . activeThreadMessagesSubject . next ( [ ] ) ;
439- this . messageToQuoteSubject . next ( undefined ) ;
440- this . usersTypingInChannelSubject . next ( [ ] ) ;
441- this . usersTypingInThreadSubject . next ( [ ] ) ;
415+ this . setChannelState ( channel ) ;
442416 }
443417
444418 /**
@@ -1015,8 +989,23 @@ export class ChannelService<
1015989 this . shouldSetActiveChannel &&
1016990 ! this . activeChannelSubject . getValue ( ) ;
1017991 await this . queryChannels ( shoulSetActiveChannel || false , true ) ;
1018- // Thread messages are not refetched so active thread gets deselected to avoid displaying stale messages
1019- void this . setAsActiveParentMessage ( undefined ) ;
992+ if ( this . activeChannelSubject . getValue ( ) ) {
993+ // Thread messages are not refetched so active thread gets deselected to avoid displaying stale messages
994+ void this . setAsActiveParentMessage ( undefined ) ;
995+ // Update and reselect message to quote
996+ const messageToQuote = this . messageToQuoteSubject . getValue ( ) ;
997+ this . setChannelState ( this . activeChannelSubject . getValue ( ) ! ) ;
998+ let messages ! : StreamMessage < T > [ ] ;
999+ this . activeChannelMessages$
1000+ . pipe ( take ( 1 ) )
1001+ . subscribe ( ( m ) => ( messages = m ) ) ;
1002+ const updatedMessageToQuote = messages . find (
1003+ ( m ) => m . id === messageToQuote ?. id
1004+ ) ;
1005+ if ( updatedMessageToQuote ) {
1006+ this . selectMessageToQuote ( updatedMessageToQuote ) ;
1007+ }
1008+ }
10201009 this . isStateRecoveryInProgress = false ;
10211010 } catch {
10221011 this . isStateRecoveryInProgress = false ;
@@ -1678,4 +1667,34 @@ export class ChannelService<
16781667 } ) ;
16791668 }
16801669 }
1670+
1671+ private setChannelState ( channel : Channel < T > ) {
1672+ channel . state . messages . forEach ( ( m ) => {
1673+ m . readBy = getReadBy ( m , channel ) ;
1674+ m . translation = getMessageTranslation (
1675+ m ,
1676+ channel ,
1677+ this . chatClientService . chatClient . user
1678+ ) ;
1679+ if ( m . quoted_message ) {
1680+ m . quoted_message . translation = getMessageTranslation (
1681+ m . quoted_message ,
1682+ channel ,
1683+ this . chatClientService . chatClient . user
1684+ ) ;
1685+ }
1686+ } ) ;
1687+ if ( this . canSendReadEvents && this . shouldMarkActiveChannelAsRead ) {
1688+ void channel . markRead ( ) ;
1689+ }
1690+ this . activeChannelMessagesSubject . next ( [ ...channel . state . messages ] ) ;
1691+ this . activeChannelPinnedMessagesSubject . next ( [
1692+ ...channel . state . pinnedMessages ,
1693+ ] ) ;
1694+ this . activeParentMessageIdSubject . next ( undefined ) ;
1695+ this . activeThreadMessagesSubject . next ( [ ] ) ;
1696+ this . messageToQuoteSubject . next ( undefined ) ;
1697+ this . usersTypingInChannelSubject . next ( [ ] ) ;
1698+ this . usersTypingInThreadSubject . next ( [ ] ) ;
1699+ }
16811700}
0 commit comments