I can access and update the last seen of both users through web sockets.
I’m not able to set proper conditions to check if message is seen by the other user. I need advice to when should I update the last seen of user. I have set the condition to mark the message seen if last seen time of other user is after message’s create time. I’m updating the lastseen of current user on entering the chat so by this all messages before entering is marked seen.
I’m also updating the current user’s last seen at the time of sending message. What I’m currently lacking is how to know if the messages of being seen by other user when both of them are in the chatroom.
2
Answers
In your message entry in the database, add a "seenBy" field as a array and add the users id as a single string entry or a object with the user id and timestamp when it was seen there.
When a user connects to the chatroom the
wsclient.onconnection
event will be raised and when a user disconnects or leave the chatroomwsclient.onclose
event will be raised so we can create a bool for any user which is connectedIn this example i said that its a private chatroom between 2 people which are named User1 and User2