feat: localized unread count#3679
Conversation
| if (client.options.isLocalUnreadCountEnabled) { | ||
| channel.markReadLocally(); | ||
| if (updateChannelUnreadState) { | ||
| setChannelUnreadState({ last_read: new Date(), unread_messages: 0 }); |
There was a problem hiding this comment.
What's the reason that we set channel unread state here, instead of setting it from WS event like we do for mark.read?
There was a problem hiding this comment.
There's no particularly important reason here, just architecture rationale' I guess.
Local unreads work only for the current user (not for other users obviously). This is sort of mimicking an HTTP response (a successful one) upon which we immediately set the state. We ignore the WS event as we do not need it any longer (nor is there any relevant date jump that we must set from the backend or whatever).
Pretty much the same as consuming:
const response = await channel.markRead();
and then
if (updateChannelUnreadState && response && lastRead) {
setChannelUnreadState({
last_read: lastRead,
last_read_message_id: response?.event.last_read_message_id,
unread_messages: 0,
});
...
}
There was a problem hiding this comment.
I missed we do it for markRead too, but wouldn't it be better to return new read info when calling markReadLocally and call setChannelUnreadState with that response? With this, we kind of have two distinct states. For example markReadLocally sets last_read_message_id but we never set this field when calling setChannelUnreadState, I assume it doesn't cause any bugs currently, but may cause issues in the future.
There was a problem hiding this comment.
I suppose, perhaps we can do that yeah and try to mimic a response.
🎯 Goal
SDK followup to this PR: GetStream/stream-chat-js#1787.
All details can be read there.
🛠 Implementation details
🎨 UI Changes
iOS
Android
🧪 Testing
☑️ Checklist
developbranch