ドキュメント

サポート

Vivox Unity SDK

Vivox Unity SDK

会話リストを取得する

How to retrieve a list of conversations for a player.
読み終わるまでの所要時間 1 分最終更新 23日前

ユーザーの会話のリストを取得できます。会話とは、ユーザーがメッセージ (ダイレクトメッセージ (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; }}