NIM PC Cross Platform SDK
载入中...
搜索中...
未找到
v2_nim_compatible_utilities.hpp
浏览该文件的文档.
1#ifndef V2_NIM_COMPATIBLE_UTILITIES_H
2#define V2_NIM_COMPATIBLE_UTILITIES_H
3#include "v2_nim_internal.hpp"
5namespace v2 {
8public:
17 static nim::IMMessage messageConvertToV1(const V2NIMMessage& message);
18
27 static V2NIMMessage messageConvertToV2(const nim::IMMessage& message);
28};
29
30// NOLINTBEGIN
32 nim::IMMessage v1Message;
33 v1Message.rescode_ = nim::kNIMResSuccess;
34 v1Message.feature_ = nim::kNIMMessageFeatureDefault;
36 v1Message.session_type_ = nim::kNIMSessionTypeP2P;
37 } else if (message.conversationType == V2NIM_CONVERSATION_TYPE_TEAM) {
38 v1Message.session_type_ = nim::kNIMSessionTypeTeam;
40 v1Message.session_type_ = nim::kNIMSessionTypeSuperTeam;
41 }
42 v1Message.receiver_accid_ = message.receiverId;
43 v1Message.sender_accid_ = message.senderId;
44 v1Message.timetag_ = static_cast<int64_t>(message.createTime);
45 v1Message.content_ = message.text;
46 v1Message.type_ = static_cast<nim::NIMMessageType>(message.messageType);
47 if (message.attachment) {
48 v1Message.attach_ = message.attachment->raw;
49 }
50 v1Message.client_msg_id_ = message.messageClientId;
61 v1Message.msg_setting_.server_ext_ = message.serverExtension ? message.serverExtension->c_str() : "";
62 v1Message.msg_setting_.local_ext_ = message.localExtension ? *message.localExtension : "";
64 for (auto&& forcePushAccountId : message.pushConfig.forcePushAccountIds) {
65 v1Message.msg_setting_.force_push_ids_list_.push_back(forcePushAccountId);
66 }
76
77 v1Message.third_party_callback_ext_ = message.callbackExtension ? *message.callbackExtension : "";
78 v1Message.sub_type_ = static_cast<int32_t>(message.subType);
80 if (message.sendingState) {
82 v1Message.status_ = nim::kNIMMsgLogStatusSendFailed;
84 v1Message.status_ = nim::kNIMMsgLogStatusSending;
85 }
86 }
87 if (message.threadReply) {
88 v1Message.thread_info_.reply_msg_from_account_ = message.threadReply->senderId;
89 v1Message.thread_info_.reply_msg_to_account_ = message.threadReply->receiverId;
90 v1Message.thread_info_.reply_msg_time_ = message.threadReply->createTime;
91 v1Message.thread_info_.reply_msg_id_server_ = std::stoull(message.threadReply->messageServerId);
92 v1Message.thread_info_.reply_msg_id_client_ = message.threadReply->messageClientId;
93 }
94 if (message.threadRoot) {
95 v1Message.thread_info_.thread_msg_from_account_ = message.threadRoot->senderId;
96 v1Message.thread_info_.thread_msg_to_account_ = message.threadRoot->receiverId;
97 v1Message.thread_info_.thread_msg_time_ = message.threadRoot->createTime;
98 v1Message.thread_info_.thread_msg_id_server_ = std::stoull(message.threadRoot->messageServerId);
99 v1Message.thread_info_.thread_msg_id_client_ = message.threadRoot->messageClientId;
100 }
101 v1Message.robot_info_.account_ = message.robotConfig.accountId ? *message.robotConfig.accountId : "";
102 v1Message.robot_info_.function_ = message.robotConfig.function ? *message.robotConfig.function : "";
103 v1Message.robot_info_.topic_ = message.robotConfig.topic ? *message.robotConfig.topic : "";
105 v1Message.readonly_server_id_ = std::stoull(message.messageServerId);
106 return v1Message;
107}
109 V2NIMMessage v2Message;
111 if (message.session_type_ == nim::kNIMSessionTypeP2P) {
114 } else if (message.session_type_ == nim::kNIMSessionTypeTeam) {
117 } else if (message.session_type_ == nim::kNIMSessionTypeSuperTeam) {
120 }
121 v2Message.receiverId = message.receiver_accid_;
122 v2Message.senderId = message.sender_accid_;
123 v2Message.createTime = static_cast<uint64_t>(message.timetag_);
124 v2Message.text = message.content_;
125 v2Message.messageType = static_cast<V2NIMMessageType>(message.type_);
126 v2Message.attachment = nstd::make_shared<V2NIMMessageAttachment>();
127 v2Message.attachment->raw = message.attach_;
128 v2Message.messageClientId = message.client_msg_id_;
140 v2Message.localExtension = message.msg_setting_.local_ext_;
142 for (auto&& forcePushAccountId : message.msg_setting_.force_push_ids_list_) {
143 v2Message.pushConfig.forcePushAccountIds.push_back(forcePushAccountId);
144 }
155 v2Message.subType = message.sub_type_;
156 if (message.status_ == nim::kNIMMsgLogStatusSendFailed) {
158 } else if (message.status_ == nim::kNIMMsgLogStatusSending) {
160 }
161 if (!message.thread_info_.reply_msg_from_account_.empty()) {
162 v2Message.threadReply = V2NIMMessageRefer();
163 v2Message.threadReply->senderId = message.thread_info_.reply_msg_from_account_;
164 v2Message.threadReply->receiverId = message.thread_info_.reply_msg_to_account_;
165 v2Message.threadReply->createTime = message.thread_info_.reply_msg_time_;
166 v2Message.threadReply->messageServerId = std::to_string(message.thread_info_.reply_msg_id_server_);
167 v2Message.threadReply->messageClientId = message.thread_info_.reply_msg_id_client_;
168 }
169 if (!message.thread_info_.thread_msg_from_account_.empty()) {
170 v2Message.threadRoot = V2NIMMessageRefer();
171 v2Message.threadRoot->senderId = message.thread_info_.thread_msg_from_account_;
172 v2Message.threadRoot->receiverId = message.thread_info_.thread_msg_to_account_;
173 v2Message.threadRoot->createTime = message.thread_info_.thread_msg_time_;
174 v2Message.threadRoot->messageServerId = std::to_string(message.thread_info_.thread_msg_id_server_);
175 v2Message.threadRoot->messageClientId = message.thread_info_.thread_msg_id_client_;
176 }
177 v2Message.robotConfig.accountId = message.robot_info_.account_;
178 v2Message.robotConfig.function = message.robot_info_.function_;
179 v2Message.robotConfig.topic = message.robot_info_.topic_;
181 v2Message.messageServerId = std::to_string(message.readonly_server_id_);
182 return v2Message;
183}
184// NOLINTEND
185} // namespace v2
186#endif
Talk 辅助方法和数据结构定义
@ BS_TRUE
true
Definition: nim_sdk_util.h:28
@ BS_FALSE
false
Definition: nim_sdk_util.h:26
Definition: v2_nim_ai_service.hpp:4
V2NIMMessageType
Definition: v2_nim_def_enum.hpp:920
@ V2NIM_CONVERSATION_TYPE_P2P
单聊
Definition: v2_nim_def_enum.hpp:913
@ V2NIM_CONVERSATION_TYPE_UNKNOWN
未知
Definition: v2_nim_def_enum.hpp:911
@ V2NIM_CONVERSATION_TYPE_SUPER_TEAM
超大群
Definition: v2_nim_def_enum.hpp:917
@ V2NIM_CONVERSATION_TYPE_TEAM
群聊
Definition: v2_nim_def_enum.hpp:915
@ V2NIM_MESSAGE_SENDING_STATE_SENDING
发送中
Definition: v2_nim_def_enum.hpp:953
@ V2NIM_MESSAGE_SENDING_STATE_FAILED
发送失败
Definition: v2_nim_def_enum.hpp:951
const char * c_str() const
Definition: ne_stl_string.h:511
数据结构转换工具
Definition: v2_nim_compatible_utilities.hpp:7
static V2NIMMessage messageConvertToV2(const nim::IMMessage &message)
V1消息转换为V2
Definition: v2_nim_compatible_utilities.hpp:108
static nim::IMMessage messageConvertToV1(const V2NIMMessage &message)
V2消息转换为V1
Definition: v2_nim_compatible_utilities.hpp:31
bool pushNickEnabled
是否需要推送消息发送者昵称
Definition: v2_nim_def_struct.hpp:421
nstd::vector< nstd::string > forcePushAccountIds
强制推送目标账号列表
Definition: v2_nim_def_struct.hpp:431
bool forcePush
是否强制推送, 忽略用户提醒相关设置
Definition: v2_nim_def_struct.hpp:427
nstd::string pushPayload
推送数据
Definition: v2_nim_def_struct.hpp:425
nstd::string pushContent
推送文本
Definition: v2_nim_def_struct.hpp:423
bool pushEnabled
是否需要推送消息
Definition: v2_nim_def_struct.hpp:419
nstd::string forcePushContent
强制推送文案
Definition: v2_nim_def_struct.hpp:429
nstd::optional< nstd::string > antispamExtension
易盾反垃圾(增强检测数据), json格式, 限制长度 1024 字节
Definition: v2_nim_def_struct.hpp:463
bool antispamEnabled
指定是否需要过安全通
Definition: v2_nim_def_struct.hpp:453
nstd::optional< nstd::string > antispamCustomMessage
Definition: v2_nim_def_struct.hpp:459
nstd::optional< nstd::string > antispamCheating
易盾反作弊(辅助检测数据), json格式, 限制长度 1024 字节
Definition: v2_nim_def_struct.hpp:461
nstd::optional< nstd::string > antispamBusinessId
指定易盾业务id, 而不使用云信后台配置的
Definition: v2_nim_def_struct.hpp:455
nstd::optional< nstd::string > function
机器人具体功能, 用户可以自定义输入
Definition: v2_nim_def_struct.hpp:481
nstd::optional< nstd::string > customContent
机器人自定义内容
Definition: v2_nim_def_struct.hpp:483
nstd::optional< nstd::string > accountId
机器人账号, 仅群聊有效
Definition: v2_nim_def_struct.hpp:477
nstd::optional< nstd::string > topic
机器人消息话题
Definition: v2_nim_def_struct.hpp:479
bool routeEnabled
是否需要路由消息
Definition: v2_nim_def_struct.hpp:488
bool readReceiptEnabled
是否需要消息已读回执信息
Definition: v2_nim_def_struct.hpp:502
bool lastMessageUpdateEnabled
是否需要更新消息所属的会话信息
Definition: v2_nim_def_struct.hpp:504
bool historyEnabled
是否需要存历史消息
Definition: v2_nim_def_struct.hpp:506
bool onlineSyncEnabled
是否需要发送方多端在线同步消息
Definition: v2_nim_def_struct.hpp:510
bool unreadEnabled
是否需要计未读
Definition: v2_nim_def_struct.hpp:514
bool offlineEnabled
是否需要存离线消息
Definition: v2_nim_def_struct.hpp:512
bool roamingEnabled
是否需要存漫游消息
Definition: v2_nim_def_struct.hpp:508
Definition: v2_nim_def_struct.hpp:524
Definition: v2_nim_def_struct.hpp:623
V2NIMMessagePushConfig pushConfig
推送相关配置
Definition: v2_nim_def_struct.hpp:663
nstd::optional< nstd::string > localExtension
本地扩展
Definition: v2_nim_def_struct.hpp:651
uint64_t createTime
消息时间
Definition: v2_nim_def_struct.hpp:629
nstd::string conversationId
消息所属会话 ID
Definition: v2_nim_def_struct.hpp:639
nstd::optional< V2NIMMessageRefer > threadReply
回复消息引用
Definition: v2_nim_def_struct.hpp:673
V2NIMMessageConfig messageConfig
消息相关配置
Definition: v2_nim_def_struct.hpp:661
nstd::string receiverId
消息接收者账号
Definition: v2_nim_def_struct.hpp:635
V2NIMConversationType conversationType
消息所属会话类型
Definition: v2_nim_def_struct.hpp:637
V2NIMMessageAntispamConfig antispamConfig
反垃圾相关配置
Definition: v2_nim_def_struct.hpp:667
nstd::optional< nstd::string > serverExtension
服务端扩展
Definition: v2_nim_def_struct.hpp:649
V2NIMMessageRouteConfig routeConfig
路由抄送相关配置
Definition: v2_nim_def_struct.hpp:665
nstd::string senderId
消息发送者账号
Definition: v2_nim_def_struct.hpp:631
nstd::optional< nstd::string > callbackExtension
回调扩展
Definition: v2_nim_def_struct.hpp:653
nstd::optional< V2NIMMessageRefer > threadRoot
Thread 消息引用
Definition: v2_nim_def_struct.hpp:671
uint32_t subType
消息内容
Definition: v2_nim_def_struct.hpp:643
nstd::shared_ptr< V2NIMMessageAttachment > attachment
消息附属附件
Definition: v2_nim_def_struct.hpp:647
nstd::string messageServerId
服务端消息 ID
Definition: v2_nim_def_struct.hpp:627
V2NIMMessageRobotConfig robotConfig
机器人相关配置
Definition: v2_nim_def_struct.hpp:669
nstd::optional< V2NIMMessageSendingState > sendingState
消息发送状态
Definition: v2_nim_def_struct.hpp:655
V2NIMMessageType messageType
消息类型
Definition: v2_nim_def_struct.hpp:641
nstd::string messageClientId
客户端消息 ID
Definition: v2_nim_def_struct.hpp:625
nstd::string text
消息文本
Definition: v2_nim_def_struct.hpp:645
static nstd::string superTeamConversationId(const nstd::string &superTeamId)
获取超级群会话ID
Definition: v2_nim_internal.hpp:252
static nstd::string p2pConversationId(const nstd::string &accountId)
获取点对点会话ID
Definition: v2_nim_internal.hpp:246
static nstd::string teamConversationId(const nstd::string &teamId)
获取群组会话ID
Definition: v2_nim_internal.hpp:249
static nstd::string parseConversationTargetId(const nstd::string &conversationId)
获取会话ID对应的目标ID
Definition: v2_nim_internal.hpp:258
nim_cpp_wrapper_util::Json::Value push_payload_
第三方自定义的推送属性,长度2048
Definition: nim_talk_helper.h:46
std::string anti_spam_ext
(可选)String, 易盾反垃圾扩展字段,限制 json,长度限制 1024
Definition: nim_talk_helper.h:82
std::string anti_apam_biz_id_
(可选)用户配置的对某些单条消息另外的反垃圾的业务ID
Definition: nim_talk_helper.h:64
BoolStatus team_msg_need_ack_
群消息是否需要已读业务,0:不需要,1:需要
Definition: nim_talk_helper.h:70
std::string force_push_content_
群组消息强推文本
Definition: nim_talk_helper.h:58
BoolStatus push_need_prefix_
需要推送昵称
Definition: nim_talk_helper.h:38
BoolStatus is_force_push_
群组消息强推开关,强推全员设置true并强推列表为空
Definition: nim_talk_helper.h:54
int anti_apam_using_yidun_
int, (可选) 单条消息是否使用易盾反垃圾 0:(在开通易盾的情况下)不过易盾反垃圾
Definition: nim_talk_helper.h:66
std::string yidun_anti_cheating_
(可选)String, 易盾反垃圾增强反作弊专属字段, 限制json,长度限制1024
Definition: nim_talk_helper.h:78
std::string push_content_
自定义推送文案,长度限制200字节
Definition: nim_talk_helper.h:48
BoolStatus anti_spam_enable_
是否需要过易盾反垃圾
Definition: nim_talk_helper.h:60
BoolStatus self_sync_
该消息是否支持发送者多端同步
Definition: nim_talk_helper.h:32
BoolStatus is_update_session_
(可选) 消息是否需要刷新到session服务,0:否,1:是;只有消息存离线的情况下,才会判断该参数,缺省:1
Definition: nim_talk_helper.h:76
BoolStatus routable_
是否要抄送
Definition: nim_talk_helper.h:40
BoolStatus push_need_badge_
是否要做消息计数
Definition: nim_talk_helper.h:36
BoolStatus roaming_
该消息是否支持漫游
Definition: nim_talk_helper.h:30
std::list< std::string > force_push_ids_list_
群组消息强推列表
Definition: nim_talk_helper.h:56
BoolStatus server_history_saved_
该消息是否存储云端历史
Definition: nim_talk_helper.h:28
std::string local_ext_
本地扩展字段, 格式不限,长度限制1024
Definition: nim_talk_helper.h:52
std::string anti_spam_content_
(可选)开发者自定义的反垃圾字段,长度限制5000
Definition: nim_talk_helper.h:62
BoolStatus need_offline_
是否支持离线消息
Definition: nim_talk_helper.h:44
BoolStatus need_push_
是否需要推送
Definition: nim_talk_helper.h:34
nim_cpp_wrapper_util::Json::Value server_ext_
第三方扩展字段, 长度限制1024
Definition: nim_talk_helper.h:50
std::string thread_msg_from_account_
thread消息的消息发送者
Definition: nim_talk_helper.h:268
uint64_t thread_msg_time_
thread消息的消息发送时间
Definition: nim_talk_helper.h:272
uint64_t thread_msg_id_server_
thread消息的消息ID(serverId)
Definition: nim_talk_helper.h:274
std::string thread_msg_id_client_
thread消息的消息ID(clientId)
Definition: nim_talk_helper.h:276
std::string reply_msg_from_account_
被回复消息的消息发送者
Definition: nim_talk_helper.h:257
std::string thread_msg_to_account_
thread消息的消息接受者,群的话是tid
Definition: nim_talk_helper.h:270
uint64_t reply_msg_time_
被回复消息的消息发送时间
Definition: nim_talk_helper.h:261
uint64_t reply_msg_id_server_
被回复消息的消息ID(serverId)
Definition: nim_talk_helper.h:263
std::string reply_msg_id_client_
被回复消息的消息ID(clientId)
Definition: nim_talk_helper.h:265
std::string reply_msg_to_account_
被回复消息的消息接受者,群的话是tid
Definition: nim_talk_helper.h:259
std::string topic_
Definition: nim_talk_helper.h:298
std::string function_
Definition: nim_talk_helper.h:296
std::string account_
Definition: nim_talk_helper.h:302
std::string custom_content_
Definition: nim_talk_helper.h:300
Definition: nim_talk_helper.h:305
NIMSessionType session_type_
会话类型
Definition: nim_talk_helper.h:314
NIMMessageFeature feature_
消息属性
Definition: nim_talk_helper.h:310
MessageSetting msg_setting_
消息属性设置
Definition: nim_talk_helper.h:330
int32_t sub_type_
消息的子类型,客户端定义,服务器透传
Definition: nim_talk_helper.h:334
std::string client_msg_id_
消息ID(客户端)
Definition: nim_talk_helper.h:328
std::string receiver_accid_
接收者ID
Definition: nim_talk_helper.h:316
NIMResCode rescode_
错误码
Definition: nim_talk_helper.h:308
NIMMsgLogStatus status_
消息状态(客户端)
Definition: nim_talk_helper.h:344
std::string local_talk_id_
会话ID(客户端)
Definition: nim_talk_helper.h:340
IMMessageThreadInfo thread_info_
Definition: nim_talk_helper.h:349
uint64_t readonly_server_id_
消息ID(服务器,只读)
Definition: nim_talk_helper.h:360
NIMMessageType type_
消息类型
Definition: nim_talk_helper.h:324
std::string attach_
消息附件 ,长度限制10000
Definition: nim_talk_helper.h:326
int64_t timetag_
消息时间戳(毫秒)
Definition: nim_talk_helper.h:320
std::string content_
消息内容,长度限制10000
Definition: nim_talk_helper.h:322
std::string third_party_callback_ext_
第三方回调回来的自定义扩展字段 v7.8添加
Definition: nim_talk_helper.h:332
IMMessageRobotInfo robot_info_
Definition: nim_talk_helper.h:350
std::string sender_accid_
发送者ID
Definition: nim_talk_helper.h:318
String toStyledString() const
Definition: json_value.cpp:1464