File tree Expand file tree Collapse file tree 1 file changed +17
-15
lines changed
package/src/components/Chat/hooks Expand file tree Collapse file tree 1 file changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -131,21 +131,23 @@ export const handleEventToSyncDB = async <
131131 if ( cid && client . user && client . user . id !== user ?. id ) {
132132 const userId = client . user . id ;
133133 const channel = client . activeChannels [ cid ] ;
134- const ownReads = channel ?. state . read [ userId ] ;
135- const unreadCount = channel ?. state . unreadCount ;
136- const upsertReadsQueries = await upsertReads ( {
137- cid,
138- flush : flushOverride ,
139- reads : [
140- {
141- last_read : ownReads . last_read . toString ( ) as string ,
142- last_read_message_id : ownReads . last_read_message_id ,
143- unread_messages : unreadCount ,
144- user : client . user ,
145- } ,
146- ] ,
147- } ) ;
148- queries = [ ...queries , ...upsertReadsQueries ] ;
134+ if ( channel ) {
135+ const ownReads = channel . state . read [ userId ] ;
136+ const unreadCount = channel . countUnread ( ) ;
137+ const upsertReadsQueries = await upsertReads ( {
138+ cid,
139+ flush : flushOverride ,
140+ reads : [
141+ {
142+ last_read : ownReads . last_read . toString ( ) as string ,
143+ last_read_message_id : ownReads . last_read_message_id ,
144+ unread_messages : unreadCount ,
145+ user : client . user ,
146+ } ,
147+ ] ,
148+ } ) ;
149+ queries = [ ...queries , ...upsertReadsQueries ] ;
150+ }
149151 }
150152 return queries ;
151153 } ) ;
You can’t perform that action at this time.
0 commit comments