跳轉至

頻道

建立頻道

要建立新的聊天頻道,請先建立 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 伺服器的連線狀態,並將應用使用者與頻道中發生的狀態變更事件持續傳遞到應用。詳細的事件處理方式,請參閱 事件管理 > 頻道事件 文件。