Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDev UX Bug · Knowing how many unread messages there are #146
Comments
|
It's easy to get count unread messages. You could do something like this - https://getstream.io/chat/docs/unread/?language=js Also if you are using expo - you can also show count of unread message on your app icon -
|
|
@familywiser1 I did exactly what you described in the code i attached, but i had to add a ton of workarounds to make it actually keep up to date, thats the entire point of this issue |
Describe the bug
I have had to jump through an insane amount of hoops to get a simple 'unread notificaiton' badge count working in my app.
Here is all the code i've had to write.
(promise in this case is the promise that's returned from 'setUser' which i need to be resolved in order to figure out the initial 'total_unread_count')
A bit of an explanation as to whats going on:
Currently there is no way to reliably query how many unread messages you have. You essentially have to wait until messages come through to see the latest 'count'. The problem is, when we unmount a component, that component cannot 'listen' for changes anymore, so when it gets remounted, it will have no idea how many unread messages there are (
client.user.total_unread_countis only accurate immediately aftersetUseris called, and then is no longer reliable). The only way i could solve this is attaching a global listener to client that operates even when the badge component is unmounted. This 'attempts' to keep track of the unread count but can fail due to a few reasons. Eg, if you minimise the app, the app garbage collection can mean that the listener will stop firing. So when you reopen the app, you will either have to refire 'setUser' to get the latest count, or wait until an event fires to retrigger the listener.Anyway, its very messy. Ideally the 'client' object would have a reliable up-to-date property that shows the actual unread count. That way you could just set up a timer that checks that value every 500ms and rerenders if it changes.
Dev environment info (please complete/provide the following information):
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
Screenshots
If applicable, add screenshots to help explain your problem.