会話リストを取得する

ユーザーの会話のリストを取得できます。会話とは、ユーザーがメッセージ (ダイレクトメッセージ (DM)) を送信したチャンネルのことです。この API を使用して、ユーザーのチャンネルや DM のリストを入力し、そのユーザーのアクティブなチャットを探すことができます。

ノート: 返された会話リストは、最近のアクティビティによってランク付けされます。より新しいメッセージがある会話が結果の最初に表示されます。

会話リストを取得するには、アプリケーションにサインインしてから、await VivoxService.Instance.GetConversationsAsync(); を使用してリクエストを行います。このメソッドは、VivoxConversation のオブジェクトのコレクションを返します。各オブジェクトは、DM またはチャンネルの会話を表します。

以下のコードは、ユーザーの会話リストを取得する方法の例です。

// 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);

ユーザーの会話リストを取得した後は、結果の VivoxConversation のコレクションを解析して、どれが DM でどれがチャンネルの会話であるかを判別できます。

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;
    }
}

ノート: 返された VivoxConversationVivoxConversation.ConversationType によって、VivoxConversation.Name は別のユーザーの PlayerId か、チャンネルの一意のチャンネル名となります。両方のケースで、VivoxConversation.Name は 2 種類の会話のどちらか一方の一意識別子です。