Unread messages logic

Quick background:

I’ve built a simple messenger from one user to another.

When the user 1 sends a message to user 2 it creates a conversation and adds a new message to a message list. It also marks the conversation ‘opened= no’ in the database to that the recipient knows its new.

When user 2 opens the message it turn to ‘opened=yes’

So with this, I am trying to indicate to user 2 in the inbox which message is unread (a bit like a bold text when you get a new email)

The problem is it can’t do the same if user 1 adds a new message to the conversation as it doesnt make sense ( User 1 already know they have just added a message) so I came up with this:

Make the background grey if new.

But it’s not working- or not as I want it to, am I doing something wrong- any ideas of how to approach this?

Hi @pauljamess!

I’ve done messaging a few different ways and here’s one that might make unread notifications a little easier. Have 2 data types:

Message

  • body (text)
  • conversation (Conversation)

Conversation

  • messages (list of Messages)
  • users (list if users… Those involved)

And under User type…

User

  • unread messages (list of Messages)

So 1 conversation is created between 2 users. Every single message is a new Message and then gets added to the conversation as well as the recipient’s list of unread messages.

When message is in current user’s list of unread messages, make bold.

When they mark it as read (button click maybe), remove from unread list.

And so forth. Just a different tapproach that might be easier to manage. The key here is that each message needs to be “marked” independently for different users. So you have 1 item being shared (message) but presented differently for Users (read/unread) so this creates a need for another data type or another field outside of the shared thing that can be independent to the user. Here, the unread list for the User and the independent type for messages.


Gaby | Coaching Bubble

3 Likes

If the number of users in a conversation is limited to two, then @pauljamess’s approach can work, with a modification of separating the conversation’s unread status between the two users.

@romanmg’s approach is better for conversations with multiple people : )

thanks both @romanmg and @mishav! Really appreciate it :slight_smile:
Could you help me understand how I can do that @mishav - I tried to separate by using “current user” is there another way I could do this?

Paul

For two people, the unread status of a conversation only needs to track unread, and for whom.

One way to do this is both pieces of information in one setting … when a message is added, set a new field [Conversation’s Marked Unread By] to [Current User]. Then for other person not matching that user, the conversation is unread. When finished reading it, set it to nothing.

If it’s easier, can make the new field “Marked Unread For” and put the destination user in there.

Your approach of the unread status and not being creator of the last message captures the same information, I’m not sure why it didn’t work.

Another alternative is to set [Conversations’s Last Unread Message] to [the new Message], then check for [Conversations’s Last Unread Message’s Creator] is not [Current User] … and also gives the message to show in your preview.

Good luck!

The problem i’m finding with this is that when a conversation is initiated. User 2 becomes the “recipient”- but once the recipient replies to user 1- user 1 does not become the recipient, user 2 is still the recipient from when the conversation was initialed.

I’d say the time to update the conversation’s recipient this is on the action of adding a new message to the conversation.