How to handle a situation where we need send a message so it is visible to only a single user in group channels?

This is our case scenario requirement that is very common in today’s chat apps.

Requirements

  • We are a Whatsapp-like one-on-one chat app, and we use Sendbird’s Group Channels.
  • Inside the Group Channel, user A and user B joins.
  • user A calls user B but user B does not answer a call.
  • we want to send a chat message “user A called you!” to only user B.

Our Solution

  • To build this feature, when user A calls user B, in the server side using sendbirds Platform API we send a ADMM type, Sendbird Admin Message to the group channel. However there are two problems we cannot solve.

Problem to our Solution

  1. How can we only show the channel message to user A? Admin Messages seem to go through the channel and delivered to both user A and user B?

  2. Could we manipulate the ‘Unread Message Count’ for each user in server side through the Platform API? Because the Admin message that “User A called you!” goes to the group channel, user B should not have the message counted as an unread message count, because the message should only be visible to user A.

  3. Could we manipulate the ‘Latest last message’ through the Platform API? Same as I stated above in 2., “User A called you” should not be delivered as the ‘Latest last message’ for the group channel for the user B, because user B shouldn’t see the message at all in his/her chat room.

Hi @Dexter_Kim,

There are a couple of steps needed to solve the problems with your solution.

Q: How can we only show the channel message to user A? Admin Messages seem to go through the channel and delivered to both user A and user B?
A: This likely would need to be handled on the client side. You could send the message with a sorted_metaarray attached to it, which would allow you to render based on that value on the client side.

Example:
POST Body:

{
  "message": "You missed a call from User B",
  "message_type": "ADMM",
  "sorted_metaarray": [
        {
            "key": "forUser",
            "value": ["A"]
        }
    ]
}

Then when you query the message on the client side, you can render off that value.

The next two questions are sort of tied into one. Essentially, the ADMM message has an is_silent flag. This flag allows you to send the message silently, which does not change the Latest last message value. It also does not affect the unreadCount. Unfortunately, there isn’t a way to selectively update it for one user, and not the other.

So there won’t be a way to change the Latest last message and unreadCount?

I believe this is a very common case in dating or other social media apps. As there will be ADMM messages that should only be shown to a certain user in 2 way chat.

What ways do you recommend us to do? to develop this to meet our business needs?

Hi @Dexter_Kim,

There is no way for you to manipulate the unreadCount or the Latest last message. Any type of manipulation would need to occur client side.

So we have to make every single more API call for all the group channels to fetch our last messages and update the unreadCount and Latest last message accordingly client side?

Is there no need for this feature from other users? I believe it is a very common case that is needed.

I’m not sure I understand what you mean by the need to make additional API calls to fetch last messages and update the unreadCount. Ideally, you’d simply update the values in whatever state management you’re using and then render that accordingly on the front end. For example, if I was using React and Redux, and I received an ADMM message that was only designed for one user, I’d update my Redux Store to increment the unreadCount, and the last read message for the channel for that specific user. Thus the other user is unaware of any change. No additional API calls would be needed.

As for your comment about other use cases, its not something I’ve personally seen requested before.

Thanks for the reply Tyler.

But how would you handle the first time fetch? Your explanation is good for updates on the app when the ADMM message comes at the moment.

However when the user first comes to the app and it has to fetch the list of channels in the client, all the unread count and latest last message data comes from sendbird, that would be incorrect in our case.
I meant that in that case, we need to make additional API calls and fetch the latest messages and filter out messages that shouldn’t be shown to the user and find out what the real latest last message for the user should be right? This is the complicated part I don’t think it can be handled well.

Hi Dexter,

You’re correct. My comments did not take into account what would happen if the message was received when the user was not connected.

You could potentially use the data field on the ADMM message to pass in data such as who should see it, and when the message was sent. Then send the message as silent, so that it doesn’t update the last message or unread count for either user.

Then on your original call for the message list, you could locally increase the unread count for the user depending on their last read timestamp.

I’ll try to work out an example for you in Javascript later today or tomorrow.

Could you help me with a situation like below? It would be very helpful if you provide some sample code :slight_smile: If we go on a paid plan, would we be able to schedule a call with you for technical issues?

  1. We use Syncmanager for React Native
  2. When User A calls User B, we want to show an ADMM(admin) message to only User B with the message “User A called You!” and the group channel should not be visible to User A only for User B.

What would be a good approach for this, regarding Group channel visibility, Last message, Unread Message Count sync? It seems like a very hard problem to solve.

We were also thinking that when the event “User A calls User B”, we create 2 group channels.

  1. Group Channel btw User A, User B
  2. Group Channel btw User B, Admin

and only send ADMM messages to User B in the conceptually “Private” Channel (btw User B, Admin) and sync all 1, 2 Group channels and combine the messages and unread message count and etc to show it in one group chat room.

What are your thoughts for the best solution?