跳转至

频道

创建频道

要创建新的聊天频道,请先创建 CreateChannelParams 对象,然后调用 Chat 类的 createChannel() 方法。

CreateChannelParams

字段名 说明 类型 必填
channelId 频道 ID
(可使用英文字母大小写、数字以及部分特殊字符(-, ., _, ~, :),最多 100 个字符)
string Y
password 密码(仅 PRIVATE 频道时为必填字段)
(最多 50 个字符)
string N
channelName 频道名称
(最多 50 个字符)
string Y
maxMemberCount 频道最大参与人数
(最少 2 人,最多 5,000 人)
(仅在不是 ONE_ON_ONE 频道时为必填)
integer N
type 频道类型 (PRIVATE, PUBLIC, GROUP, ONE_ON_ONE) enum Y
chatHistoryAllowed 是否允许查询频道历史记录 boolean N
otherPlayerId 要邀请的对方玩家 ID(仅 ONE_ON_ONE 频道时为必填字段) long N

ONE_ON_ONE 频道创建时,请将 type 设置为 ONE_ON_ONE,并在 otherPlayerId 中输入对方 PlayerID。此时不传递 maxMemberCount

以下是创建新聊天频道的示例代码。

using hive;

CreateChannelParams createChannelParams = new CreateChannelParams();
createChannelParams.channelId = "CHANNEL_ID";
createChannelParams.password = "";
createChannelParams.channelName = "CHANNEL_NAME";
createChannelParams.maxMemberCount = 8;
createChannelParams.type = ChannelType.PUBLIC;

Chat.createChannel(createChannelParams, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
#include "HiveChat.h"

FHiveCreateChannelParams CreateChannelParams = FHiveCreateChannelParams();
CreateChannelParams.ChannelId = TEXT("CHANNEL_ID");
CreateChannelParams.Password = TEXT("");
CreateChannelParams.ChannelName = TEXT("CHANNEL_NAME");
CreateChannelParams.MaxMemberCount = 8;
CreateChannelParams.Type = EHiveChannelType::Public;

FHiveChat::CreateChannel(CreateChannelParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API 调用成功
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

CreateChannelParams param;
param.channelId = "CHANNEL_ID";
param.channelName = "CHANNEL_NAME";
param.password = "";
param.maxMemberCount = 8;
param.type = ChannelType::PUBLIC;

Chat::createChannel(param, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.CreateChannelParams(
    channelId = "CHANNEL_ID",
    password = "",
    channelName = "CHANNEL_NAME",
    maxMemberCount = 8,
    type = Chat.ChannelType.PUBLIC
)

Chat.createChannel(params, object: Chat.CreateChannelListener{
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API 调用成功
        }
    }
})
import com.hive.Chat;

Chat.CreateChannelParams params = new Chat.CreateChannelParams(
    "CHANNEL_ID",
    "",
    "CHANNEL_NAME",
    8,
    Chat.ChannelType.PUBLIC
);

Chat.createChannel(params, result -> {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import HIVEService

let params = Chat.CreateChannelParams(
    channelId: "CHANNEL_ID",
    password: "",
    channelName: "CHANNEL_NAME",
    maxMemberCount: 8,
    type: .public
)
ChatInterface.createChannel(params) { result in
    if result.isSuccess() {
        // API 调用成功
    }
}
#import "HIVEService.h"

HiveChatCreateChannelParams* params = [[HiveChatCreateChannelParams alloc] init];
params.channelId = @"CHANNEL_ID";
params.password = @"";
params.channelName = @"CHANNEL_NAME";
params.maxMemberCount = 8;
params.type = Chat::ChannelType::PUBLIC;

[HiveChat createChannelWithCreateParams:params handler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API 调用成功
    }
}];

删除频道

如要删除现有聊天频道,请调用 Chat 类的 deleteChannel() 方法。

以下是删除聊天频道的示例代码。

using hive;

String channelId = "CHANNEL_ID";

Chat.deleteChannel(channelId, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
#include "HiveChat.h"

FString ChannelId = TEXT("CHANNEL_ID");

FHiveChat::DeleteChannel(ChannelId, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API 调用成功
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

hat::deleteChannel(commonChannelId, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val channelId = "CHANNEL_ID"

Chat.deleteChannel(channelId, object: Chat.DeleteChannelListener{
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API 调用成功
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

Chat.deleteChannel(channelId, result -> {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import HIVEService

let channelId = "CHANNEL_ID"
ChatInterface.deleteChannel(channelId: channelId) { result in
    if result.isSuccess() {
        // API 调用成功
    }
}
#import "HIVEService.h"

NSString *channelId = @"CHANNEL_ID";
[HiveChat deleteChannelWithChannelId:channelId handler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API 调用成功
    }
}];

进入频道

要进入现有聊天频道,请先创建 EnterChannelParams 对象,然后调用 Chat 类的 enterChannel() 方法。

Note

对于 ONE_ON_ONE 频道,除首次创建时参与的两个账号之外,其他账号无法进入。

EnterChannelParams

字段名 说明 类型 必填
channelId 频道 ID string Y
password 密码(PRIVATE 频道时必填) string N

以下是进入聊天频道的示例代码。

using hive;

EnterChannelParams enterChannelParams = new EnterChannelParams();
enterChannelParams.channelId = "CHANNEL_ID";
enterChannelParams.password = "";

Chat.enterChannel(enterChannelParams, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
#include "HiveChat.h"

FHiveEnterChannelParams EnterChannelParams = FHiveEnterChannelParams();

EnterChannelParams.ChannelId = TEXT("CHANNEL_ID");
EnterChannelParams.Password = TEXT("");

FHiveChat::EnterChannel(EnterChannelParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API 调用成功
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

EnterChannelParams param;
param.channelId = "CHANNEL_ID";
param.password = "";

Chat::enterChannel(param, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.EnterChannelParams(
    channelId = "CHANNEL_ID",
    password = ""
)

Chat.enterChannel(params, object: Chat.EnterChannelListener{
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API 调用成功
        }
    }
})
import com.hive.Chat;

Chat.EnterChannelParams params = new Chat.EnterChannelParams(
    "CHANNEL_ID",
    ""
);

Chat.enterChannel(params, result -> {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import HIVEService

let params = HiveChatParams.EnterChannelParams(
    channelId: "CHANNEL_ID",
    password: ""
)

ChatInterface.enterChannel(enterChannelParams: params) { result in
    if result.isSuccess() {
        // API 调用成功
    }
}
#import "HIVEService.h"

HiveChatEnterChannelParams* params = [[HiveChatEnterChannelParams alloc] init];
params.channelId = @"CHANNEL_ID";
params.password = @"";

[HiveChat enterChannelWithEnterChannelParams:params handler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API 调用成功
    }
}];

退出频道

如要退出已参与的聊天频道,请调用 Chat 类的 exitChannel() 方法。

以下是退出已参与聊天频道的示例代码。

using hive;

String channelId = "CHANNEL_ID";

Chat.exitChannel(channelId, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
#include "HiveChat.h"

FString ChannelId = TEXT("CHANNEL_ID");

FHiveChat::ExitChannel(ChannelId, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API 调用成功
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

Chat::exitChannel(channelId, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val channelId = "CHANNEL_ID"

Chat.exitChannel(channelId, object: Chat.ExitChannelListener {
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API 调用成功
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

Chat.exitChannel(channelId, result -> {
    if (result.isSuccess()) {
        // API 调用成功
    }
});
import HIVEService

let channelId = "CHANNEL_ID"
ChatInterface.exitChannel(channelId: channelId) { result in
    if result.isSuccess() {
        // API 调用成功
    }
}
#import "HIVEService.h"

NSString *channelId = @"CHANNEL_ID";
[HiveChat exitChannelWithChannelId:channelId handler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API 调用成功
    }
}];

查询全部频道列表

要查询当前存在的全部频道列表,请先创建 GetChannelsParams 对象,然后调用 Chat 类的 getChannels() 方法。

Note

如果不传递 GetChannelsParams 对象(即不传递对象时传递 null),则返回当前存在的全部频道列表,不做过滤。

Note

对于 ONE_ON_ONE 频道,如果无需先查询频道而需要向对方发送消息,可以通过调用 createChannel() 访问现有频道或额外创建频道。

GetChannelsParams

字段名 说明 类型 必填
type 要查询的频道类型 (PRIVATE, PUBLIC, GROUP) enum Y
channelId 查询以特定频道 ID 开头的频道 string N
channelName 查询包含特定频道名称的频道 string N
sort 频道排序基准 (ChannelId, ChannelName, RegTime) enum N
pageOrder 排序方式 (ASC, DESC)
(默认值 DESC)
string N
pageSize 每页查询的频道数量
(最少 1 个,最多 10 个,默认值 10)
integer N
pageNumber 要查询的页码
(从 1 开始,默认值 1)
integer N

响应会返回 Channel 对象和 ChannelPage 对象,其结构如下。

Channel

字段名 说明 类型
channelId 频道 ID string
type 频道类型 (PRIVATE, PUBLIC, GROUP) enum
owner 频道所有者的 Hive PlayerID string
channelName 频道名称 string
memberCount 当前参与成员数 integer
maxMemberCount 频道最大参与人数 integer
regTime 频道创建时间(以 UTC+0 为准,格式为 yyyy-MM-dd'T'HH:mm:ss.SSSZ string
regTimeMillis 频道创建时间 (Unix Timestamp) long
chatHistoryAllowed 是否允许查询频道历史记录 bool
query 查询频道消息历史记录的方法 method

ChannelPage

字段名 说明 类型
size 每页项目数 integer
currentPage 当前页码 integer
totalElements 全部项目数 integer
totalPages 总页数 integer

注意事项

  • 如果不传递 GetChannelsParams 对象(=null),则返回当前存在的全部频道列表,不做过滤。
  • 此 API 仅查询 PUBLICPRIVATEGROUP 频道。ONE_ON_ONE 频道不包含在查询范围内。

示例代码

以下是查询当前存在的 PUBLIC 类型全部频道列表的示例代码。

using hive;

GetChannelsParams getChannelsParams = new GetChannelsParams();
getChannelsParams.type = ChannelType.PUBLIC;

Chat.getChannels(getChannelsParams, (ResultAPI result, List<Channel> channels, ChannelPage channelPage) => {
    if (result.isSuccess()) {
        // API 调用成功

        foreach (Channel channel in channels) {
            // 获取 Channel
        }

        if (channelPage != null) {
            // 获取 ChannelPage
        }

    }
});
#include "HiveChat.h"

TOptional<FHiveGetChannelsParams> GetChannelsParams = FHiveGetChannelsParams();
GetChannelsParams->Type = EHiveChannelType::Public;

FHiveChat::GetChannels(GetChannelsParams, FHiveChatOnGetChannelsDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TArray<FHiveChannel>& channels, FHiveChannelPage const & channelPage) {
    if (Result.IsSuccess()) {
        // API 调用成功

        for (const FHiveChannel& Channel : Channels) {
            // 获取 Channel
        }

        if (ChannelPage != nullptr) {
            // 获取 ChannelPage
        }
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

Chat::GetChannelsParams params = Chat::GetChannelsParams();
params.type = Chat::ChannelType::PUBLIC;

Chat::getChannels(param, [=](ResultAPI const & result, std::vector<Channel> const & channels, ChannelPage const & pageInfo) {
    if (result.isSuccess()) {
        // API 调用成功

        for (Chat::Channel channel : channels) {
            // 获取 Channel
        }

        if (channelPage != null) {
            // 获取 ChannelPage
        }
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.GetChannelsParams(type = Chat.ChannelType.PUBLIC)

Chat.getChannels(params, object: Chat.GetChannelsListener{
    override fun onResult(
        result: ResultAPI,
        channels: ArrayList<Chat.Channel>,
        channelPage: Chat.ChannelPage?
    ) {
        if (result.isSuccess) {
            // API 调用成功

            channels.forEach {
                // 获取 Channel
            }
            channelPage?.let {
                // 获取 ChannelPage
            }    
        }
    }
})
import com.hive.Chat;

Chat.GetChannelsParams params = new Chat.GetChannelsParams(Chat.ChannelType.PUBLIC, null, null, null, null, null);
Chat.getChannels(params, (result, channels, channelPage) -> {
    if (result.isSuccess()) {
        // API 调用成功
        for (Chat.Channel channel : channels) {
            // 获取 Channel
        }
        if (channelPage != null) {
            // 获取 ChannelPage
        }
    }
});
import HIVEService

let params = HiveChatParams.GetChannelsParams(type: .public, null, null, null, null, null)
ChatInterface.getChannels(getChannelsParams: params) { result, channels, pageInfo  in
    if result.isSuccess() {
        channels.forEach {
            // 获取 Channel
        }

        if let pageInfo {
            // 获取 ChannelPage
        }
    }
}
#import "HIVEService.h"

HiveChatGetChannelsParams* params = [[HiveChatGetChannelsParams alloc] init];
params.type = HiveChatChannelTypePublicChannel;

[HiveChat getChannelsWithGetChannelsParams:params handler:^(HIVEResultAPI * result, NSArray<HiveChatChannelContent *> * channels, HiveChatPageInfo * pageInfo) {
    if ([result isSuccess]) {
        // API 调用成功

        for (Chat::Channel *channel : channels) {
            // 获取 Channel
        }

        if (pageInfo != pageInfo) {
            // 获取 ChannelPage
        }
    }
}];

查询频道信息

如要查询特定频道的详细信息,请调用 Chat 类的 getChannelInfo() 方法。

响应会返回 Channel 对象和 Member 对象,其结构如下。

Channel

字段名 说明 类型
channelId 频道 ID string
type 频道类型 (PRIVATE, PUBLIC, GROUP) enum
owner 频道所有者的 Hive PlayerID string
channelName 频道名称 string
memberCount 当前参与成员数 integer
maxMemberCount 频道最大参与人数 integer
regTime 频道创建时间(以 UTC+0 为准,格式为 yyyy-MM-dd'T'HH:mm:ss.SSSZ string
regTimeMillis 频道创建时间 (Unix Timestamp) long
chatHistoryAllowed 是否允许查询频道历史记录 bool
query 查询频道消息历史记录的方法 method

Member

字段名 说明 类型
playerId Hive PlayerID long
connectedTime 连接时间(以 UTC+0 为准,格式为 yyyy-MM-dd'T'HH:mm:ss.SSSZ string
connectedTimeMillis 连接时间 (Unix Timestamp) long

以下是查询特定频道详细信息的示例代码。

using hive;

String channelId = "CHANNEL_ID";

Chat.getChannelInfo(channelId, (ResultAPI result, Channel channel, List<Member> members) => {
    if (result.isSuccess()) {
        if (channel != null) {
            // 获取 Channel
        }

        foreach (Member member in members) {
            // 获取 Member
        }
    }
});
#include "HiveChat.h"

FString ChannelId = TEXT("CHANNEL_ID");

FHiveChat::GetChannelInfo(ChannelId, FHiveChatOnGetChannelInfoDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChannel& channel, const TArray<FHiveMember>& members) {
    if (Result.IsSuccess()) {
        // API 调用成功

        if (channel != nullptr) {
            // 获取 Channel
        }

        for (const FHiveMember& Member : Members) {
            // 获取 Member
        }
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

Chat::getChannelInfo(channelId, [=](ResultAPI const & result, Channel const & channel, std::vector<Member> const & members) {
    if (result.isSuccess()) {
        if (channel != null) {
            // 获取 Channel
        }

        for (Chat::Member member : members) {
            // 获取 Member
        }
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val channelId = "CHANNEL_ID"

Chat.getChannelInfo(channelId, object: Chat.GetChannelInfoListener {
    override fun onResult(
        result: ResultAPI,
        channel: Chat.Channel?,
        members: ArrayList<Chat.Member>
    ) {
        if (result.isSuccess) {
            channel?.let {
                // 获取 Channel
            }
            members.forEach {
                // 获取 Member
            }
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

Chat.getChannelInfo(channelId, (result, channel, members) -> {
    if(result.isSuccess()) {
        if (channel != null) {
            // 获取 Channel
        }
        for (Chat.Member member : members) {
            // 获取 Member
        }
    }
});
import HIVEService

let channelId = "CHANNEL_ID"
ChatInterface.getChannelInfo(channelId: channelId) { result, channel, members  in
    if result.isSuccess() {
        if let channel {
            // 获取 Channel
        }
        members.forEach {
            // 获取 Member
        }
    }
}
#import "HIVEService.h"

NSString *channelId = @"CHANNEL_ID";
[HiveChat getChannelInfoWithChannelId:channelId handler:^(HIVEResultAPI * result, HiveChatChannelContent * channel, NSArray<HiveChatMember *> * members) {
    if ([result isSuccess]) {
        if (channel != null) {
            // 获取 Channel
        }
        for (Chat::Member *member : members) {
            // 获取 Member
        }
    }
}];

查询频道参与成员

如要查询频道参与成员,请调用 Chat 类的 getChannelMembers() 方法。

Note

响应值与 getChannelInfo() 中返回的 Member 对象相同。

using hive;

String channelId = "CHANNEL_ID";

Chat.getChannelMembers(channelId, (ResultAPI result, List<Member> members) => {
    if (result.isSuccess()) {
        foreach (Member member in members) {
            // 获取 Member
        }
    }
});
#include "HiveChat.h"

FString ChannelId = TEXT("CHANNEL_ID");

FHiveChat::GetChannelMembers(ChannelId, FHiveChatOnGetChannelMembersDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TArray<FHiveMember>& members) {
    if (Result.IsSuccess()) {
        for (const FHiveMember& Member : members) {
            // 获取 Member
        }
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

Chat::getChannelMembers(channelId, [=](ResultAPI const & result, std::vector<Member> const & members) {
    if (result.isSuccess()) {
        for (Chat::Member member : members) {
            // 获取 Member
        }
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val channelId = "CHANNEL_ID"

Chat.getChannelMembers(channelId, object: Chat.GetChannelMembersListener{
    override fun onResult(result: ResultAPI, members: ArrayList<Chat.Member>) {
        if (result.isSuccess) {
            members.forEach { 
                // 获取 Member
            }
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

Chat.getChannelMembers(channelId, (result, members) -> {
    if (result.isSuccess()) {
        for (Chat.Member member : members) {
            // 获取 Member
        }
    }
});
import HIVEService

let channelId = "CHANNEL_ID"
ChatInterface.getChannelMembers(channelId: channelId) { result, members in
    if result.isSuccess() {
        members.forEach {
            // 获取 Member
        }
    }
}
#import "HIVEService.h"

NSString *channelId = @"CHANNEL_ID";
[HiveChat getChannelMembersWithChannelId:channelId handler:^(HIVEResultAPI * result, NSArray<HiveChatMember *> * members) {
    if ([result isSuccess]) {
        for (Chat::Member *member : members) {
            // 获取 Member
        }
    }
}];

查询频道消息历史记录

通过调用 channel.query(ChannelMessageListQueryParams, ChannelMessageListQueryListener) 方法加载之前的聊天记录。

只有频道属性 chatHistoryAllowedtrue 的频道才可以查询历史记录。

ChannelMessageListQueryParams

字段名 说明 类型 必填
prevSize 查询之前消息的数量(最少 0,最多 50,默认值 0) integer N
nextSize 查询之后消息的数量(最少 0,最多 50,默认值 0) integer N
messageId 以该消息 ID 为基准查询消息记录。如果该值为 null,则以最新消息为基准进行查询。 string N
sort 默认按日期降序排序,可根据查询方向调整排序方式(DESC or ASC),默认值 DESC string N

ChannelMessageListQueryResponse

字段名 说明 类型
hasNext 是否存在之后可继续查询的消息 boolean
nextMessageId 继续查询之后消息时作为基准的消息 ID string
hasPrev 是否存在之前可继续查询的消息 boolean
prevMessageId 继续查询之前消息时作为基准的消息 ID string
content 查询到的消息结果 list<ChannelMessage>

以下是以特定消息 ID 为基准查询之前 10 条消息和之后 10 条消息的示例代码。

using hive;

ChannelMessageListQueryParams queryParams = new ChannelMessageListQueryParams();
queryParams.prevSize = 10;
queryParams.nextSize = 10;
queryParams.messageId = "TARGET_MESSAGE_ID";
channel.query(queryParams, (ResultAPI result, ChannelMessageListQueryResponse response) => {
    if (result.isSuccess() && response != null) {
        foreach (ChannelMessage message in response.content) {
            // 频道消息列表
        }
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

ChannelMessageListQueryParams queryParams;
queryParams.prevSize = 10;
queryParams.nextSize = 10;
queryParams.messageId = "TARGET_MESSAGE_ID";

channel.query(queryParams, [=](ResultAPI const & result, ChannelMessageListQueryResponse const & response) {
    if (result.isSuccess()) {
        for (auto message : response.message) {
            // 频道消息列表
        }
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val queryParams = Chat.ChannelMessageListQueryParams(
    prevSize = 10,
    nextSize = 10,
    messageId = "TARGET_MESSAGE_ID"
    )

channel.query(queryParams, object : Chat.ChannelMessageListQueryListener {
    override fun onResult(
        result: ResultAPI,
        response: Chat.ChannelMessageListQueryResponse?
    ) {
        if(result.isSuccess && response != null) {
            response.content.forEach {
                // 频道消息列表
            }
        }
    }
})
import com.hive.Chat;

Chat.ChannelMessageListQueryParams queryParams = new Chat.ChannelMessageListQueryParams();
queryParams.prevSize = 10;
queryParams.nextSize = 10;
queryParams.messageId = "TARGET_MESSAGE_ID";

channel.query(queryParams, (result, response) -> {
    if (result.isSuccess() && response != null) {
        for (HiveChatChannelMessage message : response.getContent()) {
            // 频道消息列表
        }
    }
});
import HIVEService

let queryParams = HiveChatParams.ChannelMessageListQueryParams(prevSize: 10, nextSize: 10, messageId: "TARGET_MESSAGE_ID")

channel.query(queryParams) { result, response in
    if result.isSuccess(),
       let contents = response.content {
        contents.forEach { message in
            // 频道消息列表
        }
    }
}
#import "HIVEService.h"

HiveChatChannelMessageListQueryParams* queryParams = [HiveChatChannelMessageListQueryParams new];
queryParams.prevSize = 10;
queryParams.nextSize = 10;
queryParams.messageId = @"TARGET_MESSAGE_ID";

[channel queryWithParams:queryParams listener:^(HIVEResultAPI * result, HiveChatChannelMessageListQueryResponse* response) {
    if ([result isSuccess] && response.content) {
        for (HiveChatChannelMessage *message in response.content) {
            // 频道消息列表
        }
    }
}];

设置频道自动翻译接收

设置是否接收该频道消息的自动翻译。 可在接收到的 ChannelMessage 对象中确认已翻译的消息。

using hive;

bool translateEnabled = true;

channel.setTranslationEnabled(translateEnabled, (ResultAPI result) => {
    if(result.isSuccess()) {
        // 已完成频道消息翻译设置。
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

bool translateEnabled = true;

channel.setTranslationEnabled(translateEnabled, [=](ResultAPI const & result) {
    if(result.isSuccess()) {
        // 已完成频道消息翻译设置。
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val translateEnabled = true;

channel.setTranslationEnabled(translateEnabled, object : Chat.SetTranslationEnabledListener {
    override fun onResult(result: ResultAPI) {
        if(result.isSuccess) {
            // 已完成频道消息翻译设置。
        }
    }
})
import com.hive.Chat;

boolean translateEnabled = true;

channel.setTransationEnabled(translateEnabled, (result) -> {
    if (result.isSuccess()) {
        // 已完成频道消息翻译设置。
    }
});
import HIVEService

let translateEnabled = true;

channel.setTranslationEnabled(translateEnabled) { result in
    if result.isSuccess() {
        // 已完成频道消息翻译设置。
    }
}
#import "HIVEService.h"

BOOL translateEnabled = YES;

[channel setTranslationEnabledWithEnabled: translateEnabled handler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // 已完成频道消息翻译设置。
    }
}];

频道事件管理

持续检测 Hive 聊天 Socket 服务器的连接状态,并将应用用户和频道中发生的状态变更事件持续传递到应用。有关详细的事件处理方法,请参阅 事件管理 > 频道事件 文档。