Retrieve Conversations list
You can retrieve a user’s list of conversations. A conversation is a channel where a user has sent a message or a direct message (DM). You can use this API to populate a list of channels or DMs for a user to find their active chats.
Note: The returned Conversation list is ranked by most recent activity. Conversations with newer messages show up first in the results.
To retrieve the conversation list, sign in to the application and then use await VivoxService.Instance.GetConversationsAsync();
to make a request.
This method returns a collection of VivoxConversation
objects, each representing either a DM or a channel conversation.
The following code is an example of how to retrieve a user’s conversation list.
// The use of `ConversationQueryOptions` is optional and the method can be called without providing it.
var options = new ConversationQueryOptions()
{
CutoffTime = DateTime.Now, // Point in time to fetch conversations from. Conversations joined after this timestamp will not be present in the query results. This timestamp gets converted to UTC internally.
PageCursor = 1, // Parameter if you’re fetching anything but the first page.
PageSize = 10 // The number of results returned per page. The default is 10.
};
var conversations = await VivoxService.Instance.GetConversationsAsync(options);
After you retrieve the user’s conversation list, you can parse the resulting collection of VivoxConversation
to determine which are DMs and which are channel conversations:
foreach (VivoxConversation conversation in conversations)
{
switch (conversation.ConversationType)
{
case ConversationType.ChannelConversation:
// Code for handling channel conversations.
// You must be in a channel matching conversation.Name in order to fetch the message history of type ConversationType.ChannelConversation.
break;
case ConversationType.DirectedMessageConversation:
// Code for handling DM conversations, for instance...
var directMessages = await VivoxService.Instance.GetDirectTextMessageHistoryAsync(conversation.Name);
// Populate UI with directMessages with another user.
break;
default:
break;
}
}
Note: Depending on the VivoxConversation.ConversationType
of a returned VivoxConversation
, the VivoxConversation.Name
will either be the PlayerId of another user, or the unique channel name of a channel.
In both cases, the VivoxConversation.Name
is a unique identifier for one of the two types of conversations.