File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -438,7 +438,7 @@ const ChannelInner = <
438438 mainChannelUpdated = false ;
439439 }
440440
441- if ( mainChannelUpdated && event . message ?. user ?. id !== client . userID ) {
441+ if ( mainChannelUpdated ) {
442442 if ( ! document . hidden ) {
443443 markReadThrottled ( ) ;
444444 } else if ( channelConfig ?. read_events && ! channel . muteStatus ( ) . muted ) {
@@ -536,6 +536,14 @@ const ChannelInner = <
536536 ) ,
537537 type : 'initStateFromChannel' ,
538538 } ) ;
539+
540+ /**
541+ * TODO: maybe pass last_read to the countUnread method to get proper value
542+ * combined with channel.countUnread adjustment (_countMessageAsUnread)
543+ * to allow counting own messages too
544+ *
545+ * const lastRead = channel.state.read[client.userID as string].last_read;
546+ */
539547 if ( channel . countUnread ( ) > 0 ) markRead ( ) ;
540548 // The more complex sync logic is done in Chat
541549 document . addEventListener ( 'visibilitychange' , onVisibilityChange ) ;
Original file line number Diff line number Diff line change @@ -1347,6 +1347,20 @@ describe('Channel', () => {
13471347 await waitFor ( ( ) => expect ( markReadSpy ) . toHaveBeenCalledWith ( ) ) ;
13481348 } ) ;
13491349
1350+ it ( 'should mark the channel as read if the new message author is the current user and the user is looking at the page' , async ( ) => {
1351+ const { channel, chatClient } = await initClient ( ) ;
1352+ const markReadSpy = jest . spyOn ( channel , 'markRead' ) ;
1353+
1354+ const message = generateMessage ( { user : generateUser ( ) } ) ;
1355+ const dispatchMessageEvent = createChannelEventDispatcher ( { message } , chatClient , channel ) ;
1356+
1357+ renderComponent ( { channel, chatClient } , ( ) => {
1358+ dispatchMessageEvent ( ) ;
1359+ } ) ;
1360+
1361+ await waitFor ( ( ) => expect ( markReadSpy ) . toHaveBeenCalledWith ( ) ) ;
1362+ } ) ;
1363+
13501364 it ( 'title of the page should include the unread count if the user is not looking at the page when a new message event happens' , async ( ) => {
13511365 const { channel, chatClient } = await initClient ( ) ;
13521366 const unreadAmount = 1 ;
You can’t perform that action at this time.
0 commit comments