Skip to content

Commit

Permalink
Optimize the method of message to json
Browse files Browse the repository at this point in the history
  • Loading branch information
Hevin committed Jan 22, 2018
1 parent 6c2ed93 commit 3461d70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions src/android/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,23 @@ static JSONObject toJson(Message msg) {
result.put("from", toJson(msg.getFromUser())); // 消息发送者
result.put("isSend", msg.getDirect() == MessageDirect.send); // 消息是否是由当前用户发出

if (msg.getDirect() == MessageDirect.send) { // 消息发送
if (msg.getTargetType() == ConversationType.single) { // 消息发送对象的类型
result.put("target", toJson((UserInfo) msg.getTargetInfo()));
} else if (msg.getTargetType() == ConversationType.group) {
result.put("target", toJson((GroupInfo) msg.getTargetInfo()));
}

} else if (msg.getDirect() == MessageDirect.receive) { // 消息接收
if (msg.getTargetType() == ConversationType.single) {
result.put("target", toJson(JMessageClient.getMyInfo()));
} else if (msg.getTargetType() == ConversationType.group) {
result.put("target", toJson((GroupInfo) msg.getTargetInfo()));
}
JSONObject targetJson = null;
switch (msg.getTargetType()) {
case single:
if (msg.getDirect() == MessageDirect.send) { // 消息发送
targetJson = toJson((UserInfo) msg.getTargetInfo());
} else { // 消息接收
targetJson = toJson(JMessageClient.getMyInfo());
}
break;
case group:
targetJson = toJson((GroupInfo) msg.getTargetInfo());
break;
case chatroom:
targetJson = toJson((ChatRoomInfo) msg.getTargetInfo());
break;
}
result.put("target", targetJson);

MessageContent content = msg.getContent();
if (content.getStringExtras() != null) {
Expand Down
2 changes: 1 addition & 1 deletion www/JMessagePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ var JMessagePlugin = {
exec(success, error, PLUGIN_NAME, 'exitChatRoom', [params])
},
/**
* 获取聊天室会话信息。如果无法返回
* 获取聊天室会话信息。
*
* @param {object} params = { roomId: String }
* @param {function} success = function (conversation) {}
Expand Down

0 comments on commit 3461d70

Please sign in to comment.