7 #ifndef _NIM_SDK_CPP_TALK_HELPER_H_
8 #define _NIM_SDK_CPP_TALK_HELPER_H_
15 #include "nim_define_include.h"
16 #include "nim_wrapper_util/nim_json_util.h"
58 : resend_flag_(BS_NOT_INIT)
59 , server_history_saved_(BS_NOT_INIT)
60 , roaming_(BS_NOT_INIT)
61 , self_sync_(BS_NOT_INIT)
62 , need_push_(BS_NOT_INIT)
63 , push_need_badge_(BS_NOT_INIT)
64 , push_need_prefix_(BS_NOT_INIT)
65 , routable_(BS_NOT_INIT)
66 , need_offline_(BS_NOT_INIT)
67 , is_force_push_(BS_NOT_INIT)
68 , anti_spam_enable_(BS_NOT_INIT)
69 , anti_apam_biz_id_(
"")
70 , anti_apam_using_yidun_(1)
71 , client_anti_spam_hitting_(BS_NOT_INIT)
72 , team_msg_need_ack_(BS_NOT_INIT)
73 , team_msg_ack_sent_(BS_NOT_INIT)
74 , team_msg_unread_count_(-1)
75 , is_update_session_(BS_NOT_INIT)
76 , yidun_anti_cheating_(
"")
84 void ToJsonValue(nim_cpp_wrapper_util::Json::Value& message)
const {
85 if (server_history_saved_ != BS_NOT_INIT)
86 message[kNIMMsgKeyHistorySave] = server_history_saved_;
87 if (roaming_ != BS_NOT_INIT)
88 message[kNIMMsgKeyMsgRoaming] = roaming_;
89 if (self_sync_ != BS_NOT_INIT)
90 message[kNIMMsgKeyMsgSync] = self_sync_;
91 if (push_need_badge_ != BS_NOT_INIT)
92 message[kNIMMsgKeyPushNeedBadge] = push_need_badge_;
93 if (need_push_ != BS_NOT_INIT)
94 message[kNIMMsgKeyPushEnable] = need_push_;
95 if (push_need_prefix_ != BS_NOT_INIT)
96 message[kNIMMsgKeyPushNeedPrefix] = push_need_prefix_;
97 if (resend_flag_ != BS_NOT_INIT)
98 message[kNIMMsgKeyResendFlag] = resend_flag_;
99 if (routable_ != BS_NOT_INIT)
100 message[kNIMMsgKeyMsgRoutable] = routable_;
101 if (need_offline_ != BS_NOT_INIT)
102 message[kNIMMsgKeySetMsgOffline] = need_offline_;
103 if (!push_payload_.empty())
104 message[kNIMMsgKeyPushPayload] = GetJsonStringWithNoStyled(push_payload_);
105 if (!push_content_.empty())
106 message[kNIMMsgKeyPushContent] = push_content_;
107 if (!server_ext_.empty())
108 message[kNIMMsgKeyServerExt] = GetJsonStringWithNoStyled(server_ext_);
109 if (!local_ext_.empty())
110 message[kNIMMsgKeyLocalExt] = local_ext_;
111 if (is_force_push_ != BS_NOT_INIT)
112 message[kNIMMsgKeyIsForcePush] = is_force_push_ == BS_TRUE ? 1 : 0;
113 if (!force_push_content_.empty())
114 message[kNIMMsgKeyForcePushContent] = force_push_content_;
115 if (!force_push_ids_list_.empty()) {
116 std::string ids_json;
117 StrListToJsonString(force_push_ids_list_, ids_json);
118 message[kNIMMsgKeyForcePushList] = ids_json;
120 if (anti_spam_enable_ != BS_NOT_INIT)
121 message[kNIMMsgKeyAntiSpamEnable] = anti_spam_enable_ == BS_TRUE ? 1 : 0;
122 if (!anti_spam_content_.empty())
123 message[kNIMMsgKeyAntiSpamContent] = anti_spam_content_;
124 if (!anti_apam_biz_id_.empty())
125 message[kNIMMsgKeyAntiSpamBizId] = anti_apam_biz_id_;
126 message[kNIMMsgKeyAntiSpamUsingYiDun] = anti_apam_using_yidun_;
127 if (client_anti_spam_hitting_ != BS_NOT_INIT)
128 message[kNIMMsgKeyClientAntiSpam] = client_anti_spam_hitting_;
129 if (team_msg_need_ack_ != BS_NOT_INIT)
130 message[kNIMMsgKeyTeamMsgAck] = team_msg_need_ack_;
131 if (team_msg_ack_sent_ != BS_NOT_INIT)
132 message[kNIMMsgKeyLocalKeyTeamMsgAckSent] = team_msg_ack_sent_;
133 if (team_msg_unread_count_ > -1)
134 message[kNIMMsgKeyLocalKeyTeamMsgUnreadCount] = team_msg_unread_count_;
135 if (is_update_session_ != BS_NOT_INIT)
136 message[kNIMMsgKeyIsUpdateSession] = is_update_session_;
137 if (!yidun_anti_cheating_.empty())
138 message[kNIMMsgKeyAntiCheatingYiDun] = yidun_anti_cheating_;
139 if (!anti_spam_ext.empty())
140 message[kNIMMsgKeyAntiSpamExt] = anti_spam_ext;
141 if (!anti_spam_res.empty())
142 message[kNIMMsgKeyAntiSpamRes] = anti_spam_res;
143 if (!env_config_.empty())
144 message[kNIMMsgKeyEnv] = env_config_;
153 if (message.isMember(kNIMMsgKeyHistorySave))
154 server_history_saved_ = message[kNIMMsgKeyHistorySave].asInt() == 1 ? BS_TRUE : BS_FALSE;
155 if (message.isMember(kNIMMsgKeyMsgRoaming))
156 roaming_ = message[kNIMMsgKeyMsgRoaming].asInt() == 1 ? BS_TRUE : BS_FALSE;
157 if (message.isMember(kNIMMsgKeyMsgSync))
158 self_sync_ = message[kNIMMsgKeyMsgSync].asInt() == 1 ? BS_TRUE : BS_FALSE;
159 if (message.isMember(kNIMMsgKeyPushNeedBadge))
160 push_need_badge_ = message[kNIMMsgKeyPushNeedBadge].asInt() == 1 ? BS_TRUE : BS_FALSE;
161 if (message.isMember(kNIMMsgKeyPushEnable))
162 need_push_ = message[kNIMMsgKeyPushEnable].asInt() == 1 ? BS_TRUE : BS_FALSE;
163 if (message.isMember(kNIMMsgKeyPushNeedPrefix))
164 push_need_prefix_ = message[kNIMMsgKeyPushNeedPrefix].asInt() == 1 ? BS_TRUE : BS_FALSE;
165 if (message.isMember(kNIMMsgKeyResendFlag))
166 resend_flag_ = message[kNIMMsgKeyResendFlag].asInt() == 1 ? BS_TRUE : BS_FALSE;
167 if (message.isMember(kNIMMsgKeyMsgRoutable))
168 routable_ = message[kNIMMsgKeyMsgRoutable].asInt() == 1 ? BS_TRUE : BS_FALSE;
169 if (message.isMember(kNIMMsgKeySetMsgOffline))
170 need_offline_ = message[kNIMMsgKeySetMsgOffline].asInt() == 1 ? BS_TRUE : BS_FALSE;
171 nim_cpp_wrapper_util::Json::Reader reader;
172 if (message.isMember(kNIMMsgKeyServerExt) && !message[kNIMMsgKeyServerExt].asString().empty())
173 if ((!reader.parse(message[kNIMMsgKeyServerExt].asString(), server_ext_) || !server_ext_.isObject())) {
175 if (message.isMember(kNIMMsgKeyPushPayload) && !message[kNIMMsgKeyPushPayload].asString().empty())
176 if (!reader.parse(message[kNIMMsgKeyPushPayload].asString(), push_payload_) || !push_payload_.isObject()) {
178 local_ext_ = message[kNIMMsgKeyLocalExt].asString();
179 push_content_ = message[kNIMMsgKeyPushContent].asString();
180 if (message.isMember(kNIMMsgKeyIsForcePush))
181 is_force_push_ = message[kNIMMsgKeyIsForcePush].asInt() == 1 ? BS_TRUE : BS_FALSE;
182 force_push_content_ = message[kNIMMsgKeyForcePushContent].asString();
183 if (message[kNIMMsgKeyForcePushList].isString()) {
184 nim_cpp_wrapper_util::Json::Value values;
185 if (reader.parse(message[kNIMMsgKeyForcePushList].asString(), values) && values.isArray())
186 JsonStrArrayToList(values, force_push_ids_list_);
191 if (message.isMember(kNIMMsgKeyAntiSpamEnable))
192 anti_spam_enable_ = message[kNIMMsgKeyAntiSpamEnable].asInt() == 1 ? BS_TRUE : BS_FALSE;
193 anti_spam_content_ = message[kNIMMsgKeyAntiSpamContent].asString();
194 if (message.isMember(kNIMMsgKeyClientAntiSpam))
195 client_anti_spam_hitting_ = message[kNIMMsgKeyClientAntiSpam].asInt() == 1 ? BS_TRUE : BS_FALSE;
196 if (message.isMember(kNIMMsgKeyTeamMsgAck))
197 team_msg_need_ack_ = message[kNIMMsgKeyTeamMsgAck].asInt() == 1 ? BS_TRUE : BS_FALSE;
198 if (message.isMember(kNIMMsgKeyLocalKeyTeamMsgAckSent))
199 team_msg_ack_sent_ = message[kNIMMsgKeyTeamMsgAck].asInt() == 1 ? BS_TRUE : BS_FALSE;
200 if (message.isMember(kNIMMsgKeyLocalKeyTeamMsgUnreadCount))
201 team_msg_unread_count_ = message[kNIMMsgKeyLocalKeyTeamMsgUnreadCount].asUInt();
202 if (message.isMember(kNIMMsgKeyIsUpdateSession))
203 is_update_session_ = message[kNIMMsgKeyIsUpdateSession].asBool() ? BS_TRUE : BS_FALSE;
204 if (message.isMember(kNIMMsgKeyAntiCheatingYiDun))
205 yidun_anti_cheating_ = message[kNIMMsgKeyAntiCheatingYiDun].asString();
206 if (message.isMember(kNIMMsgKeyAntiSpamExt))
207 anti_spam_ext = message[kNIMMsgKeyAntiSpamExt].asString();
208 if (message.isMember(kNIMMsgKeyAntiSpamRes))
209 anti_spam_res = message[kNIMMsgKeyAntiSpamRes].asString();
210 if (message.isMember(kNIMMsgKeyEnv))
211 env_config_ = message[kNIMMsgKeyEnv].asString();
217 std::string reply_msg_from_account_;
218 std::string reply_msg_to_account_;
219 uint64_t reply_msg_time_;
220 uint64_t reply_msg_id_server_;
221 std::string reply_msg_id_client_;
223 std::string thread_msg_from_account_;
224 std::string thread_msg_to_account_;
225 uint64_t thread_msg_time_;
226 uint64_t thread_msg_id_server_;
227 std::string thread_msg_id_client_;
230 : reply_msg_from_account_(
"")
231 , reply_msg_to_account_(
"")
233 , reply_msg_id_server_(0)
234 , reply_msg_id_client_(
"")
235 , thread_msg_from_account_(
"")
236 , thread_msg_to_account_(
"")
237 , thread_msg_time_(0)
238 , thread_msg_id_server_(0)
239 , thread_msg_id_client_(
"")
276 : rescode_((NIMResCode)0)
277 , feature_(kNIMMessageFeatureDefault)
278 , readonly_sender_client_type_(kNIMClientTypeDefault)
279 , readonly_server_id_(0)
280 , session_type_(kNIMSessionTypeP2P)
282 , type_(kNIMMessageTypeUnknown)
283 , status_(
nim::kNIMMsgLogStatusNone)
284 , sub_status_(
nim::kNIMMsgLogSubStatusNone) {}
288 : rescode_((NIMResCode)0)
289 , feature_(kNIMMessageFeatureDefault)
290 , readonly_sender_client_type_(kNIMClientTypeDefault)
291 , readonly_server_id_(0)
292 , session_type_(kNIMSessionTypeP2P)
294 , type_(kNIMMessageTypeUnknown)
295 , status_(
nim::kNIMMsgLogStatusNone)
296 , sub_status_(
nim::kNIMMsgLogSubStatusNone) {
297 nim_cpp_wrapper_util::Json::Value values;
298 nim_cpp_wrapper_util::Json::Reader reader;
299 if (reader.parse(json_msg, values) && values.isObject()) {
300 session_type_ = (NIMSessionType)values[kNIMMsgKeyToType].asUInt();
301 receiver_accid_ = values[kNIMMsgKeyToAccount].asString();
302 sender_accid_ = values[kNIMMsgKeyFromAccount].asString();
303 readonly_sender_client_type_ = (NIMClientType)values[kNIMMsgKeyFromClientType].asUInt();
304 readonly_sender_device_id_ = values[kNIMMsgKeyFromDeviceId].asString();
305 readonly_sender_nickname_ = values[kNIMMsgKeyFromNick].asString();
306 timetag_ = values[kNIMMsgKeyTime].asUInt64();
308 type_ = (NIMMessageType)values[kNIMMsgKeyType].asUInt();
309 content_ = values[kNIMMsgKeyBody].asString();
310 attach_ = values[kNIMMsgKeyAttach].asString();
311 client_msg_id_ = values[kNIMMsgKeyClientMsgid].asString();
312 readonly_server_id_ = values[kNIMMsgKeyServerMsgid].asUInt64();
314 local_res_path_ = values[kNIMMsgKeyLocalFilePath].asString();
315 local_talk_id_ = values[kNIMMsgKeyLocalTalkId].asString();
316 local_res_id_ = values[kNIMMsgKeyLocalResId].asString();
317 status_ = (NIMMsgLogStatus)values[kNIMMsgKeyLocalLogStatus].asUInt();
318 sub_status_ = (NIMMsgLogSubStatus)values[kNIMMsgKeyLocalLogSubStatus].asUInt();
323 third_party_callback_ext_ = values[kNIMMsgKeyThirdPartyCBEXT].asString();
324 sub_type_ = values[kNIMMsgKeySubType].asInt();
333 nim_cpp_wrapper_util::Json::Value
ToJsonObject(
bool use_to_send)
const {
334 nim_cpp_wrapper_util::Json::Value values;
335 values[kNIMMsgKeyToType] = session_type_;
336 values[kNIMMsgKeyToAccount] = receiver_accid_;
337 values[kNIMMsgKeyFromAccount] = sender_accid_;
338 values[kNIMMsgKeyTime] = timetag_;
339 values[kNIMMsgKeyType] = type_;
340 values[kNIMMsgKeyBody] = content_;
341 values[kNIMMsgKeyAttach] = attach_;
342 values[kNIMMsgKeyClientMsgid] = client_msg_id_;
343 values[kNIMMsgKeyLocalFilePath] = local_res_path_;
344 values[kNIMMsgKeyLocalTalkId] = local_talk_id_;
345 values[kNIMMsgKeyLocalResId] = local_res_id_;
346 values[kNIMMsgKeyLocalLogStatus] = status_;
347 values[kNIMMsgKeyLocalLogSubStatus] = sub_status_;
348 values[kNIMMsgKeySubType] = sub_type_;
352 values[kNIMMsgKeyFromClientType] = readonly_sender_client_type_;
353 values[kNIMMsgKeyFromDeviceId] = readonly_sender_device_id_;
354 values[kNIMMsgKeyFromNick] = readonly_sender_nickname_;
355 values[kNIMMsgKeyServerMsgid] = readonly_server_id_;
356 values[kNIMMsgKeyThirdPartyCBEXT] = third_party_callback_ext_;
360 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyReplyMsgFromAccount] = thread_info_.reply_msg_from_account_;
361 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyReplyMsgToAccount] = thread_info_.reply_msg_to_account_;
362 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyReplyMsgTime] = thread_info_.reply_msg_time_;
363 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyReplyMsgIdServer] = thread_info_.reply_msg_id_server_;
364 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyReplyMsgIdClient] = thread_info_.reply_msg_id_client_;
366 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyThreadMsgFromAccount] = thread_info_.thread_msg_from_account_;
367 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyThreadMsgToAccount] = thread_info_.thread_msg_to_account_;
368 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyThreadMsgTime] = thread_info_.thread_msg_time_;
369 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyThreadMsgIdServer] = thread_info_.thread_msg_id_server_;
370 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyThreadMsgIdClient] = thread_info_.thread_msg_id_client_;
372 values[kNIMMsgKeyThreadInfo][kNIMMsgKeyDeleted] = thread_info_.deleted_;
382 nim_cpp_wrapper_util::Json::Value values = ToJsonObject(use_to_send);
383 return GetJsonStringWithNoStyled(values);
388 struct NIM_SDK_CPPWRAPPER_DLL_API
IMFile {
399 , msg_attachment_tag_(kNIMNosDefaultTagIM) {}
406 std::string
ToJsonString(nim_cpp_wrapper_util::Json::Value& attach)
const {
408 if (!display_name_.empty())
409 attach[kNIMFileMsgKeyDisplayName] = display_name_;
410 if (!file_extension_.empty())
411 attach[kNIMFileMsgKeyExt] = file_extension_;
413 attach[kNIMFileMsgKeyMd5] = md5_;
415 attach[kNIMFileMsgKeySize] = size_;
417 attach[kNIMMsgAttachKeyUrl] = url_;
418 if (!msg_attachment_tag_.empty())
419 attach[kNIMMsgAttachKeyTag] = msg_attachment_tag_;
420 return GetJsonStringWithNoStyled(attach);
428 nim_cpp_wrapper_util::Json::Value attach;
429 attach[kNIMFileMsgKeyDisplayName] = display_name_;
430 return ToJsonString(attach);
449 nim_cpp_wrapper_util::Json::Value attach;
450 attach[kNIMImgMsgKeyWidth] = width_;
451 attach[kNIMImgMsgKeyHeight] = height_;
473 nim_cpp_wrapper_util::Json::Value attach;
474 attach[kNIMLocationMsgKeyTitle] = description_;
475 attach[kNIMLocationMsgKeyLatitude] = latitude_;
476 attach[kNIMLocationMsgKeyLongitude] = longitude_;
478 return GetJsonStringWithNoStyled(attach);
495 nim_cpp_wrapper_util::Json::Value attach;
496 attach[kNIMAudioMsgKeyDuration] = duration_;
519 nim_cpp_wrapper_util::Json::Value attach;
520 attach[kNIMVideoMsgKeyWidth] = width_;
521 attach[kNIMVideoMsgKeyHeight] = height_;
522 attach[kNIMVideoMsgKeyDuration] = duration_;
547 nim_cpp_wrapper_util::Json::Value attach;
548 attach[kNIMBotRobotMsgKeyRobotID] = robot_accid_;
549 attach[kNIMBotRobotSentMsgKeyParam] = sent_param_;
551 return GetJsonStringWithNoStyled(attach);
559 std::string from_id_;
592 NIM_SDK_CPPWRAPPER_DLL_API
void ParseMessage(
const nim_cpp_wrapper_util::Json::Value& msg_json,
IMMessage& message);
596 #endif //_NIM_SDK_CPP_TALK_HELPER_H_