I am building a chat app using Node.js, Express, React and Socket.io. I want to keep track of unread messages so I can notify the user with unread messages count. Should this be implemented on both server and client sides?
How can I track unread messages in a messenger app
You can track the read message count and total message count. Then to show unread messages you can check for the difference between total message count and read message count by the end-user. If the Difference is greater than zero then you can notify the user with an unread message count. To show notification in real-time you need to implement socket events on the client side. And also need to store the read message count at the server-side in case of app refresh. –
Penknife
Check this to see some of the tradeoff doing it either on client or server side.
Also it depends on how you are implementing it.
I'm currently doing something very similar and I chose to keep track of the last time the user checked the chatroom/ conversation and compare it to the created_at date of the messages. So the server sends off all the chatrooms and their last 50 messages to the client. I then calculate the number of unread messages directly in redux via a helper function and display it on the chatroom badge.
© 2022 - 2024 — McMap. All rights reserved.