Hy guys, I want to create a WhatsApp like “Read” functionality that automatically marks the messages as read when the user has the chat tab opened, I’d be glad if I could get some help achieving this
Hi @mubaraqishola23 ,
You can make change to messages when he want to move out of the chat .
On the data type of conversation, you should have a data field that would be called ‘active participants’ and the field will be of type user and be a list.
Then when a user clicks on the conversation to read the messages, add the user to the list of active participants. Then when the user exits the conversation remove the user from list of active participants.
When creating a message, mark a message sent to the user as unread when the user who is receiving the message is not in the list of active participants and vice versa
That makes a lot of sense, thanks buddy.
How could I achieve making changes to the list of active participants when user clicks off, I wanted to use do when condition is true, but I realized I wouldn’t have access to the message to make a change to.
In my apps I have a button to go back to the list of conversations from a message, so I do it there, in other apps I have built so list of conversations are still visible when a user is viewing a particular conversation so when they click onto a new conversation I remove them from the current conversation in view, and I know which conversation is in view by storing that value in the URL
Okay then, I’d consider using the URL parameter too, thanks again.
Smart solutions @boston85719
I want to ask you a question here If i understand your solution well
If user get into chat and active users now contain current user and he reload the page still in active users ( out of chat and he was in active users ) is it right ?
The way I build I put into the URL parameters the conversation the user is in, so on page reload the user will still be in the conversation
Nice ,but If he close the tab and open it without parameters how you handle it ?
When page loads without parameters it shows all conversations and runs a page is loaded workflow to remove the user from all active participants from all of the conversations.
Ok, but if he close the tab and didn’t make reload to page he still in active users still making problems if other one send messages it will be flagged as read
Okay, so come up with an idea for how to solve for that problem, then you are all set
idea now
- chat has a field to store un read messages called unread_messages ( to reduce WL in step 3 )
- create a state to store active chat
- make workflow do every seconds (only when this chat state not empty )and create a state to store chat
3.1 make change to unread_messages not created by current user
Still bad for WL
There are plugins that can detect when a user is going to close the tab (basically checks if the cursor moves off the page and into the browser address bar area). These allow you to trigger workflows when those events occur.
It would be potentially better to utilize a plugin like that to run the workflow to remove the user from the active participants list.
Its really nice sur
thanks for this.
@boston85719 I’ve had limited success with those plugins. Maybe i’m using the wrong one… Do you call an api or just run a workflow on the front end?
I don’t know which one you are using or which plugins you’ve had limited success with. I didn’t recommend any specific plugins, so you’d need to elaborate.
If using a plugin to detect the users mouse position it would be a front end workflow.