NIM 跨平台 C++ 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
String toStyledString() const
Definition: json_value.cpp:1464
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
static nstd::string superTeamConversationId(const nstd::string &superTeamId)
获取超级群会话ID
Definition: v2_nim_internal.hpp:275
static nstd::string p2pConversationId(const nstd::string &accountId)
获取点对点会话ID
Definition: v2_nim_internal.hpp:269
static nstd::string teamConversationId(const nstd::string &teamId)
获取群组会话ID
Definition: v2_nim_internal.hpp:272
static nstd::string parseConversationTargetId(const nstd::string &conversationId)
获取会话ID对应的目标ID
Definition: v2_nim_internal.hpp:281
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
@ BS_TRUE
true
Definition: nim_sdk_util.h:28
@ BS_FALSE
false
Definition: nim_sdk_util.h:26
Talk 辅助方法和数据结构定义
Definition: nim_talk_helper.h:339
NIMSessionType session_type_
会话类型
Definition: nim_talk_helper.h:345
NIMMessageFeature feature_
消息属性
Definition: nim_talk_helper.h:343
MessageSetting msg_setting_
消息属性设置
Definition: nim_talk_helper.h:361
int32_t sub_type_
消息的子类型,客户端定义,服务器透传
Definition: nim_talk_helper.h:365
std::string client_msg_id_
消息ID(客户端)
Definition: nim_talk_helper.h:359
std::string receiver_accid_
接收者ID
Definition: nim_talk_helper.h:347
NIMResCode rescode_
错误码
Definition: nim_talk_helper.h:341
NIMMsgLogStatus status_
消息状态(客户端)
Definition: nim_talk_helper.h:373
std::string local_talk_id_
会话ID(客户端)
Definition: nim_talk_helper.h:369
IMMessageThreadInfo thread_info_
thread 消息信息
Definition: nim_talk_helper.h:377
uint64_t readonly_server_id_
消息ID(服务器,只读)
Definition: nim_talk_helper.h:389
NIMMessageType type_
消息类型
Definition: nim_talk_helper.h:355
std::string attach_
消息附件 ,长度限制10000
Definition: nim_talk_helper.h:357
int64_t timetag_
消息时间戳(毫秒)
Definition: nim_talk_helper.h:351
std::string content_
消息内容,长度限制10000
Definition: nim_talk_helper.h:353
std::string third_party_callback_ext_
第三方回调回来的自定义扩展字段 v7.8添加
Definition: nim_talk_helper.h:363
IMMessageRobotInfo robot_info_
机器人消息信息
Definition: nim_talk_helper.h:379
std::string sender_accid_
发送者ID
Definition: nim_talk_helper.h:349
std::string topic_
Definition: nim_talk_helper.h:296
std::string function_
Definition: nim_talk_helper.h:294
std::string account_
Definition: nim_talk_helper.h:300
std::string custom_content_
Definition: nim_talk_helper.h:298
std::string thread_msg_from_account_
thread消息的消息发送者
Definition: nim_talk_helper.h:266
uint64_t thread_msg_time_
thread消息的消息发送时间
Definition: nim_talk_helper.h:270
uint64_t thread_msg_id_server_
thread消息的消息ID(serverId)
Definition: nim_talk_helper.h:272
std::string thread_msg_id_client_
thread消息的消息ID(clientId)
Definition: nim_talk_helper.h:274
std::string reply_msg_from_account_
被回复消息的消息发送者
Definition: nim_talk_helper.h:255
std::string thread_msg_to_account_
thread消息的消息接受者,群的话是tid
Definition: nim_talk_helper.h:268
uint64_t reply_msg_time_
被回复消息的消息发送时间
Definition: nim_talk_helper.h:259
uint64_t reply_msg_id_server_
被回复消息的消息ID(serverId)
Definition: nim_talk_helper.h:261
std::string reply_msg_id_client_
被回复消息的消息ID(clientId)
Definition: nim_talk_helper.h:263
std::string reply_msg_to_account_
被回复消息的消息接受者,群的话是tid
Definition: nim_talk_helper.h:257
nim_cpp_wrapper_util::Json::Value push_payload_
第三方自定义的推送属性,长度2048
Definition: nim_talk_helper.h:47
std::string anti_spam_ext
(可选)String, 易盾反垃圾扩展字段,限制 json,长度限制 1024
Definition: nim_talk_helper.h:83
std::string anti_apam_biz_id_
(可选)用户配置的对某些单条消息另外的反垃圾的业务ID
Definition: nim_talk_helper.h:65
BoolStatus team_msg_need_ack_
群消息是否需要已读业务,0:不需要,1:需要
Definition: nim_talk_helper.h:71
std::string force_push_content_
群组消息强推文本
Definition: nim_talk_helper.h:59
BoolStatus push_need_prefix_
需要推送昵称
Definition: nim_talk_helper.h:39
BoolStatus is_force_push_
群组消息强推开关,强推全员设置true并强推列表为空
Definition: nim_talk_helper.h:55
int anti_apam_using_yidun_
int, (可选) 单条消息是否使用易盾反垃圾 0:(在开通易盾的情况下)不过易盾反垃圾
Definition: nim_talk_helper.h:67
std::string yidun_anti_cheating_
(可选)String, 易盾反垃圾增强反作弊专属字段, 限制json,长度限制1024
Definition: nim_talk_helper.h:79
std::string push_content_
自定义推送文案,长度限制200字节
Definition: nim_talk_helper.h:49
BoolStatus anti_spam_enable_
是否需要过易盾反垃圾
Definition: nim_talk_helper.h:61
BoolStatus self_sync_
该消息是否支持发送者多端同步
Definition: nim_talk_helper.h:33
BoolStatus is_update_session_
(可选) 消息是否需要刷新到session服务,0:否,1:是;只有消息存离线的情况下,才会判断该参数,缺省:1
Definition: nim_talk_helper.h:77
BoolStatus routable_
是否要抄送
Definition: nim_talk_helper.h:41
BoolStatus push_need_badge_
是否要做消息计数
Definition: nim_talk_helper.h:37
BoolStatus roaming_
该消息是否支持漫游
Definition: nim_talk_helper.h:31
std::list< std::string > force_push_ids_list_
群组消息强推列表
Definition: nim_talk_helper.h:57
BoolStatus server_history_saved_
该消息是否存储云端历史
Definition: nim_talk_helper.h:29
std::string local_ext_
本地扩展字段, 格式不限,长度限制1024
Definition: nim_talk_helper.h:53
std::string anti_spam_content_
(可选)开发者自定义的反垃圾字段,长度限制5000
Definition: nim_talk_helper.h:63
BoolStatus need_offline_
是否支持离线消息
Definition: nim_talk_helper.h:45
BoolStatus need_push_
是否需要推送
Definition: nim_talk_helper.h:35
nim_cpp_wrapper_util::Json::Value server_ext_
第三方扩展字段, 长度限制1024
Definition: nim_talk_helper.h:51
nstd::optional< nstd::string > antispamExtension
易盾反垃圾(增强检测数据), json格式, 限制长度 1024 字节
Definition: v2_nim_def_struct.hpp:483
bool antispamEnabled
指定是否需要过安全通
Definition: v2_nim_def_struct.hpp:473
nstd::optional< nstd::string > antispamCustomMessage
Definition: v2_nim_def_struct.hpp:479
nstd::optional< nstd::string > antispamCheating
易盾反作弊(辅助检测数据), json格式, 限制长度 1024 字节
Definition: v2_nim_def_struct.hpp:481
nstd::optional< nstd::string > antispamBusinessId
指定易盾业务id, 而不使用云信后台配置的
Definition: v2_nim_def_struct.hpp:475
bool readReceiptEnabled
是否需要消息已读回执信息
Definition: v2_nim_def_struct.hpp:522
bool lastMessageUpdateEnabled
是否需要更新消息所属的会话信息
Definition: v2_nim_def_struct.hpp:524
bool historyEnabled
是否需要存历史消息
Definition: v2_nim_def_struct.hpp:526
bool onlineSyncEnabled
是否需要发送方多端在线同步消息
Definition: v2_nim_def_struct.hpp:530
bool unreadEnabled
是否需要计未读
Definition: v2_nim_def_struct.hpp:534
bool offlineEnabled
是否需要存离线消息
Definition: v2_nim_def_struct.hpp:532
bool roamingEnabled
是否需要存漫游消息
Definition: v2_nim_def_struct.hpp:528
Definition: v2_nim_def_struct.hpp:643
V2NIMMessagePushConfig pushConfig
推送相关配置
Definition: v2_nim_def_struct.hpp:683
nstd::optional< nstd::string > localExtension
本地扩展
Definition: v2_nim_def_struct.hpp:671
uint64_t createTime
消息时间
Definition: v2_nim_def_struct.hpp:649
nstd::string conversationId
消息所属会话 ID
Definition: v2_nim_def_struct.hpp:659
nstd::optional< V2NIMMessageRefer > threadReply
回复消息引用
Definition: v2_nim_def_struct.hpp:693
V2NIMMessageConfig messageConfig
消息相关配置
Definition: v2_nim_def_struct.hpp:681
nstd::string receiverId
消息接收者账号
Definition: v2_nim_def_struct.hpp:655
V2NIMConversationType conversationType
消息所属会话类型
Definition: v2_nim_def_struct.hpp:657
V2NIMMessageAntispamConfig antispamConfig
反垃圾相关配置
Definition: v2_nim_def_struct.hpp:687
nstd::optional< nstd::string > serverExtension
服务端扩展
Definition: v2_nim_def_struct.hpp:669
V2NIMMessageRouteConfig routeConfig
路由抄送相关配置
Definition: v2_nim_def_struct.hpp:685
nstd::string senderId
消息发送者账号
Definition: v2_nim_def_struct.hpp:651
nstd::optional< nstd::string > callbackExtension
回调扩展
Definition: v2_nim_def_struct.hpp:673
nstd::optional< V2NIMMessageRefer > threadRoot
Thread 消息引用
Definition: v2_nim_def_struct.hpp:691
uint32_t subType
消息内容
Definition: v2_nim_def_struct.hpp:663
nstd::shared_ptr< V2NIMMessageAttachment > attachment
消息附属附件
Definition: v2_nim_def_struct.hpp:667
nstd::string messageServerId
服务端消息 ID
Definition: v2_nim_def_struct.hpp:647
V2NIMMessageRobotConfig robotConfig
机器人相关配置
Definition: v2_nim_def_struct.hpp:689
nstd::optional< V2NIMMessageSendingState > sendingState
消息发送状态
Definition: v2_nim_def_struct.hpp:675
V2NIMMessageType messageType
消息类型
Definition: v2_nim_def_struct.hpp:661
nstd::string messageClientId
客户端消息 ID
Definition: v2_nim_def_struct.hpp:645
nstd::string text
消息文本
Definition: v2_nim_def_struct.hpp:665
bool pushNickEnabled
是否需要推送消息发送者昵称
Definition: v2_nim_def_struct.hpp:441
nstd::vector< nstd::string > forcePushAccountIds
强制推送目标账号列表
Definition: v2_nim_def_struct.hpp:451
bool forcePush
是否强制推送, 忽略用户提醒相关设置
Definition: v2_nim_def_struct.hpp:447
nstd::string pushPayload
推送数据
Definition: v2_nim_def_struct.hpp:445
nstd::string pushContent
推送文本
Definition: v2_nim_def_struct.hpp:443
bool pushEnabled
是否需要推送消息
Definition: v2_nim_def_struct.hpp:439
nstd::string forcePushContent
强制推送文案
Definition: v2_nim_def_struct.hpp:449
Definition: v2_nim_def_struct.hpp:544
nstd::optional< nstd::string > function
机器人具体功能, 用户可以自定义输入
Definition: v2_nim_def_struct.hpp:501
nstd::optional< nstd::string > customContent
机器人自定义内容
Definition: v2_nim_def_struct.hpp:503
nstd::optional< nstd::string > accountId
机器人账号, 仅群聊有效
Definition: v2_nim_def_struct.hpp:497
nstd::optional< nstd::string > topic
机器人消息话题
Definition: v2_nim_def_struct.hpp:499
bool routeEnabled
是否需要路由消息
Definition: v2_nim_def_struct.hpp:508