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.feature_ = nim::kNIMMessageFeatureLeaveMsg;
37 } else if (message.messageSource == V2NIM_MESSAGE_SOURCE_ROAMING) {
38 v1Message.feature_ = nim::kNIMMessageFeatureRoamMsg;
39 }
41 v1Message.session_type_ = nim::kNIMSessionTypeP2P;
42 } else if (message.conversationType == V2NIM_CONVERSATION_TYPE_TEAM) {
43 v1Message.session_type_ = nim::kNIMSessionTypeTeam;
45 v1Message.session_type_ = nim::kNIMSessionTypeSuperTeam;
46 }
47 v1Message.receiver_accid_ = message.receiverId;
48 v1Message.sender_accid_ = message.senderId;
49 v1Message.timetag_ = static_cast<int64_t>(message.createTime);
50 v1Message.content_ = message.text;
51 v1Message.type_ = static_cast<nim::NIMMessageType>(message.messageType);
52 if (message.attachment) {
53 v1Message.attach_ = message.attachment->raw;
54 }
55 v1Message.client_msg_id_ = message.messageClientId;
66 v1Message.msg_setting_.server_ext_ = message.serverExtension ? message.serverExtension->c_str() : "";
67 v1Message.msg_setting_.local_ext_ = message.localExtension ? *message.localExtension : "";
69 for (auto&& forcePushAccountId : message.pushConfig.forcePushAccountIds) {
70 v1Message.msg_setting_.force_push_ids_list_.push_back(forcePushAccountId);
71 }
81
82 v1Message.third_party_callback_ext_ = message.callbackExtension ? *message.callbackExtension : "";
83 v1Message.sub_type_ = static_cast<int32_t>(message.subType);
85 if (message.sendingState) {
87 v1Message.status_ = nim::kNIMMsgLogStatusSendFailed;
89 v1Message.status_ = nim::kNIMMsgLogStatusSending;
90 }
91 }
92 if (message.threadReply) {
93 v1Message.thread_info_.reply_msg_from_account_ = message.threadReply->senderId;
94 v1Message.thread_info_.reply_msg_to_account_ = message.threadReply->receiverId;
95 v1Message.thread_info_.reply_msg_time_ = message.threadReply->createTime;
96 v1Message.thread_info_.reply_msg_id_server_ = std::stoull(message.threadReply->messageServerId);
97 v1Message.thread_info_.reply_msg_id_client_ = message.threadReply->messageClientId;
98 }
99 if (message.threadRoot) {
100 v1Message.thread_info_.thread_msg_from_account_ = message.threadRoot->senderId;
101 v1Message.thread_info_.thread_msg_to_account_ = message.threadRoot->receiverId;
102 v1Message.thread_info_.thread_msg_time_ = message.threadRoot->createTime;
103 v1Message.thread_info_.thread_msg_id_server_ = std::stoull(message.threadRoot->messageServerId);
104 v1Message.thread_info_.thread_msg_id_client_ = message.threadRoot->messageClientId;
105 }
106 v1Message.robot_info_.account_ = message.robotConfig.accountId ? *message.robotConfig.accountId : "";
107 v1Message.robot_info_.function_ = message.robotConfig.function ? *message.robotConfig.function : "";
108 v1Message.robot_info_.topic_ = message.robotConfig.topic ? *message.robotConfig.topic : "";
110 v1Message.readonly_server_id_ = std::stoull(message.messageServerId);
111 return v1Message;
112}
114 V2NIMMessage v2Message;
116 if (message.session_type_ == nim::kNIMSessionTypeP2P) {
119 } else if (message.session_type_ == nim::kNIMSessionTypeTeam) {
122 } else if (message.session_type_ == nim::kNIMSessionTypeSuperTeam) {
125 }
126 v2Message.receiverId = message.receiver_accid_;
127 v2Message.senderId = message.sender_accid_;
128 v2Message.createTime = static_cast<uint64_t>(message.timetag_);
129 v2Message.text = message.content_;
130 v2Message.messageType = static_cast<V2NIMMessageType>(message.type_);
131 v2Message.attachment = nstd::make_shared<V2NIMMessageAttachment>();
132 v2Message.attachment->raw = message.attach_;
133 v2Message.messageClientId = message.client_msg_id_;
145 v2Message.localExtension = message.msg_setting_.local_ext_;
147 for (auto&& forcePushAccountId : message.msg_setting_.force_push_ids_list_) {
148 v2Message.pushConfig.forcePushAccountIds.push_back(forcePushAccountId);
149 }
160 v2Message.subType = message.sub_type_;
161 if (message.status_ == nim::kNIMMsgLogStatusSendFailed) {
163 } else if (message.status_ == nim::kNIMMsgLogStatusSending) {
165 }
166 if (!message.thread_info_.reply_msg_from_account_.empty()) {
167 v2Message.threadReply = V2NIMMessageRefer();
168 v2Message.threadReply->senderId = message.thread_info_.reply_msg_from_account_;
169 v2Message.threadReply->receiverId = message.thread_info_.reply_msg_to_account_;
170 v2Message.threadReply->createTime = message.thread_info_.reply_msg_time_;
171 v2Message.threadReply->messageServerId = std::to_string(message.thread_info_.reply_msg_id_server_);
172 v2Message.threadReply->messageClientId = message.thread_info_.reply_msg_id_client_;
173 }
174 if (!message.thread_info_.thread_msg_from_account_.empty()) {
175 v2Message.threadRoot = V2NIMMessageRefer();
176 v2Message.threadRoot->senderId = message.thread_info_.thread_msg_from_account_;
177 v2Message.threadRoot->receiverId = message.thread_info_.thread_msg_to_account_;
178 v2Message.threadRoot->createTime = message.thread_info_.thread_msg_time_;
179 v2Message.threadRoot->messageServerId = std::to_string(message.thread_info_.thread_msg_id_server_);
180 v2Message.threadRoot->messageClientId = message.thread_info_.thread_msg_id_client_;
181 }
182 v2Message.robotConfig.accountId = message.robot_info_.account_;
183 v2Message.robotConfig.function = message.robot_info_.function_;
184 v2Message.robotConfig.topic = message.robot_info_.topic_;
186 v2Message.messageServerId = std::to_string(message.readonly_server_id_);
187
189 if (message.feature_ == nim::kNIMMessageFeatureLeaveMsg) {
191 } else if (message.feature_ == nim::kNIMMessageFeatureRoamMsg) {
193 }
194 return v2Message;
195}
196// NOLINTEND
197} // namespace v2
198#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:113
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:276
static nstd::string p2pConversationId(const nstd::string &accountId)
获取点对点会话ID
Definition: v2_nim_internal.hpp:270
static nstd::string teamConversationId(const nstd::string &teamId)
获取群组会话ID
Definition: v2_nim_internal.hpp:273
static nstd::string parseConversationTargetId(const nstd::string &conversationId)
获取会话ID对应的目标ID
Definition: v2_nim_internal.hpp:282
Definition: v2_nim_ai_service.hpp:4
@ V2NIM_MESSAGE_SOURCE_ROAMING
漫游消息
Definition: v2_nim_def_enum.hpp:987
@ V2NIM_MESSAGE_SOURCE_OFFLINE
离线消息
Definition: v2_nim_def_enum.hpp:985
@ V2NIM_MESSAGE_SOURCE_ONLINE
在线消息
Definition: v2_nim_def_enum.hpp:983
V2NIMMessageType
Definition: v2_nim_def_enum.hpp:943
@ V2NIM_CONVERSATION_TYPE_P2P
单聊
Definition: v2_nim_def_enum.hpp:936
@ V2NIM_CONVERSATION_TYPE_UNKNOWN
未知
Definition: v2_nim_def_enum.hpp:934
@ V2NIM_CONVERSATION_TYPE_SUPER_TEAM
超大群
Definition: v2_nim_def_enum.hpp:940
@ V2NIM_CONVERSATION_TYPE_TEAM
群聊
Definition: v2_nim_def_enum.hpp:938
@ V2NIM_MESSAGE_SENDING_STATE_SENDING
发送中
Definition: v2_nim_def_enum.hpp:976
@ V2NIM_MESSAGE_SENDING_STATE_FAILED
发送失败
Definition: v2_nim_def_enum.hpp:974
@ BS_TRUE
true
Definition: nim_sdk_util.h:28
@ BS_FALSE
false
Definition: nim_sdk_util.h:26
Talk 辅助方法和数据结构定义
Definition: nim_talk_helper.h:440
NIMSessionType session_type_
会话类型
Definition: nim_talk_helper.h:446
NIMMessageFeature feature_
消息属性
Definition: nim_talk_helper.h:444
MessageSetting msg_setting_
消息属性设置
Definition: nim_talk_helper.h:466
int32_t sub_type_
消息的子类型,客户端定义,服务器透传
Definition: nim_talk_helper.h:470
std::string client_msg_id_
消息ID(客户端)
Definition: nim_talk_helper.h:464
std::string receiver_accid_
接收者ID
Definition: nim_talk_helper.h:448
NIMResCode rescode_
错误码
Definition: nim_talk_helper.h:442
NIMMsgLogStatus status_
消息状态(客户端)
Definition: nim_talk_helper.h:478
std::string local_talk_id_
会话ID(客户端)
Definition: nim_talk_helper.h:474
IMMessageThreadInfo thread_info_
thread 消息信息
Definition: nim_talk_helper.h:482
uint64_t readonly_server_id_
消息ID(服务器,只读)
Definition: nim_talk_helper.h:496
NIMMessageType type_
消息类型
Definition: nim_talk_helper.h:460
std::string attach_
消息附件 ,长度限制10000
Definition: nim_talk_helper.h:462
int64_t timetag_
消息时间戳(毫秒)
Definition: nim_talk_helper.h:452
std::string content_
消息内容,长度限制10000
Definition: nim_talk_helper.h:458
std::string third_party_callback_ext_
第三方回调回来的自定义扩展字段 v7.8添加
Definition: nim_talk_helper.h:468
IMMessageRobotInfo robot_info_
机器人消息信息
Definition: nim_talk_helper.h:484
std::string sender_accid_
发送者ID
Definition: nim_talk_helper.h:450
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:519
bool antispamEnabled
指定是否需要过安全通
Definition: v2_nim_def_struct.hpp:509
nstd::optional< nstd::string > antispamCustomMessage
Definition: v2_nim_def_struct.hpp:515
nstd::optional< nstd::string > antispamCheating
易盾反作弊(辅助检测数据), json格式, 限制长度 1024 字节
Definition: v2_nim_def_struct.hpp:517
nstd::optional< nstd::string > antispamBusinessId
指定易盾业务id, 而不使用云信后台配置的
Definition: v2_nim_def_struct.hpp:511
bool readReceiptEnabled
是否需要消息已读回执信息
Definition: v2_nim_def_struct.hpp:558
bool lastMessageUpdateEnabled
是否需要更新消息所属的会话信息
Definition: v2_nim_def_struct.hpp:560
bool historyEnabled
是否需要存历史消息
Definition: v2_nim_def_struct.hpp:562
bool onlineSyncEnabled
是否需要发送方多端在线同步消息
Definition: v2_nim_def_struct.hpp:566
bool unreadEnabled
是否需要计未读
Definition: v2_nim_def_struct.hpp:570
bool offlineEnabled
是否需要存离线消息
Definition: v2_nim_def_struct.hpp:568
bool roamingEnabled
是否需要存漫游消息
Definition: v2_nim_def_struct.hpp:564
Definition: v2_nim_def_struct.hpp:744
V2NIMMessagePushConfig pushConfig
推送相关配置
Definition: v2_nim_def_struct.hpp:786
nstd::optional< nstd::string > localExtension
本地扩展
Definition: v2_nim_def_struct.hpp:774
uint64_t createTime
消息时间
Definition: v2_nim_def_struct.hpp:750
nstd::string conversationId
消息所属会话 ID
Definition: v2_nim_def_struct.hpp:760
nstd::optional< V2NIMMessageRefer > threadReply
回复消息引用
Definition: v2_nim_def_struct.hpp:796
V2NIMMessageConfig messageConfig
消息相关配置
Definition: v2_nim_def_struct.hpp:784
nstd::string receiverId
消息接收者账号
Definition: v2_nim_def_struct.hpp:756
V2NIMConversationType conversationType
消息所属会话类型
Definition: v2_nim_def_struct.hpp:758
V2NIMMessageAntispamConfig antispamConfig
反垃圾相关配置
Definition: v2_nim_def_struct.hpp:790
nstd::optional< nstd::string > serverExtension
服务端扩展
Definition: v2_nim_def_struct.hpp:772
V2NIMMessageRouteConfig routeConfig
路由抄送相关配置
Definition: v2_nim_def_struct.hpp:788
nstd::string senderId
消息发送者账号
Definition: v2_nim_def_struct.hpp:752
nstd::optional< nstd::string > callbackExtension
回调扩展
Definition: v2_nim_def_struct.hpp:776
nstd::optional< V2NIMMessageRefer > threadRoot
Thread 消息引用
Definition: v2_nim_def_struct.hpp:794
uint32_t subType
消息子类型
Definition: v2_nim_def_struct.hpp:764
nstd::shared_ptr< V2NIMMessageAttachment > attachment
消息附属附件
Definition: v2_nim_def_struct.hpp:770
nstd::string messageServerId
服务端消息 ID
Definition: v2_nim_def_struct.hpp:748
V2NIMMessageRobotConfig robotConfig
机器人相关配置
Definition: v2_nim_def_struct.hpp:792
nstd::optional< V2NIMMessageSendingState > sendingState
消息发送状态
Definition: v2_nim_def_struct.hpp:778
V2NIMMessageType messageType
消息类型
Definition: v2_nim_def_struct.hpp:762
nstd::string messageClientId
客户端消息 ID
Definition: v2_nim_def_struct.hpp:746
V2NIMMessageSource messageSource
消息来源
Definition: v2_nim_def_struct.hpp:810
nstd::string text
消息文本
Definition: v2_nim_def_struct.hpp:768
bool pushNickEnabled
是否需要推送消息发送者昵称
Definition: v2_nim_def_struct.hpp:477
nstd::vector< nstd::string > forcePushAccountIds
强制推送目标账号列表
Definition: v2_nim_def_struct.hpp:487
bool forcePush
是否强制推送, 忽略用户提醒相关设置
Definition: v2_nim_def_struct.hpp:483
nstd::string pushPayload
推送数据
Definition: v2_nim_def_struct.hpp:481
nstd::string pushContent
推送文本
Definition: v2_nim_def_struct.hpp:479
bool pushEnabled
是否需要推送消息
Definition: v2_nim_def_struct.hpp:475
nstd::string forcePushContent
强制推送文案
Definition: v2_nim_def_struct.hpp:485
Definition: v2_nim_def_struct.hpp:582
nstd::optional< nstd::string > function
机器人具体功能, 用户可以自定义输入
Definition: v2_nim_def_struct.hpp:537
nstd::optional< nstd::string > customContent
机器人自定义内容
Definition: v2_nim_def_struct.hpp:539
nstd::optional< nstd::string > accountId
机器人账号, 仅群聊有效
Definition: v2_nim_def_struct.hpp:533
nstd::optional< nstd::string > topic
机器人消息话题
Definition: v2_nim_def_struct.hpp:535
bool routeEnabled
是否需要路由消息
Definition: v2_nim_def_struct.hpp:544