1package com.netease.nimlib.sdk.v2.message;
3import android.text.TextUtils;
4import com.netease.nimlib.SDKCacheUI;
5import com.netease.nimlib.biz.constant.ITalkService;
6import com.netease.nimlib.biz.constant.ITalkService.TagString;
7import com.netease.nimlib.log.NimLog;
8import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
9import com.netease.nimlib.sdk.v2.conversation.enums.V2NIMConversationType;
10import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageAIConfig;
11import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageAntispamConfig;
12import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageAntispamConfig.V2NIMMessageAntispamConfigBuilder;
13import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageConfig;
14import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageConfig.V2NIMMessageConfigBuilder;
15import com.netease.nimlib.sdk.v2.message.config.V2NIMMessagePushConfig;
16import com.netease.nimlib.sdk.v2.message.config.V2NIMMessagePushConfig.V2NIMMessagePushConfigBuilder;
17import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageRobotConfig;
18import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageRobotConfig.V2NIMMessageRobotConfigBuilder;
19import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageRouteConfig;
20import com.netease.nimlib.sdk.v2.message.config.V2NIMMessageRouteConfig.V2NIMMessageRouteConfigBuilder;
21import com.netease.nimlib.sdk.v2.message.enums.V2NIMMessageAIStatus;
22import com.netease.nimlib.sdk.v2.message.enums.V2NIMMessageType;
23import com.netease.nimlib.session.MsgHelper;
24import com.netease.nimlib.session.TimeConsumingStatisticsImpl;
25import com.netease.nimlib.v2.message.compat.V2MessageModelConverter;
26import com.netease.nimlib.v2.message.impl.V2NIMMessageImpl;
27import com.netease.nimlib.v2.message.impl.V2NIMMessageReferImpl;
29import org.json.JSONException;
30import org.json.JSONObject;
34 private static final String TAG =
"V2NIMMessageConverter";
44 V2NIMMessageImpl messageImpl = (V2NIMMessageImpl) message;
45 JSONObject msgBody =
new JSONObject();
47 msgBody.put(ITalkService.TagString.ReceiverType, messageImpl.getConversationTypeV1().getValue());
48 msgBody.put(ITalkService.TagString.ReceiverAccount, messageImpl.getReceiverId());
49 msgBody.put(ITalkService.TagString.fromAccount, messageImpl.getSenderId());
50 msgBody.put(ITalkService.TagString.clientType, messageImpl.getFromClientType());
51 msgBody.put(ITalkService.TagString.fromNick, messageImpl.getFromNick());
52 msgBody.put(ITalkService.TagString.time, messageImpl.getCreateTime());
53 if (messageImpl.getMessageType() !=
null) {
54 msgBody.put(ITalkService.TagString.type, messageImpl.getMessageType().getValue());
57 msgBody.put(ITalkService.TagString.body, messageImpl.getText());
59 String attach = messageImpl.getAttachmentText();
60 if (!TextUtils.isEmpty(attach)) {
61 msgBody.put(ITalkService.TagString.attach, attach);
64 msgBody.put(ITalkService.TagString.msgid_client, messageImpl.getMessageClientId());
65 msgBody.put(ITalkService.TagString.msgid_server, messageImpl.getMessageServerIdValue());
67 msgBody.put(ITalkService.TagString.ext, messageImpl.getServerExtension());
70 if(pushConfig !=
null){
71 msgBody.put(ITalkService.TagString.pushEnable, pushConfig.
isPushEnabled() ? 1 : 0);
72 msgBody.put(ITalkService.TagString.pushPayload, pushConfig.
getPushPayload());
73 msgBody.put(ITalkService.TagString.pushContent, pushConfig.
getPushContent());
74 msgBody.put(ITalkService.TagString.needPushNick, pushConfig.
isPushNickEnabled() ? 1 : 0);
77 if (forcePushAccountIds !=
null) {
78 String pushListStr = MsgHelper.getJsonStringFromList(forcePushAccountIds);
79 msgBody.put(ITalkService.TagString.forcePushList, pushListStr);
82 msgBody.put(ITalkService.TagString.isForcePush, pushConfig.
isForcePush() ? 1 : 0);
87 if (antispamConfig !=
null) {
89 msgBody.put(ITalkService.TagString.antiSpamContentCustom, 1);
92 msgBody.put(ITalkService.TagString.antiSpamContentCustom, 0);
96 msgBody.put(ITalkService.TagString.antiSpamUsingYidun, antispamConfig.
isAntispamEnabled() ? 1 : 0);
97 msgBody.put(ITalkService.TagString.yidunAntiCheating, antispamConfig.
getAntispamCheating());
102 if(messageConfig !=
null){
104 msgBody.put(ITalkService.TagString.msgAck, 1);
107 msgBody.put(ITalkService.TagString.historyEnable, messageConfig.
isHistoryEnabled() ? 1 : 0);
108 msgBody.put(ITalkService.TagString.roamingEnable, messageConfig.
isRoamingEnabled() ? 1 : 0);
109 msgBody.put(ITalkService.TagString.selfSyncEnable, messageConfig.
isOnlineSyncEnabled() ? 1 : 0);
110 msgBody.put(ITalkService.TagString.persistEnable, messageConfig.
isOfflineEnabled() ? 1 : 0);
111 msgBody.put(ITalkService.TagString.needBadge, messageConfig.
isUnreadEnabled() ? 1 : 0);
115 V2NIMMessageReferImpl threadReply = (V2NIMMessageReferImpl) messageImpl.getThreadReply();
116 if(threadReply !=
null) {
117 msgBody.put(ITalkService.TagString.replyMsgFromAccount, threadReply.getSenderId());
118 msgBody.put(ITalkService.TagString.replyMsgToAccount, threadReply.getReceiverId());
119 msgBody.put(ITalkService.TagString.replyMsgTime, threadReply.getCreateTime());
120 msgBody.put(ITalkService.TagString.replyMsgIdServer, threadReply.getMessageServerIdValue());
121 msgBody.put(ITalkService.TagString.replyMsgIdClient, threadReply.getMessageClientId());
124 V2NIMMessageReferImpl threadRoot = (V2NIMMessageReferImpl) messageImpl.getThreadRoot();
125 if (threadRoot !=
null) {
126 msgBody.put(ITalkService.TagString.threadMsgFromAccount, threadRoot.getSenderId());
127 msgBody.put(ITalkService.TagString.threadMsgToAccount, threadRoot.getReceiverId());
128 msgBody.put(ITalkService.TagString.threadMsgTime, threadRoot.getCreateTime());
129 msgBody.put(ITalkService.TagString.threadMsgIdServer, threadRoot.getMessageServerIdValue());
130 msgBody.put(ITalkService.TagString.threadMsgIdClient, threadRoot.getMessageClientId());
133 msgBody.put(ITalkService.TagString.delete, messageImpl.isDeleted() ? 1 : 0);
134 msgBody.put(ITalkService.TagString.callbackExt, messageImpl.getCallbackExtension());
135 msgBody.put(ITalkService.TagString.subtype, messageImpl.getSubType());
137 TimeConsumingStatisticsImpl timeConsumingStatistics = messageImpl.getTimeConsumingStatistics();
138 if (timeConsumingStatistics !=
null) {
139 JSONObject jsonObject = timeConsumingStatistics.toJsonForClientExt();
140 msgBody.put(ITalkService.TagString.clientExt, jsonObject.toString());
144 if (robotConfig !=
null) {
145 msgBody.put(ITalkService.TagString.function, robotConfig.
getFunction());
146 msgBody.put(ITalkService.TagString.topic, robotConfig.
getTopic());
147 msgBody.put(ITalkService.TagString.customContent, robotConfig.
getCustomContent());
148 msgBody.put(ITalkService.TagString.account, robotConfig.
getAccountId());
152 if (routeConfig !=
null) {
153 msgBody.put(ITalkService.TagString.routeEnable, routeConfig.
isRouteEnabled() ? 1 : 0);
157 msgBody.put(ITalkService.TagString.isBlackListed, messageImpl.isInBlackList() ? 1 : 0);
160 if (aiConfig !=
null) {
161 msgBody.put(ITalkService.TagString.ai_agent_account, aiConfig.
getAccountId());
163 if(aiStatus !=
null){
164 msgBody.put(TagString.ai_agent_msg_direction, aiStatus.
getValue());
168 if(messageImpl.getAIErrorCode() > 0){
169 msgBody.put(ITalkService.TagString.ai_agent_error_code, messageImpl.getAIErrorCode());
172 long modifyTime = messageImpl.getModifyTime();
174 msgBody.put(ITalkService.TagString.modifyTimetag, modifyTime);
177 String modifyAccountId = messageImpl.getModifyAccountId();
178 if(!TextUtils.isEmpty(modifyAccountId)){
179 msgBody.put(ITalkService.TagString.modifyAccid, modifyAccountId);
183 catch (JSONException e) {
184 NimLog.e(TAG,
"messageSerialization JSONException: " + e.getMessage());
187 return msgBody.toString();
196 if(TextUtils.isEmpty(msg)){
201 msgBody =
new JSONObject(msg);
203 catch (Throwable e) {
204 NimLog.e(TAG,
"messageDeserialization exception, msg format error, msg = " + msg,e);
208 V2NIMMessageImpl message =
new V2NIMMessageImpl();
209 int sessionType = -1;
212 if(msgBody.has(ITalkService.TagString.ReceiverType)){
213 sessionType = msgBody.getInt(ITalkService.TagString.ReceiverType);
215 message.setConversationType(conversationType);
218 catch (Throwable e) {
219 NimLog.e(TAG,
"messageDeserialization exception, conversationType error, conversationType = " + msgBody.opt(ITalkService.TagString.ReceiverType),e);
223 String receiver =
null;
225 if(msgBody.has(ITalkService.TagString.ReceiverAccount)){
226 receiver = msgBody.getString(ITalkService.TagString.ReceiverAccount);
227 message.setReceiverId(receiver);
230 catch (Throwable e) {
231 NimLog.e(TAG,
"messageDeserialization exception, receiverId error, receiverId = " + msgBody.opt(ITalkService.TagString.ReceiverAccount),e);
235 String fromId =
null;
237 if(msgBody.has(ITalkService.TagString.fromAccount)){
238 fromId = msgBody.getString(ITalkService.TagString.fromAccount);
239 message.setSenderId(fromId);
242 catch (Throwable e) {
243 NimLog.e(TAG,
"messageDeserialization exception, senderId error,senderId = " + msgBody.opt(ITalkService.TagString.fromAccount),e);
247 String sessionId = sessionIdOfMsg(sessionType,fromId,receiver, SDKCacheUI.getAccount());
248 message.setSessionId(sessionId);
251 if(msgBody.has(ITalkService.TagString.clientType)){
252 message.setFromClientType(msgBody.getInt(ITalkService.TagString.clientType));
255 catch (Throwable e) {
256 NimLog.e(TAG,
"messageDeserialization exception, fromClientType error, fromClientType = "+msgBody.opt(ITalkService.TagString.clientType),e);
261 if(msgBody.has(ITalkService.TagString.fromNick)){
262 message.setMsgFromNick(msgBody.getString(ITalkService.TagString.fromNick));
265 catch (Throwable e) {
266 NimLog.e(TAG,
"messageDeserialization exception, fromNick error, fromNick = "+msgBody.opt(ITalkService.TagString.fromNick),e);
271 if(msgBody.has(ITalkService.TagString.time)){
272 message.setCreateTime(msgBody.getLong(ITalkService.TagString.time));
275 catch (Throwable e) {
276 NimLog.e(TAG,
"messageDeserialization exception, createTime error, createTime = "+msgBody.opt(ITalkService.TagString.time),e);
281 if(msgBody.has(ITalkService.TagString.type)){
283 message.setMessageType(messageType);
286 catch (Throwable e) {
287 NimLog.e(TAG,
"messageDeserialization exception, messageType error, messageType = "+msgBody.opt(ITalkService.TagString.type),e);
292 if(msgBody.has(ITalkService.TagString.body)){
293 message.setText(msgBody.getString(ITalkService.TagString.body));
296 catch (Throwable e) {
297 NimLog.e(TAG,
"messageDeserialization exception, text error, text = "+msgBody.opt(ITalkService.TagString.body),e);
302 if(msgBody.has(ITalkService.TagString.attach)){
303 String attachment = msgBody.getString(TagString.attach);
304 message.setAttachment(V2MessageModelConverter.parseV2Attachment(messageType,attachment));
307 catch (Throwable e) {
308 NimLog.e(TAG,
"messageDeserialization exception, attachment error, attachment = "+msgBody.opt(ITalkService.TagString.attach),e);
313 if(msgBody.has(ITalkService.TagString.msgid_client)){
314 message.setMessageClientId(msgBody.getString(ITalkService.TagString.msgid_client));
317 catch (Throwable e) {
318 NimLog.e(TAG,
"messageDeserialization exception, messageClientId error, messageClientId = "+msgBody.opt(ITalkService.TagString.msgid_client),e);
323 if(msgBody.has(ITalkService.TagString.msgid_server)){
324 message.setMessageServerId(msgBody.getLong(ITalkService.TagString.msgid_server));
327 catch (Throwable e) {
328 NimLog.e(TAG,
"messageDeserialization exception, messageServerId error, messageServerId = "+msgBody.opt(ITalkService.TagString.msgid_server),e);
333 if(msgBody.has(ITalkService.TagString.ext)){
334 message.setServerExtension(msgBody.getString(ITalkService.TagString.ext));
337 catch (Throwable e) {
338 NimLog.e(TAG,
"messageDeserialization exception, serverExtension error, serverExtension = "+msgBody.opt(ITalkService.TagString.ext),e);
342 V2NIMMessagePushConfigBuilder pushConfigBuilder = V2NIMMessagePushConfigBuilder.builder();
344 if(msgBody.has(ITalkService.TagString.pushEnable)){
345 pushConfigBuilder.withPushEnabled(msgBody.getInt(ITalkService.TagString.pushEnable) == 1);
348 catch (Throwable e) {
349 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, pushEnable = "+msgBody.opt(ITalkService.TagString.pushEnable),e);
354 if(msgBody.has(ITalkService.TagString.pushPayload)){
355 pushConfigBuilder.withPayload(msgBody.getString(ITalkService.TagString.pushPayload));
358 catch (Throwable e) {
359 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, pushPayload = "+msgBody.opt(ITalkService.TagString.pushPayload),e);
364 if(msgBody.has(ITalkService.TagString.pushContent)){
365 pushConfigBuilder.withContent(msgBody.getString(ITalkService.TagString.pushContent));
368 catch (Throwable e) {
369 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, pushContent = "+msgBody.opt(ITalkService.TagString.pushContent),e);
374 if(msgBody.has(ITalkService.TagString.needPushNick)){
375 pushConfigBuilder.withPushNickEnabled(msgBody.getInt(ITalkService.TagString.needPushNick) == 1);
378 catch (Throwable e) {
379 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, needPushNick = "+msgBody.opt(ITalkService.TagString.needPushNick),e);
384 if(msgBody.has(ITalkService.TagString.forcePushContent)){
385 pushConfigBuilder.withForcePushContent(msgBody.getString(ITalkService.TagString.forcePushContent));
388 catch (Throwable e) {
389 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, forcePushContent = "+msgBody.opt(ITalkService.TagString.forcePushContent),e);
394 if(msgBody.has(ITalkService.TagString.isForcePush)){
395 pushConfigBuilder.withForcePush(msgBody.getInt(ITalkService.TagString.isForcePush) == 1);
398 catch (Throwable e) {
399 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, isForcePush = "+msgBody.opt(ITalkService.TagString.isForcePush),e);
404 if(msgBody.has(ITalkService.TagString.forcePushList)){
405 String forcePushListStr = msgBody.optString(ITalkService.TagString.forcePushList);
406 if (!TextUtils.isEmpty(forcePushListStr)) {
407 pushConfigBuilder.withForcePushAccountIds(MsgHelper.getListFromJsonString(forcePushListStr));
411 catch (Throwable e) {
412 NimLog.e(TAG,
"messageDeserialization exception, pushConfig error, forcePushList = "+msgBody.opt(ITalkService.TagString.forcePushList),e);
416 message.setPushConfig(pushConfigBuilder.build());
418 V2NIMMessageAntispamConfigBuilder antispamConfigBuilder = V2NIMMessageAntispamConfigBuilder.builder();
420 if(msgBody.has(ITalkService.TagString.antiSpamContent)){
421 antispamConfigBuilder.withAntispamCustomMessage(msgBody.getString(ITalkService.TagString.antiSpamContent));
424 catch (Throwable e) {
425 NimLog.e(TAG,
"messageDeserialization exception, antispamConfig error, antispamCustomMessage = "+msgBody.opt(ITalkService.TagString.antiSpamContent),e);
430 if(msgBody.has(ITalkService.TagString.antiSpamUsingYidun)){
431 antispamConfigBuilder.withAntispamEnabled(msgBody.getInt(ITalkService.TagString.antiSpamUsingYidun) == 1);
434 catch (Throwable e) {
435 NimLog.e(TAG,
"messageDeserialization exception, antispamConfig error, antispamEnabled = "+msgBody.opt(ITalkService.TagString.antiSpamUsingYidun),e);
440 if(msgBody.has(ITalkService.TagString.antiSpamConfigId)){
441 antispamConfigBuilder.withAntispamBusinessId(msgBody.getString(ITalkService.TagString.antiSpamConfigId));
444 catch (Throwable e) {
445 NimLog.e(TAG,
"messageDeserialization exception, antispamConfig error, antispamBusinessId = "+msgBody.opt(ITalkService.TagString.antiSpamConfigId),e);
450 if(msgBody.has(ITalkService.TagString.yidunAntiCheating)){
451 antispamConfigBuilder.withAntispamCheating(msgBody.getString(ITalkService.TagString.yidunAntiCheating));
454 catch (Throwable e) {
455 NimLog.e(TAG,
"messageDeserialization exception, antispamConfig error, antispamCheating = "+msgBody.opt(ITalkService.TagString.yidunAntiCheating),e);
460 if(msgBody.has(ITalkService.TagString.yidunAntiSpamExt)){
461 antispamConfigBuilder.withAntispamExtension(msgBody.getString(ITalkService.TagString.yidunAntiSpamExt));
464 catch (Throwable e) {
465 NimLog.e(TAG,
"messageDeserialization exception, antispamConfig error, antispamExtension = "+msgBody.opt(ITalkService.TagString.yidunAntiSpamExt),e);
469 message.setAntispamConfig(antispamConfigBuilder.build());
471 V2NIMMessageConfigBuilder messageConfigBuilder = V2NIMMessageConfigBuilder.builder();
474 if(msgBody.has(ITalkService.TagString.msgAck)){
475 messageConfigBuilder.withReadReceiptEnabled(msgBody.getInt(ITalkService.TagString.msgAck) == 1);
478 catch (Throwable e) {
479 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, readReceiptEnabled = "+msgBody.opt(ITalkService.TagString.msgAck),e);
484 if(msgBody.has(ITalkService.TagString.isSessionUpdate)){
485 messageConfigBuilder.withLastMessageUpdateEnabled(msgBody.getInt(ITalkService.TagString.isSessionUpdate) == 1);
488 catch (Throwable e) {
489 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, lastMessageUpdateEnabled = "+msgBody.opt(ITalkService.TagString.isSessionUpdate),e);
494 if(msgBody.has(ITalkService.TagString.historyEnable)){
495 messageConfigBuilder.withHistoryEnabled(msgBody.getInt(ITalkService.TagString.historyEnable) == 1);
498 catch (Throwable e) {
499 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, historyEnable = "+msgBody.opt(ITalkService.TagString.historyEnable),e);
504 if(msgBody.has(ITalkService.TagString.roamingEnable)){
505 messageConfigBuilder.withRoamingEnabled(msgBody.getInt(ITalkService.TagString.roamingEnable) == 1);
508 catch (Throwable e) {
509 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, roamingEnable = "+msgBody.opt(ITalkService.TagString.roamingEnable),e);
514 if(msgBody.has(ITalkService.TagString.selfSyncEnable)){
515 messageConfigBuilder.withOnlineSyncEnabled(msgBody.getInt(ITalkService.TagString.selfSyncEnable) == 1);
518 catch (Throwable e) {
519 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, onlineSyncEnabled = "+msgBody.opt(ITalkService.TagString.selfSyncEnable),e);
524 if(msgBody.has(ITalkService.TagString.persistEnable)){
525 messageConfigBuilder.withOfflineEnabled(msgBody.getInt(ITalkService.TagString.persistEnable) == 1);
528 catch (Throwable e) {
529 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, offlineEnabled = "+msgBody.opt(ITalkService.TagString.persistEnable),e);
534 if(msgBody.has(ITalkService.TagString.needBadge)){
535 messageConfigBuilder.withUnreadEnabled(msgBody.getInt(ITalkService.TagString.needBadge) == 1);
538 catch (Throwable e) {
539 NimLog.e(TAG,
"messageDeserialization exception, messageConfig error, unreadEnabled = "+msgBody.opt(ITalkService.TagString.needBadge),e);
543 message.setMessageConfig(messageConfigBuilder.build());
545 boolean hasThreadRoot =
false;
547 String threadRootSenderId =
null;
549 if (msgBody.has(ITalkService.TagString.threadMsgFromAccount)) {
550 threadRootSenderId = msgBody.getString(ITalkService.TagString.threadMsgFromAccount);
551 hasThreadRoot =
true;
554 catch (Throwable e) {
555 NimLog.e(TAG,
"messageDeserialization exception, threadRootSenderId error, threadRoot senderId = "+msgBody.opt(ITalkService.TagString.threadMsgFromAccount),e);
559 String threadRootReceiverId =
null;
561 if (msgBody.has(ITalkService.TagString.threadMsgToAccount)) {
562 threadRootReceiverId = msgBody.getString(ITalkService.TagString.threadMsgToAccount);
563 hasThreadRoot =
true;
566 catch (Throwable e) {
567 NimLog.e(TAG,
"messageDeserialization exception, threadRootReceiverId error, threadRoot receiverId = "+msgBody.opt(ITalkService.TagString.threadMsgToAccount),e);
571 long threadRootCreateTime = 0;
573 if (msgBody.has(ITalkService.TagString.threadMsgTime)) {
574 threadRootCreateTime = msgBody.getLong(ITalkService.TagString.threadMsgTime);
575 hasThreadRoot =
true;
578 catch (Throwable e) {
579 NimLog.e(TAG,
"messageDeserialization exception, threadRootCreateTime error, threadRoot createTime = "+msgBody.opt(ITalkService.TagString.threadMsgTime),e);
583 long threadRootMessageServerId = 0;
585 if (msgBody.has(ITalkService.TagString.threadMsgIdServer)) {
586 threadRootMessageServerId = msgBody.getLong(ITalkService.TagString.threadMsgIdServer);
587 hasThreadRoot =
true;
590 catch (Throwable e) {
591 NimLog.e(TAG,
"messageDeserialization exception, threadRootMessageServerId error, threadRoot messageServerId = "+msgBody.opt(ITalkService.TagString.threadMsgIdServer),e);
595 String threadRootMessageClientId =
null;
597 if (msgBody.has(ITalkService.TagString.threadMsgIdClient)) {
598 threadRootMessageClientId = msgBody.getString(ITalkService.TagString.threadMsgIdClient);
599 hasThreadRoot =
true;
602 catch (Throwable e) {
603 NimLog.e(TAG,
"messageDeserialization exception, threadRootMessageClientId error, threadRoot messageClientId = "+msgBody.opt(ITalkService.TagString.threadMsgIdClient),e);
608 V2NIMMessageReferImpl threadRoot =
new V2NIMMessageReferImpl(
610 threadRootReceiverId,
611 threadRootMessageClientId,
612 threadRootMessageServerId,
615 threadRootCreateTime);
616 message.setThreadRoot(threadRoot);
619 boolean hasThreadReply =
false;
621 String threadReplySenderId =
null;
623 if (msgBody.has(ITalkService.TagString.replyMsgFromAccount)) {
624 threadReplySenderId = msgBody.getString(ITalkService.TagString.replyMsgFromAccount);
625 hasThreadReply =
true;
628 catch (Throwable e) {
629 NimLog.e(TAG,
"messageDeserialization exception, threadReplySenderId error, threadReply senderId = "+msgBody.opt(ITalkService.TagString.replyMsgFromAccount),e);
633 String threadReplyReceiverId =
null;
635 if (msgBody.has(ITalkService.TagString.replyMsgToAccount)) {
636 threadReplyReceiverId = msgBody.getString(ITalkService.TagString.replyMsgToAccount);
637 hasThreadReply =
true;
640 catch (Throwable e) {
641 NimLog.e(TAG,
"messageDeserialization exception, threadReplyReceiverId error, threadReply receiverId = "+msgBody.opt(ITalkService.TagString.replyMsgToAccount),e);
645 long threadReplyCreateTime = 0;
647 if (msgBody.has(ITalkService.TagString.replyMsgTime)) {
648 threadReplyCreateTime = msgBody.getLong(ITalkService.TagString.replyMsgTime);
649 hasThreadReply =
true;
652 catch (Throwable e) {
653 NimLog.e(TAG,
"messageDeserialization exception, threadReplyCreateTime error, threadReply createTime = "+msgBody.opt(ITalkService.TagString.replyMsgTime),e);
657 long threadReplyMessageServerId = 0;
659 if (msgBody.has(ITalkService.TagString.replyMsgIdServer)) {
660 threadReplyMessageServerId = msgBody.getLong(ITalkService.TagString.replyMsgIdServer);
661 hasThreadReply =
true;
664 catch (Throwable e) {
665 NimLog.e(TAG,
"messageDeserialization exception, threadReplyMessageServerId error, threadReply messageServerId = "+msgBody.opt(ITalkService.TagString.replyMsgIdServer),e);
669 String threadReplyMessageClientId =
null;
671 if (msgBody.has(ITalkService.TagString.replyMsgIdClient)) {
672 threadReplyMessageClientId = msgBody.getString(ITalkService.TagString.replyMsgIdClient);
673 hasThreadReply =
true;
676 catch (Throwable e) {
677 NimLog.e(TAG,
"messageDeserialization exception, threadReplyMessageClientId error, threadReply messageClientId = "+msgBody.opt(ITalkService.TagString.replyMsgIdClient),e);
682 V2NIMMessageReferImpl threadReply =
new V2NIMMessageReferImpl(
684 threadReplyReceiverId,
685 threadReplyMessageClientId,
686 threadReplyMessageServerId,
689 threadReplyCreateTime);
690 message.setThreadReply(threadReply);
695 if (msgBody.has(ITalkService.TagString.delete)) {
696 message.setDeleted(msgBody.getInt(ITalkService.TagString.delete) == 1);
699 catch (Throwable e) {
700 NimLog.e(TAG,
"messageDeserialization exception, delete error, delete = "+msgBody.opt(ITalkService.TagString.delete),e);
705 if (msgBody.has(ITalkService.TagString.callbackExt)) {
706 message.setCallbackExtension(msgBody.getString(ITalkService.TagString.callbackExt));
709 catch (Throwable e) {
710 NimLog.e(TAG,
"messageDeserialization exception, callbackExt error, callbackExt = "+msgBody.opt(ITalkService.TagString.callbackExt),e);
716 if (msgBody.has(ITalkService.TagString.subtype)) {
717 message.setSubType(msgBody.getInt(ITalkService.TagString.subtype));
720 catch (Throwable e) {
721 NimLog.e(TAG,
"messageDeserialization exception, subtype error, subtype = "+msgBody.opt(ITalkService.TagString.subtype),e);
728 if (msgBody.has(ITalkService.TagString.clientExt)){
729 String clientExt = msgBody.getString(ITalkService.TagString.clientExt);
730 TimeConsumingStatisticsImpl timeConsumingStatistics = TimeConsumingStatisticsImpl.initWithClientExt(clientExt);
731 message.setTimeConsumingStatistics(timeConsumingStatistics);
734 catch (Throwable e) {
735 NimLog.e(TAG,
"messageDeserialization exception, clientExt error, clientExt = "+msgBody.opt(ITalkService.TagString.clientExt),e);
739 boolean hasRobotConfig =
false;
741 String robotConfigFunction =
null;
743 if(msgBody.has(ITalkService.TagString.function)){
744 robotConfigFunction = msgBody.getString(ITalkService.TagString.function);
745 hasRobotConfig =
true;
748 catch (Throwable e) {
749 NimLog.e(TAG,
"messageDeserialization exception, robotConfig error, function = "+msgBody.opt(ITalkService.TagString.function),e);
753 String robotConfigTopic =
null;
755 if(msgBody.has(ITalkService.TagString.topic)){
756 robotConfigTopic = msgBody.getString(ITalkService.TagString.topic);
757 hasRobotConfig =
true;
760 catch (Throwable e) {
761 NimLog.e(TAG,
"messageDeserialization exception, robotConfig error, topic = "+msgBody.opt(ITalkService.TagString.topic),e);
765 String robotConfigCustomContent =
null;
767 if(msgBody.has(ITalkService.TagString.customContent)){
768 robotConfigCustomContent = msgBody.getString(ITalkService.TagString.customContent);
769 hasRobotConfig =
true;
772 catch (Throwable e) {
773 NimLog.e(TAG,
"messageDeserialization exception, robotConfig error, customContent = "+msgBody.opt(ITalkService.TagString.customContent),e);
777 String robotConfigAccountId =
null;
779 if(msgBody.has(ITalkService.TagString.account)){
780 robotConfigAccountId = msgBody.getString(ITalkService.TagString.account);
783 catch (Throwable e) {
784 NimLog.e(TAG,
"messageDeserialization exception, robotConfig error, accountId = "+msgBody.opt(ITalkService.TagString.account),e);
789 V2NIMMessageRobotConfigBuilder robotConfigBuilder = V2NIMMessageRobotConfigBuilder.builder();
790 robotConfigBuilder.withFunction(robotConfigFunction);
791 robotConfigBuilder.withTopic(robotConfigTopic);
792 robotConfigBuilder.withCustomContent(robotConfigCustomContent);
793 robotConfigBuilder.withAccountId(robotConfigAccountId);
794 message.setRobotConfig(robotConfigBuilder.build());
797 V2NIMMessageRouteConfigBuilder routeConfigBuilder = V2NIMMessageRouteConfigBuilder.builder();
800 if(msgBody.has(ITalkService.TagString.routeEnable)){
801 routeConfigBuilder.withRouteEnabled(msgBody.getInt(ITalkService.TagString.routeEnable) == 1);
804 catch (Throwable e) {
805 NimLog.e(TAG,
"messageDeserialization exception, routeConfig error, routeEnable = "+msgBody.opt(ITalkService.TagString.routeEnable),e);
810 if(msgBody.has(ITalkService.TagString.env)){
811 routeConfigBuilder.withRouteEnvironment(msgBody.getString(ITalkService.TagString.env));
814 catch (Throwable e) {
815 NimLog.e(TAG,
"messageDeserialization exception, routeConfig error, routeEnvironment = "+msgBody.opt(ITalkService.TagString.env),e);
819 message.setRouteConfig(routeConfigBuilder.build());
822 if(msgBody.has(ITalkService.TagString.isBlackListed)){
823 message.setInBlackList(msgBody.getInt(ITalkService.TagString.isBlackListed) == 1);
826 catch (Throwable e) {
827 NimLog.e(TAG,
"messageDeserialization exception, isBlackListed error, isBlackListed = "+msgBody.opt(ITalkService.TagString.isBlackListed),e);
832 if(msgBody.has(ITalkService.TagString.ai_agent_account)){
834 aiConfig.
setAccountId(msgBody.optString(ITalkService.TagString.ai_agent_account));
836 message.setAIConfig(aiConfig);
839 catch (Throwable e) {
840 NimLog.e(TAG,
"messageDeserialization exception, ai_agent_account error, ai_agent_account = "+msgBody.optString(ITalkService.TagString.ai_agent_account),e);
845 if(msgBody.has(ITalkService.TagString.ai_agent_error_code)){
846 message.setAIErrorCode(msgBody.optInt(ITalkService.TagString.ai_agent_error_code));
849 catch (Throwable e) {
850 NimLog.e(TAG,
"messageDeserialization exception, ai_agent_error_code error, ai_agent_error_code = "+msgBody.optInt(ITalkService.TagString.ai_agent_error_code),e);
855 if(msgBody.has(ITalkService.TagString.modifyTimetag)){
856 message.setModifyTime(msgBody.optLong(ITalkService.TagString.modifyTimetag));
859 catch (Throwable e) {
860 NimLog.e(TAG,
"messageDeserialization exception, modifyTimetag error, modifyTimetag = "+msgBody.optLong(ITalkService.TagString.modifyTimetag),e);
865 if(msgBody.has(ITalkService.TagString.modifyAccid)){
866 message.setModifyAccountId(msgBody.optString(ITalkService.TagString.modifyAccid));
869 catch (Throwable e) {
870 NimLog.e(TAG,
"messageDeserialization exception, modifyAccid error, modifyAccid = "+msgBody.optString(ITalkService.TagString.modifyAccid),e);
878 private static String sessionIdOfMsg(
int sessionType,String fromId, String receiver, String currentAccount) {
880 if (TextUtils.isEmpty(currentAccount)) {
883 if (sessionType == ITalkService.SessionType.P2P || sessionType == ITalkService.SessionType.Ysf) {
885 if(!currentAccount.equals(fromId) && !currentAccount.equals(receiver)) {
888 return TextUtils.equals(currentAccount, fromId) ? receiver : fromId;
static String messageSerialization(V2NIMMessage message)
消息序列化为字符串
static V2NIMMessage messageDeserialization(String msg)
字符串反序列化为消息对象
void setAIStatus(V2NIMMessageAIStatus aiStatus)
设置该 AI 消息的询问和应答标识
String getAccountId()
获取数字人的 accountId
V2NIMMessageAIStatus getAIStatus()
获取该 AI 消息的询问和应答标识
void setAccountId(String accountId)
设置数字人的 accountId
String getAntispamBusinessId()
String getAntispamCheating()
String getAntispamExtension()
String getAntispamCustomMessage()
boolean isAntispamEnabled()
boolean isRoamingEnabled()
boolean isUnreadEnabled()
boolean isReadReceiptEnabled()
boolean isHistoryEnabled()
boolean isLastMessageUpdateEnabled()
boolean isOfflineEnabled()
boolean isOnlineSyncEnabled()
String getForcePushContent()
List< String > getForcePushAccountIds()
boolean isPushNickEnabled()
String getCustomContent()
String getRouteEnvironment()
static SessionTypeEnum typeOfValue(int value)
static V2NIMMessageAIStatus typeOfValue(int value)
static V2NIMMessageType typeOfValue(int value)