Skip to content

Commit 5172379

Browse files
committed
fix: use countUnread() api for brevity
1 parent 0434848 commit 5172379

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

package/src/components/Chat/hooks/handleEventToSyncDB.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)