Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hevin committed Apr 2, 2018
1 parent 20842f7 commit e40beb3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/android/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ static JSONObject toJson(Message msg) {
result.put("id", String.valueOf(msg.getId())); // 本地数据库 id
result.put("serverMessageId", String.valueOf(msg.getServerMessageId())); // 服务器端 id
result.put("from", toJson(msg.getFromUser())); // 消息发送者
result.put("isSend", msg.getDirect() == MessageDirect.send); // 消息是否是由当前用户发出

boolean isSend = msg.getDirect().equals(MessageDirect.send);
result.put("isSend", isSend); // 消息是否是由当前用户发出

JSONObject targetJson = null;
switch (msg.getTargetType()) {
case single:
if (msg.getDirect() == MessageDirect.send) { // 消息发送
if (isSend) { // 消息发送
targetJson = toJson((UserInfo) msg.getTargetInfo());
} else { // 消息接收
targetJson = toJson(JMessageClient.getMyInfo());
Expand All @@ -141,6 +143,7 @@ static JSONObject toJson(Message msg) {
case chatroom:
targetJson = toJson((ChatRoomInfo) msg.getTargetInfo());
break;
default:
}
result.put("target", targetJson);

Expand Down Expand Up @@ -186,7 +189,9 @@ static JSONObject toJson(Message msg) {
case eventNotification:
result.put("type", "event");
List usernameList = ((EventNotificationContent) content).getUserNames();
result.put("usernames", toJson(usernameList));
if (usernameList != null) {
result.put("usernames", toJson(usernameList));
}
switch (((EventNotificationContent) content).getEventNotificationType()) {
case group_member_added:
//群成员加群事件
Expand All @@ -200,7 +205,9 @@ static JSONObject toJson(Message msg) {
//群成员退群事件
result.put("eventType", "group_member_exit");
break;
default:
}
default:
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down

0 comments on commit e40beb3

Please sign in to comment.