Skip to content

Commit

Permalink
Update group API
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLipan committed Dec 13, 2018
1 parent 941807e commit 04c2d44
Showing 1 changed file with 53 additions and 58 deletions.
111 changes: 53 additions & 58 deletions src/android/JMessagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public void gotResult(int status, String desc) {

public void userLogin(JSONArray data, final CallbackContext callback) {
String username, password;

try {
JSONObject params = data.getJSONObject(0);
username = params.getString("username");
Expand Down Expand Up @@ -2758,7 +2757,6 @@ public void onEvent(MessageRetractEvent event) throws JSONException {
public void onEvent(CommandNotificationEvent event) throws JSONException {
final JSONObject result = new JSONObject();
result.put("content", event.getMsg());

event.getSenderUserInfo(new GetUserInfoCallback() {
@Override
public void gotResult(int status, String desc, UserInfo userInfo) {
Expand All @@ -2769,37 +2767,37 @@ public void gotResult(int status, String desc, UserInfo userInfo) {
e.printStackTrace();
}
}
}
});
event.getTargetInfo(new CommandNotificationEvent.GetTargetInfoCallback() {
@Override
public void gotResult(int status, String desc, Object obj, CommandNotificationEvent.Type type) {
if (status == 0) {
if (type == CommandNotificationEvent.Type.single) {
try {
UserInfo receiver = (UserInfo) obj;
result.put("receiver", toJson(receiver));
result.put("receiverType", "single");
} catch (JSONException e) {
e.printStackTrace();
}

event.getTargetInfo(new CommandNotificationEvent.GetTargetInfoCallback() {
@Override
public void gotResult(int status, String desc, Object obj, CommandNotificationEvent.Type type) {
if (status == 0) {
if (type == CommandNotificationEvent.Type.single) {
try {
UserInfo receiver = (UserInfo) obj;
result.put("receiver", toJson(receiver));
result.put("receiverType", "single");
} catch (JSONException e) {
e.printStackTrace();
} else {
try {
GroupInfo receiver = (GroupInfo) obj;
result.put("receiver", toJson(receiver));
result.put("receiverType", "group");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
JSONObject eventJson = toJson("receiveTransCommand", result);
eventSuccess(eventJson);

} else {
try {
GroupInfo receiver = (GroupInfo) obj;
result.put("receiver", toJson(receiver));
result.put("receiverType", "group");
} catch (JSONException e) {
e.printStackTrace();
}
}

JSONObject eventJson = toJson("receiveTransCommand", result);
eventSuccess(eventJson);
}
});
}
});

}

/**
Expand Down Expand Up @@ -2845,24 +2843,23 @@ public void gotResult(int status, String desc, UserInfo userInfo) {
e.printStackTrace();
}
}
}
});
event.getApprovalUserInfoList(new GetUserInfoListCallback() {
@Override
public void gotResult(int status, String s, List<UserInfo> list) {
if (status == 0) {
try {
json.put("joinGroupUsers", toJson(list));
} catch (JSONException e) {
e.printStackTrace();
event.getApprovalUserInfoList(new GetUserInfoListCallback() {
@Override
public void gotResult(int status, String s, List<UserInfo> list) {
if (status == 0) {
try {
json.put("joinGroupUsers", toJson(list));
} catch (JSONException e) {
e.printStackTrace();
}
}
JSONObject eventJson = toJson("receiveApplyJoinGroupApproval", json);
eventSuccess(eventJson);
}
}
});
}
});

JSONObject eventJson = toJson("receiveApplyJoinGroupApproval", json);
eventSuccess(eventJson);

}

/**
Expand All @@ -2884,24 +2881,22 @@ public void gotResult(int status, String desc, UserInfo userInfo) {
e.printStackTrace();
}
}
}
});
event.getApprovedUserInfoList(new GetUserInfoListCallback() {
@Override
public void gotResult(int status, String s, List<UserInfo> list) {
if (status == 0) {
try {
json.put("users", toJson(list));
} catch (JSONException e) {
e.printStackTrace();
event.getApprovedUserInfoList(new GetUserInfoListCallback() {
@Override
public void gotResult(int status, String s, List<UserInfo> list) {
if (status == 0) {
try {
json.put("users", toJson(list));
} catch (JSONException e) {
e.printStackTrace();
}
}
JSONObject eventJson = toJson("receiveGroupAdminApproval", json);
eventSuccess(eventJson);
}
}
});
}
});

JSONObject eventJson = toJson("receiveGroupAdminApproval", json);
eventSuccess(eventJson);

}

/**
Expand All @@ -2919,15 +2914,15 @@ public void gotResult(int status, String desc, UserInfo userInfo) {
if (status == 0) {
try {
json.put("groupManager", toJson(userInfo));
JSONObject eventJson = toJson("receiveGroupAdminReject", json);
eventSuccess(eventJson);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});

JSONObject eventJson = toJson("receiveGroupAdminReject", json);
eventSuccess(eventJson);
}

private void eventSuccess(JSONObject value) {
Expand Down

0 comments on commit 04c2d44

Please sign in to comment.