Improve "New messages" indicator behavior
Hey Valerian. I’ve tried to send a MessagesUpdated event when the last read message changes after calling markAsRead(). This way the “New messages” indicator will disappear immediately if a new message comes in. However…
- When selecting a room, the “New messages” indicator will also disappear (almost) immediately
- If the indicator is above the visible area, you won’t be able to see it, since it disappears too quickly
I also don’t think that the indicator should disappear when you’ve selected a room and receive a new message, since that event is outside of your control. You might be scrolling back to catch up with the conversation and suddenly the marker goes away.
I would suggest to insert the “New messages” indicator when a room is selected. Then only remove it if…
- The user sends a message from the selected room (possibly - imagine a "I'm back, now reading back old messages" message)
- The user selects another room and comes back - unless there were new messages received in the meantime
As such I would suggest the following:
-
The core does not send a
MessagesUpdatedevent when thelastReadmessage changes -
The frontend continues to call
markAsRead()after selecting a room, after receiving a message while the room is selected ~and (new) after sending a message if the room is selected~ (Update: Not needed anymore, since sent messages should always be displayed as read) -
The frontend will remove the “New messages” indicator by setting the
isLastReadof the last read message tofalseand setting it totruefor the last message in the room when the user navigates away. If aMessagesAppendedevent is fired while a room is not selected the "New messages" indicator should be shown again above the first appended message when the user navigates back to the room - this could be done by checking if the last message in the room has theisLastReadflag set.
Edit: As discussed, messages from the current user should always be marked as read. This means that when inserting the unread indicator after the last read message, you need to check for any subsequent messages from the same user. If such messages exist, the unread indicator should be placed after these consecutive messages.