跳转至

消息

聊天功能支持向用户已加入的频道发送频道消息,以及向特定对象直接发送私信。

发送频道消息

要向已加入的频道发送消息,请创建ChannelSendMessageParams对象,并作为参数调用Chat类的sendMessage()方法。

sendMessage() 方法返回传输结果和用于发送的 ChannelSendMessageParams,作为 retryParam。 如果传输失败,您可以尝试使用 retryParams 进行重新发送。

通道发送消息参数

ChannelSendMessageParams对象指定目标频道、消息内容、回复对象及提及对象。

字段名称 描述 类型 必需
channelId 消息发送目标频道ID string Y
message 要发送到频道的消息
(最多200个字符)
字符串 是
extraData 频道消息附加信息
以UTF-8计,最多256字节
string N
replyMessageId 正在回复的消息ID 字符串 否
mentionedPlayerIds 提及对象的Hive Player ID list <long> N

此示例向已加入的频道发送基本消息。

using hive;

ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";
channelSendMessageParams.extraData = "EXTRA_DATA";

Chat.sendMessage(channelSendMessageParams, (ResultAPI result, ChannelSendMessageParams retryParams) => {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送

    }
});
#include "HiveChat.h"

FHiveChatChannelSendMessageParams ChannelSendMessageParams;
ChannelSendMessageParams.ChannelId = TEXT("CHANNEL_ID");
ChannelSendMessageParams.Message = TEXT("你好 Hive");
ChannelSendMessageParams.ExtraData = TEXT("EXTRA_DATA");

FHiveChat::SendMessageWithChannelSendMessageParams(ChannelSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatChannelSendMessageParams& RetryParams) {
    if (!Result.IsSuccess) {
        // 消息发送失败,尝试使用 `RetryParams` 重新发送
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
  using namespace hive;

ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "你好 Hive";
params.extraData = "EXTRA_DATA";

Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result, ChannelSendMessageParams const & retryParams) {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "你好 Hive",
    extraData = "EXTRA_DATA"
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
    override fun onResult(
        result: ResultAPI,
        retryParams: Chat.ChannelSendMessageParams?
    ) {
        if (!result.isSuccess) {
            // 消息发送失败,尝试使用 `retryParams` 重新发送
        }
    }
})
import com.hive.Chat;

Chat.ChannelSendMessageParams params = new Chat.ChannelSendMessageParams(
    "CHANNEL_ID",
    "你好 Hive",
    "EXTRA_DATA"
);

Chat.sendMessage(params, (result, retryParams) -> {
    if(!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import HIVEService

let params = HiveChatParams.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "你好 Hive",
    extraData = "EXTRA_DATA"
)
ChatInterface.sendMessage(params) { result, retryParams in
    if !result.isSuccess() {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
}
#import "HIVEService.h"

HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = "CHANNEL_ID";
sendMessageParams.message = "你好,Hive";
sendMessageParams.extraData = "EXTRA_DATA";

[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatChannelSendMessageParams * retryParams) {
    if (![result isSuccess]) {
        // 消息发送失败。尝试使用 `retryParams` 重新发送
    }
}];

此示例回复已加入频道中的特定消息。

using hive;

ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";
channelSendMessageParams.replyMessageId = "TARGET_MESSAGE_ID";

Chat.sendMessage(channelSendMessageParams, (ResultAPI result, ChannelSendMessageParams retryParams) => {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送

    }
});
#include "HiveChat.h"

FHiveChatChannelSendMessageParams ChannelSendMessageParams;
ChannelSendMessageParams.ChannelId = TEXT("CHANNEL_ID");
ChannelSendMessageParams.Message = TEXT("你好,Hive");
ChannelSendMessageParams.ReplyMessageId = TEXT("TARGET_MESSAGE_ID");

FHiveChat::SendMessageWithChannelSendMessageParams(ChannelSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatChannelSendMessageParams& RetryParams) {
    if (!Result.IsSuccess) {
        // 消息发送失败,尝试使用 `RetryParams` 重新发送
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
  using namespace hive;

ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "你好 Hive";
params.replyMessageId = "TARGET_MESSAGE_ID";

Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result, ChannelSendMessageParams const & retryParams) {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "你好 Hive",
    replyMessageId = "TARGET_MESSAGE_ID"
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
    override fun onResult(
        result: ResultAPI,
        retryParams: Chat.ChannelSendMessageParams?
    ) {
        if (!result.isSuccess) {
            // 消息发送失败,尝试使用 `retryParams` 重新发送
        }
    }
})
import com.hive.Chat;

Chat.ChannelSendMessageParams params = new Chat.ChannelSendMessageParams(
    "CHANNEL_ID",
    "你好 Hive",
    "EXTRA_DATA",
    "TARGET_MESSAGE_ID"
);

Chat.sendMessage(params, (result, retryParams) -> {
    if(!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import HIVEService

let params = HiveChatParams.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "你好 Hive",
    replyMessageId = "TARGET_MESSAGE_ID"
)
ChatInterface.sendMessage(params) { result, retryParams in
    if !result.isSuccess() {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
}
#import "HIVEService.h"

HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = "CHANNEL_ID";
sendMessageParams.message = "你好 Hive";
sendMessageParams.replyMessageId = "TARGET_MESSAGE_ID";

[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatChannelSendMessageParams * retryParams) {
    if (![result isSuccess]) {
        // 消息发送失败。尝试使用 `retryParams` 重新发送
    }
}];

此示例在已加入的频道中发送提及特定用户的消息。

using hive;

ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";

List<long> playerIds = new List<long>();
playerIds.Add(1234);  // 用户1的Hive Player ID
playerIds.Add(5678);  // 用户2的Hive Player ID
channelSendMessageParams.mentionedPlayerIds = playerIds;

Chat.sendMessage(channelSendMessageParams, (ResultAPI result, ChannelSendMessageParams retryParams) => {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送

    }
});
#include "HiveChat.h"

FHiveChatChannelSendMessageParams ChannelSendMessageParams;
ChannelSendMessageParams.ChannelId = TEXT("CHANNEL_ID");
ChannelSendMessageParams.Message = TEXT("你好 Hive");

TArray<int64> PlayerIds;
PlayerIds.Add(1234); // 用户1的Hive Player ID
PlayerIds.Add(5678); // 用户2的Hive Player ID
ChannelSendMessageParams.MentionedPlayerIds = PlayerIds;

FHiveChat::SendMessageWithChannelSendMessageParams(ChannelSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatChannelSendMessageParams& RetryParams) {
    if (!Result.IsSuccess) {
        // 消息发送失败,尝试使用 `RetryParams` 重新发送
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
  using namespace hive;

ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "你好 Hive";

std::vector<int64_t> playerIds;
playerIds.push_back(1234);  // 用户1的Hive Player ID
playerIds.push_back(5678);  // 用户2的Hive Player ID
params.mentionedPlayerIds = playerIds;

Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result, ChannelSendMessageParams const & retryParams) {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val playerIds = listOf(1234L, 5678L) // 用户1、2的Hive Player ID
val params = Chat.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "Hello Hive",
    replyMessageId = "TARGET_MESSAGE_ID",
    mentionedPlayerIds = playerIds
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
    override fun onResult(
        result: ResultAPI,
        retryParams: Chat.ChannelSendMessageParams?
    ) {
        if (!result.isSuccess) {
            // 消息发送失败,尝试使用 `retryParams` 重新发送
        }
    }
})
import com.hive.Chat;

List<Long> mentionedPlayerIds = new ArrayList<>();
mentionedPlayerIds.add(1234L); // 用户1的Hive Player ID
mentionedPlayerIds.add(5678L); // 用户2的Hive Player ID

Chat.ChannelSendMessageParams params = new Chat.ChannelSendMessageParams(
    "CHANNEL_ID",
    "你好 Hive",
    "EXTRA_DATA"
);
params.mentionedPlayerIds = mentionedPlayerIds;

Chat.sendMessage(params, (result, retryParams) -> {
    if(!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import HIVEService

var playerIds: [Int64] = [1234, 5678] // 用户1、2的Hive Player ID

let params = HiveChatParams.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "你好 Hive",
    mentionedPlayerIds = playerIds
)
ChatInterface.sendMessage(params) { result, retryParams in
    if !result.isSuccess() {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
}
#import "HIVEService.h"

HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = @"CHANNEL_ID";
sendMessageParams.message = @"你好 Hive";

NSMutableArray<NSNumber *> *playerIds = [NSMutableArray array];
[playerIds addObject:@(1234)]; // 用户1的Hive Player ID
[playerIds addObject:@(5678)]; // 用户2的Hive Player ID
sendMessageParams.mentionedPlayerIds = playerIds;

[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatChannelSendMessageParams * retryParams) {
    if (![result isSuccess]) {
        // 消息发送失败。尝试使用 `retryParams` 重新发送
    }
}];

设置与清除频道消息反应

频道消息反应表示用户对消息的回应。使用setReaction()和clearReaction()设置或清除反应,并通过频道事件接收变更以更新界面。

反应类型通过1~200的reactionIndex区分。Hive仅传递编号。请在应用中定义各编号对应的表情、贴纸等含义。

设置反应的条件

用户可对已加入频道的消息留下反应,每位用户每条消息仅能留下一个反应,不能对公告消息留下反应。

对已留下反应的消息使用不同编号调用setReaction()会替换原反应;使用相同编号则保持不变。clearReaction()无需指定编号即可清除自己的反应。

处理结果与事件

setReaction()和clearReaction()的结果不包含反应统计。变更通过onSetReaction和onClearReaction传递给所有频道成员,也包括操作者本人。请接收事件并更新界面的反应信息。

替换反应时仅传递包含新编号的onSetReaction事件,不传递onClearReaction。请参阅事件管理 > 频道事件。

区分点赞与反应统计

反应与点赞(Like)分别统计。同时使用时,一条消息会同时存在两种统计,应用需分别显示。

设置与清除示例

此示例设置或清除已加入频道中消息的反应。

using hive;

String messageId = "TARGET_MESSAGE_ID";
int reactionIndex = 5; // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
channel.setReaction(messageId, reactionIndex, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});

// 清除反应
channel.clearReaction(messageId, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include "HiveChat.h"

FString MessageId = TEXT("TARGET_MESSAGE_ID");
int32 ReactionIndex = 5; // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
channel.SetReaction(MessageId, ReactionIndex, FHiveChannelSetReactionDelegate([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API Call Success
    }
}));

// 清除反应
channel.ClearReaction(MessageId, FHiveChannelClearReactionDelegate([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API Call Success
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string messageId = "TARGET_MESSAGE_ID";
int reactionIndex = 5; // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
channel.setReaction(messageId, reactionIndex, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API Call Success
    }
});

// 清除反应
channel.clearReaction(messageId, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import com.hive.Chat
import com.hive.ResultAPI

val messageId = "TARGET_MESSAGE_ID"
val reactionIndex = 5 // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
channel.setReaction(messageId, reactionIndex, object: Chat.ReactionResultListener {
    override fun onResult(result: ResultAPI, reactionIndex: Int) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})

// 清除反应
channel.clearReaction(messageId, object: Chat.ReactionResultListener {
    override fun onResult(result: ResultAPI, reactionIndex: Int) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})
import com.hive.Chat;
import com.hive.ResultAPI;

String messageId = "TARGET_MESSAGE_ID";
int reactionIndex = 5; // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
channel.setReaction(messageId, reactionIndex, new Chat.ReactionResultListener() {
    @Override
    public void onResult(@NonNull ResultAPI result, int reactionIndex) {
        if (result.isSuccess()) {
            // API Call Success
        }
    }
});

// 清除反应
channel.clearReaction(messageId, new Chat.ReactionResultListener() {
    @Override
    public void onResult(@NonNull ResultAPI result, int reactionIndex) {
        if (result.isSuccess()) {
            // API Call Success
        }
    }
});
import HIVEService

let messageId = "TARGET_MESSAGE_ID"
let reactionIndex = 5 // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
channel.setReaction(messageId: messageId, reactionIndex: reactionIndex) { result in
    if result.isSuccess() {
        // API Call Success
    }
}

// 清除反应
channel.clearReaction(messageId: messageId) { result in
    if result.isSuccess() {
        // API Call Success
    }
}
#import "HIVEService.h"

NSString *messageId = @"TARGET_MESSAGE_ID";
NSInteger reactionIndex = 5; // 游戏定义的反应编号(1~200)

// 设置反应(替换已有反应)
[channel setReactionWithMessageId:messageId reactionIndex:reactionIndex listener:^(HIVEResultAPI *result) {
    if ([result isSuccess]) {
        // API Call Success
    }
}];

// 清除反应
[channel clearReactionWithMessageId:messageId listener:^(HIVEResultAPI *result) {
    if ([result isSuccess]) {
        // API Call Success
    }
}];

查询频道消息反应

在频道消息历史查询结果的各ChannelMessage中,通过messageReaction查看反应统计。反应较多时服务器会简化统计,因此需单独查询详细信息或自己的反应状态。

简化统计中simplified为true,各编号对应的Hive Player ID列表playerIds为空,但仍传递总数totalCount和各编号数量count。

选择查询方法

要按编号查看消息的全部反应,请调用getReactions()。该方法返回包含Hive Player ID列表的MessageReaction,且simplified始终为false。

要仅查看已登录用户的反应,请调用getMyReaction(),该方法返回PlayerReaction。可在重新连接后或历史统计已简化、无法确认自身反应时使用,不能查询其他用户的反应。

MessageReaction

消息的完整反应统计。通过reactions查看各编号的统计,并保持服务器传递的列表顺序显示。

字段名 说明 类型 值与条件
simplified 是否简化统计 boolean 为true时省略各编号的playerIds,仅传递count
totalCount 消息反应总数 integer 留下反应的用户数
reactions 按反应编号统计的列表 list<ReactionSummary> 从最近添加的反应编号开始排序

ReactionSummary

特定反应编号对应的用户数及Hive Player ID列表,作为MessageReaction.reactions中的各项传递。

字段名 说明 类型 值与条件
reactionIndex 反应编号 integer 1~200
count 留下该反应的用户数 integer 按该反应编号统计
playerIds 留下该反应的Hive Player ID列表 list<long> simplified为true时为空列表

PlayerReaction

表示已登录用户是否对特定消息留下反应。请先检查reacted,再使用reactionIndex。

字段名 说明 类型 值与条件
messageId 消息ID string 查询的消息
playerId Hive Player ID long 已登录用户
reacted 是否已留下反应 boolean 自己的反应状态
reactionIndex 已留下的反应编号 integer 已留下时为1~200,未留下时的值不是有效编号

查询反应示例

此示例查询特定消息的全部反应及自己的反应。

using hive;

String messageId = "TARGET_MESSAGE_ID";

// 查询消息的全部反应
channel.getReactions(messageId, (ResultAPI result, MessageReaction messageReaction) => {
    if (result.isSuccess() && messageReaction != null) {
        foreach (ReactionSummary summary in messageReaction.reactions) {
            // summary.reactionIndex, summary.count, summary.playerIds
        }
    }
});

// 查询自己的反应
channel.getMyReaction(messageId, (ResultAPI result, PlayerReaction playerReaction) => {
    if (result.isSuccess() && playerReaction != null && playerReaction.reacted) {
        // playerReaction.reactionIndex
    }
});
#include "HiveChat.h"

FString MessageId = TEXT("TARGET_MESSAGE_ID");

// 查询消息的全部反应
channel.GetReactions(MessageId, FHiveChannelGetReactionsDelegate([this](const FHiveResultAPI& Result, const FHiveMessageReaction& MessageReaction) {
    if (Result.IsSuccess()) {
        for (const FHiveReactionSummary& Summary : MessageReaction.reactions) {
            // Summary.reactionIndex, Summary.count, Summary.playerIds
        }
    }
}));

// 查询自己的反应
channel.GetMyReaction(MessageId, FHiveChannelGetMyReactionDelegate([this](const FHiveResultAPI& Result, const FHivePlayerReaction& PlayerReaction) {
    if (Result.IsSuccess() && PlayerReaction.reacted) {
        // PlayerReaction.reactionIndex
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string messageId = "TARGET_MESSAGE_ID";

// 查询消息的全部反应
channel.getReactions(messageId, [=](ResultAPI const & result, MessageReaction const & messageReaction) {
    if (result.isSuccess()) {
        for (auto const & summary : messageReaction.reactions) {
            // summary.reactionIndex, summary.count, summary.playerIds
        }
    }
});

// 查询自己的反应
channel.getMyReaction(messageId, [=](ResultAPI const & result, PlayerReaction const & playerReaction) {
    if (result.isSuccess() && playerReaction.reacted) {
        // playerReaction.reactionIndex
    }
});
import com.hive.Chat
import com.hive.ResultAPI

val messageId = "TARGET_MESSAGE_ID"

// 查询消息的全部反应
channel.getReactions(messageId, object: Chat.GetReactionsListener {
    override fun onResult(result: ResultAPI, messageId: String, messageReaction: Chat.MessageReaction?) {
        if (result.isSuccess && messageReaction != null) {
            messageReaction.reactions.forEach { entry ->
                // entry.reactionIndex, entry.count, entry.playerIds
            }
        }
    }
})

// 查询自己的反应
channel.getMyReaction(messageId, object: Chat.GetMyReactionListener {
    override fun onResult(result: ResultAPI, playerReaction: Chat.PlayerReaction?) {
        if (result.isSuccess && playerReaction?.reacted == true) {
            // playerReaction.reactionIndex
        }
    }
})
import com.hive.Chat;
import com.hive.ResultAPI;

String messageId = "TARGET_MESSAGE_ID";

// 查询消息的全部反应
channel.getReactions(messageId, new Chat.GetReactionsListener() {
    @Override
    public void onResult(@NonNull ResultAPI result, @NonNull String messageId, Chat.MessageReaction messageReaction) {
        if (result.isSuccess() && messageReaction != null) {
            for (Chat.ReactionSummary entry : messageReaction.getReactions()) {
                // entry.getReactionIndex(), entry.getCount(), entry.getPlayerIds()
            }
        }
    }
});

// 查询自己的反应
channel.getMyReaction(messageId, new Chat.GetMyReactionListener() {
    @Override
    public void onResult(@NonNull ResultAPI result, Chat.PlayerReaction playerReaction) {
        if (result.isSuccess() && playerReaction != null && playerReaction.getReacted()) {
            // playerReaction.getReactionIndex()
        }
    }
});
import HIVEService

let messageId = "TARGET_MESSAGE_ID"

// 查询消息的全部反应
channel.getReactions(messageId: messageId) { result, reaction in
    if result.isSuccess(), let reaction {
        reaction.reactions.forEach { summary in
            // summary.reactionIndex, summary.count, summary.playerIds
        }
    }
}

// 查询自己的反应
channel.getMyReaction(messageId: messageId) { result, reaction in
    if result.isSuccess(), let reaction, reaction.reacted {
        // reaction.reactionIndex
    }
}
#import "HIVEService.h"

NSString *messageId = @"TARGET_MESSAGE_ID";

// 查询消息的全部反应
[channel getReactionsWithMessageId:messageId listener:^(HIVEResultAPI *result, HiveChatMessageReaction *reaction) {
    if ([result isSuccess] && reaction) {
        for (HiveChatReactionSummary *summary in reaction.reactions) {
            // summary.reactionIndex, summary.count, summary.playerIds
        }
    }
}];

// 查询自己的反应
[channel getMyReactionWithMessageId:messageId listener:^(HIVEResultAPI *result, HiveChatPlayerReaction *reaction) {
    if ([result isSuccess] && reaction.reacted) {
        // reaction.reactionIndex
    }
}];

添加与移除频道消息点赞

addReaction()和removeReaction()用于添加或移除已加入频道中消息的点赞。这是使用ReactionType.Like的点赞专用功能,即将停止支持。

实现新反应功能时,请使用设置与清除反应中的setReaction()和clearReaction()。

此示例添加或移除已加入频道中消息的点赞。

using hive;

String messageId = "TARGET_MESSAGE_ID";
ReactionType type = ReactionType.Like;

channel.addReaction(messageId, type, (ResultAPI result, ReactionType reactionType) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});

channel.removeReaction(messageId, type, (ResultAPI result, ReactionType reactionType) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include "HiveChat.h"

FString MessageId = TEXT("TARGET_MESSAGE_ID");
EReactionType Type = EReactionType::Like;

channel.AddReaction(MessageId, Type, FHiveChatOnReactionDelegate::CreateLambda([this](const FHiveResultAPI& Result, EReactionType Type) {
    if (Result.IsSuccess()) {
        // API Call Success
    }
}));

channel.RemoveReaction(MessageId, Type, FHiveChatOnReactionDelegate::CreateLambda([this](const FHiveResultAPI& Result, EReactionType Type) {
    if (Result.IsSuccess()) {
        // API Call Success
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string messageId = "TARGET_MESSAGE_ID";
ReactionType type = ReactionType::Like;

channel.addReaction(messageId, type, [=](ResultAPI const & result, ReactionType type) {
    if (result.isSuccess()) {
        // API Call Success
    }
});

channel.removeReaction(messageId, type, [=](ResultAPI const & result, ReactionType type) {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val messageId = "TARGET_MESSAGE_ID"
val type = Chat.ReactionType.Like;

channel.addReaction(messageId, type, object: Chat.ReactionListener {
    override fun onResult(result: ResultAPI, type: Chat.ReactionType) {
        if (result.isSuccess()) {
            // API Call Success
        }
    }
})

channel.removeReaction(messageId, type, object: Chat.ReactionListener {
    override fun onResult(result: ResultAPI, type: Chat.ReactionType) {
        if (result.isSuccess()) {
            // API Call Success
        }
    }
})
import com.hive.Chat;

String messageId = "TARGET_MESSAGE_ID";
Chat.ReactionType type = Chat.ReactionType.Like;

Chat.addReaction(messageId, type, new Chat.ReactionListener() {
    @Override
    public void onResult(ResultAPI result, ReactionType type) {
        if (result.isSuccess()) {
            // API Call Success
        }
    }
});

Chat.removeReaction(messageId, type, new Chat.ReactionListener() {
    @Override
    public void onResult(ResultAPI result, ReactionType type) {
        if (result.isSuccess()) {
            // API Call Success
        }
    }
});
import HIVEService

let messageId = "TARGET_MESSAGE_ID"
let reactionType: ReactionType = .like

ChatInterface.addReaction(messageId: messageId, type: reactionType) { result, type in
    if result.isSuccess() {
        // API 调用成功
    }
}

ChatInterface.removeReaction(messageId: messageId, type: reactionType) { result, type in
    if result.isSuccess() {
        // API Call Success
    }
}
#import "HIVEService.h"

NSString *messageId = @"TARGET_MESSAGE_ID";
HiveChatReactionType reactionType = HiveChatReactionTypeLike;

[channel addReactionWithMessageId:messageId type:reactionType handler:^(ResultAPI *result, HiveChatReactionType type) {
    if ([result isSuccess]) {
        // API 调用成功
    }
}];

[channel removeReactionWithMessageId:messageId type:reactionType handler:^(ResultAPI *result, HiveChatReactionType type) {
    if ([result isSuccess]) {
        // API Call Success
    }
}];

频道消息事件管理

通过addChannelListener事件处理器的onChannelMessage事件接收已发送消息。请参阅事件管理 > 频道事件。

1:1 消息发送

要向特定对象发送私信,请创建DirectSendMessageParams对象,并作为参数调用Chat类的sendMessage()方法。

sendMessage() 方法返回传输结果以及在传输过程中使用的 DirectSendMessageParams,其名称为 retryParam。 如果传输失败,您可以尝试使用 retryParams 重新发送。

直接发送消息参数

DirectSendMessageParams对象指定接收用户及消息内容。

字段名称 描述 类型 必需
toPlayerId 目标用户的Hive Player ID long Y
message 发送给目标用户的消息
(最多200个字符)
string Y
extraData 私信附加信息
以UTF-8计,最多256字节
string N

此示例向特定对象直接发送消息。

using hive;

DirectSendMessageParams directSendMessageParams = new DirectSendMessageParams();
directSendMessageParams.toPlayerId = 12345678;
directSendMessageParams.message = "你好 Hive";
directSendMessageParams.extraData = "EXTRA_DATA";

Chat.sendMessage(directSendMessageParams, (ResultAPI result, DirectSendMessageParams retryParams) => {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送

    }
});
#include "HiveChat.h"

FHiveChatDirectSendMessageParams DirectSendMessageParams = FHiveChatDirectSendMessageParams();
DirectSendMessageParams.ToPlayerId = 12345678l;
DirectSendMessageParams.Message = TEXT("你好 Hive");
DirectSendMessageParams.ExtraData = TEXT("EXTRA_DATA");

FHiveChat::SendMessageWithDirectSendMessageParams(DirectSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatDirectSendMessageParams& RetryParams) {
    if (!Result.IsSuccess) {
        // 消息发送失败,尝试使用 `RetryParams` 重新发送
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

DirectSendMessageParams params;
params.toPlayerId = 12345678;
params.message = "你好 Hive";
params.extraData = "EXTRA_DATA";

Chat::sendMessageWithDirectSendMessageParams(params, [=](ResultAPI const & result, DirectSendMessageParams const & retryParams) {
    if (!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.DirectSendMessageParams(
    toPlayerId = 12345678,
    message = "你好 Hive",
    extraData = "EXTRA_DATA"
)

Chat.sendMessage(params, object: Chat.SendMessageListener {
    override fun onResult(
        result: ResultAPI,
        retryParams: Chat.DirectSendMessageParams?
    ) {
        if (!result.isSuccess) {
            // 消息发送失败,尝试使用 `retryParams` 重新发送
        }
    }
})
import com.hive.Chat;

Chat.DirectSendMessageParams params = new Chat.DirectSendMessageParams(
        12345678,
        "Hello Hive",
        "EXTRA_DATA"
);

Chat.sendMessage(params, (result, retryParams) -> {
    if(!result.isSuccess()) {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
});
import HIVEService

let params = HiveChatParams.DirectSendMessageParams(toPlayerId: Int64(12345678), message: "Hello Hive", extraData: "EXTRA_DATA")

ChatInterface.sendMessage(sendMessageParams: params) { result, retryParams in
    if !result.isSuccess() {
        // 消息发送失败,尝试使用 `retryParams` 重新发送
    }
}
#import "HIVEService.h"

HiveChatDirectSendMessageParams* sendMessageParams = [[HiveChatDirectSendMessageParams alloc] init];
sendMessageParams.toPlayerId = 12345678;
sendMessageParams.message = "你好 Hive";
sendMessageParams.extraData = "EXTRA_DATA";

[HiveChat sendDirectMessageWithSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatDirectSendMessageParams * retryParams) {
    if (![result isSuccess]) {
        // 消息发送失败。尝试使用 `retryParams` 重新发送
    }
}];

1:1 消息事件管理

通过addUserListener事件处理器的onDirectMessage事件接收私信。请参阅事件管理 > 用户事件。

消息翻译请求

尝试请求该消息的翻译。 语言代码基于ISO 639 alpha-2标准。

翻译参数

TranslateParams对象指定待翻译消息、源语言及目标语言。

字段名称 描述 类型 必需
message 消息 字符串 是
sourceLanguage 消息语言代码。省略时使用auto检测语言。 string N
targetLanguages 目标语言代码数组 string array Y
using hive;

List<String> targetLanguages = new List<String>();
targetLanguages.Add("ko");
targetLanguages.Add("ja");
targetLanguages.Add("ar");

TranslateParams translateParams = new TranslateParams("hello", "auto", targetLanguages);

Chat.translate(translateParams, (ResultAPI result, TranslationData data) => {
    if (result.isSuccess() && data != null) {
        // data is translate languages
    }
});
#include "HiveChat.h"

TArray<FString> TargetLanguages;
TargetLanguages.Add(TEXT("ko"));
TargetLanguages.Add(TEXT("ja"));
TargetLanguages.Add(TEXT("ar"));

FHiveChatTranslateParams TranslateParams = FHiveChatTranslateParams(TEXT("你好"), TEXT("auto"), TargetLanguages);

FHiveChat::Translate(TranslateParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatTranslationData& data) {
    if (Result.ISSuccess && data != null) {
        // data 是翻译语言消息
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::vector<std::string> targetLanguages = { "ko", "ja", "ar" };

Chat::TranslateParams translateParams = new Chat::TranslateParams("你好", "auto", targetLanguages);

Chat::translate(translateParams, [=](ResultAPI const & result, Chat::TranslationData const & data) {
    if (!result.isSuccess() && data != null ) {
        // data is translate language messages
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

var translateParams = Chat.TranslateParams(
    message = "你好",
    sourceLanguage = "auto",
    targetLanguages = ["ko", "ja", "ar"]
)

Chat.translate(translateParams, object: Chat.TranslateParamsListener {
    override fun onResult(
        result: ResultAPI,
        data: Chat.TranslationData?
    ) {
        if (!result.isSuccess && data != null) {
            // data is translate language maessages
        } 
    }
})
import com.hive.Chat;

Chat.TranslateParams translateParams = new Chat.TranslateParams(
    "hello",
    "auto",
    ["ko", "ja", "ar"]
);

Chat.translate(translateParams, (result, data) -> {
    if(result.isSuccess() && data != null) {
        // data is translate language messages
    }
});
import HIVEService

let translateParams = HiveChatParams.TranslateParams("hello", "auto", ["ko", "ja", "ar"])
ChatInterface.translate(params: translateParams) { result, data in
    if result.isSuccess(), let data {
        // data is translate language messages
    }
}
#import "HIVEService.h"

NSArray<NSString *> *targetLanguages = @[@"ko", @"ja", @"ar"];
HiveChatTranslateParams translateParams = [[HiveChatTranslateParams alloc] message: @"hello"
                                                                           sourceLanguage: @"auto"
                                                                           targetLanguages: targetLanguages];


[HiveChat translateWithParams: translateParams
          handler:^(HIVEResultAPI * result, HiveChatTranslationData * data) {
            if ([result isSuccess] && data) {
                // data 是翻译语言消息
            }
          }];

举报频道消息

要举报消息,请创建ReportMessageParams对象,并作为参数调用Chat类的reportMessage()方法。

ReportMessageParams

ReportMessageParams对象指定要举报的消息、作者及举报原因。

字段名 说明 类型 是否必填
channelId 要举报消息所在的频道 ID string Y
messageId 要举报的消息 ID string Y
reporteePlayerId 被举报消息作者的Hive Player ID long Y
reasonType 举报原因 (INSULT, FRAUD, SPAM, ETC) enum Y
reasonDetail 详细举报原因(当 reasonType 为 ETC 时输入,其他情况下可填写 null 或省略) string N

基本举报请求示例

当以辱骂为由举报消息时,请使用以下调用方式。

using hive;

ReportMessageParams reportMessageParams = new ReportMessageParams();
reportMessageParams.channelId = "abc";
reportMessageParams.messageId = "x8LIIIDbuVentUdL";
reportMessageParams.reporteePlayerId = 12345678;
reportMessageParams.reasonType = ReasonType.INSULT;

Chat.reportMessage(reportMessageParams, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API call succeeded
    }
});
// Coming soon
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

ReportMessageParams reportMessageParams;
reportMessageParams.channelId = "abc";
reportMessageParams.messageId = "x8LIIIDbuVentUdL";
reportMessageParams.reporteePlayerId = 12345678;
reportMessageParams.reasonType = ReasonType.INSULT;

Chat::reportMessage(params, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API call succeeded
    }
});
val params = Chat.ReportMessageParam(
    channelId = "abc",
    messageId = "x8LIIIDbuVentUdL",
    reporteePlayerId = 12345678,
    reasonType = ReasonType.INSULT,
    reasonDetail = null
)

Chat.reportMessage(params, object : Chat.ReportMessageListener {
    override fun onResult(result: ResultAPI) {
        if(result.isSuccess) {
            // API call succeeded
        }
    }
})
Chat.ReportMessageParam params = new Chat.ReportMessageParam(
    "abc",
    "x8LIIIDbuVentUdL",
    12345678L,
    ReasonType.INSULT,
    null
);

Chat.reportMessage(params, new Chat.ReportMessageListener() {
    @Override
    public void onResult(ResultAPI result) {
        if (result.isSuccess()) {
            // API call succeeded
        }
    }
});
import HIVEService
let params = HiveChatParams.ReportMessageParams(
    channelId = "abc",
    messageId = "x8LIIIDbuVentUdL",
    reporteePlayerId = 12345678,
    reasonType = ReasonType.INSULT
)

ChatInterface.reportMessage(sendMessageParams: params) { result in
    if result.isSuccess() {
        // API call succeeded
    }
}
#import "HIVEService.h"

HiveChatReportMessageParams* reportMessageParams = [[HiveChatReportMessageParams alloc] init];
reportMessageParams.channelId = "abc";
reportMessageParams.messageId = "x8LIIIDbuVentUdL";
reportMessageParams.reporteePlayerId = 12345678;
reportMessageParams.reasonType = ReasonType.INSULT;

[HiveChat reportMessageWithReportMessageParams:reportMessageParams handler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API call succeeded
    }
}];

以其他原因举报

选择其他原因(reasonType 为 ETC)举报消息时,请同时填写详细原因(reasonDetail)。如果选择预定义的举报原因,则可以将详细原因留空或省略。