跳轉至

頻道

建立頻道

若要建立聊天頻道,請建立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 受邀使用者的Player ID(僅ONE_ON_ONE必填) long N

建立ONE_ON_ONE頻道時,將type設為ONE_ON_ONE,並在otherPlayerId中填入對方的Player ID。不要傳入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()方法。

只有建立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()方法。

傳入null代替GetChannelsParams物件時,傳回目前所有頻道,不進行篩選。

若要在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

查詢到的頻道資訊,可查看頻道ID、參與人數及是否允許查詢訊息歷史。

欄位名稱 說明 類型
channelId 頻道 ID string
type 頻道類型 (PRIVATE, PUBLIC, GROUP) enum
owner 頻道擁有者的Hive Player ID 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

注意事項

傳入null代替GetChannelsParams物件時,傳回目前所有頻道,不進行篩選。查詢對象為PUBLIC、PRIVATE和GROUP頻道,不包含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

查詢到的頻道資訊,可查看頻道ID、參與人數及是否允許查詢訊息歷史。

欄位名稱 說明 類型
channelId 頻道 ID string
type 頻道類型 (PRIVATE, PUBLIC, GROUP) enum
owner 頻道擁有者的Hive Player ID 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

頻道成員資訊,可查看Player ID和連線時間。

欄位名稱 說明 類型
playerId Hive Player ID 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()方法。 傳回值與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)以載入歷史聊天記錄。

僅可查詢chatHistoryAllowed屬性為true的頻道的訊息歷史。

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>

在查詢結果的每個ChannelMessage中,透過messageReaction查看訊息的反應統計。伺服器簡化統計時,simplified為true,各反應編號的使用者列表playerIds為空。此時使用者列表為空並不代表沒有反應。

若要查看詳細資訊或自己的反應狀態,請參閱查詢頻道訊息反應。

此範例以特定訊息ID為基準,查詢之前和之後各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伺服器連線狀態,持續向應用程式傳遞使用者和頻道的狀態變化事件。處理方法請參閱事件管理 > 頻道事件。