List all channels (chats) you have joined

Hi guys,

Is there a way to easily list all channels a user have joined? I want to show a list of the most recent chat rooms / groups / 1to1, and maybe to show which one has unread messages since last open.

In docs there’s not much about this topic besides how to join / leave or send messages on a channel.

Thank you so much!

@vladmustiata We don’t have an API to return the list of chat channels that the user is connected to because the way the user joins the chat channel either programmatically or by some kind of UI that they opt-in to join rooms is all known client-side. It’s a client initiated action so there’s no need to expose it as an API back to the client.

and maybe to show which one has unread messages since last open.

For this feature you can use the cursor returned when you use the ListChatMessagesAsync method from the game client SDK. The cursor is cacheable so you can use it when the game client wants to fetch newer messages in the future and the count of new messages can come from the response data returned. This lets you implement an unread message indicator in the game UI.

https://heroiclabs.com/docs/social-realtime-chat/#message-history

It would probably be great to add some of this logic to the client SDK to make it more automatic for the game developer to utilize. The API covers all which is needed though. Let me know when you’ve implemented it and we can always discuss a pull request to add some kind of MessageStore type to the SDK which tracks the cacheable cursor for various chat channels.

1 Like

@novabyte, thanks for the prompt answer!

We’re building a social gaming platform, that’s why we’re interested in this feature. As I saw in the docs that there is a Join chat section, I also thought that this information is stored somewhere in Nakama.

Does somehow ‘joining’ here means connecting to the socket to receive messages from that channel? In this case, this means that the user never really ‘joins’ a channel – and it’s only a temporary connection, as long as he is on that channel & online?

I thought that when you join a channel, this will be equal as starting a conversation in whatsapp or other messaging apps. :smile:

Cheers’

I also thought that this information is stored somewhere in Nakama.

@vladmustiata It is stored in Nakama but the preferences are not persisted by themselves. The server maintains chat history (optionally) and the streams are held in-memory when sockets are connected to the chat channels.

Does somehow ‘joining’ here means connecting to the socket to receive messages from that channel?

Yes, when a user opens a socket it does not implicitly mean they’ve joined any chat channels. They can choose to join chat channels or you can programmatically connect them to one or more of the chat channels but it’s explicit rather than implicit. This keeps the design flexible to what the user is actually interested in and makes it more flexible to different types of games. For example in a realtime multiplayer game the player might leave the chat channels when they’re in game to optimize bandwidth for important data messages, etc.

In this case, this means that the user never really ‘joins’ a channel – and it’s only a temporary connection, as long as he is on that channel & online?

I don’t know what you mean by “never really joins a chat channel” the user must of course join the chat channel to receive messages which are broadcast by other users onto it. They must also join it to send chat messages on it. This is why its referred to as joining a chat channel in our docs:

https://heroiclabs.com/docs/social-realtime-chat/#join-chat

I thought that when you join a channel, this will be equal as starting a conversation in whatsapp or other messaging apps.

Yes, this is exactly what happens. You start a chat channel with one user (direct message), or to a group, or to a chat room and you will receive chat history when on or off the socket as well as can send and receive live chat messages in realtime. Have a look at the docs here:

https://heroiclabs.com/docs/social-realtime-chat/

I think what you might really be looking for is some kind of chat room manifest so that when the user starts the app they can see which list of chat channels they might have unread messages from. To implement this you’d just store a storage object for the user with the chat channels they’re “subscribed” on.

That way at app start you’d just fetch that storage object and programmatically connect the socket and join those channels for live messages. You can also fetch chat history for all those channels as well if you want and/or use the cacheable cursor to determine how many messages are unread for each channel.

https://heroiclabs.com/docs/storage-collections/

You could even update the channel list for the user with an after hook that would do it automatically when the player joins the chat channel for the first time if you want.

https://heroiclabs.com/docs/runtime-code-basics/#after-hook

I think the server covers all you’d need to implement Whatsapp as a messaging app (without the end to end encryption of course). The game server is authoritative over the chat messages rather than the end device like in Whatsapp.

@novabyte this is what I was thinking too, after your first response. Thank you very much for clarifying! I think now all the dots are connected :smile:.

Cheers’

1 Like