Skip to content

Commit db8a7bc

Browse files
KenChoiKenChoi
authored andcommitted
add getChatRoomOwner
1 parent 37f9902 commit db8a7bc

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

android/src/io/jchat/android/Constant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ public class Constant {
9999
public static final String ROOM_ID = "roomId";
100100
public static final String ROOM_IDS = "roomIds";
101101
public static final String ROOM_NAME = "roomName";
102-
public static final String TOTAL_MEMBER_COUNT = "totalMemberCount";
102+
public static final String MEMBER_COUNT = "memberCount";
103103
}

android/src/io/jchat/android/JMessageModule.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public void createSendMessage(ReadableMap map, Callback callback) {
308308
content = new ImageContent(new File(path));
309309
} else if (type.equals(Constant.VOICE)) {
310310
String path = map.getString(Constant.PATH);
311-
File file = new File(map.getString(path));
311+
File file = new File(path);
312312
MediaPlayer mediaPlayer = MediaPlayer.create(mContext, Uri.parse(path));
313313
int duration = mediaPlayer.getDuration() / 1000; // Millisecond to second.
314314
content = new VoiceContent(file, duration);
@@ -1473,7 +1473,7 @@ public void getChatRoomListByApp(ReadableMap param, final Callback success, fina
14731473
@Override
14741474
public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfos) {
14751475
mJMessageUtils.handleCallbackWithArray(status, desc, success, fail,
1476-
ResultUtils.toJSArray(chatRoomInfos, fail));
1476+
ResultUtils.toJSArray(chatRoomInfos));
14771477
}
14781478
});
14791479
} catch (Exception e) {
@@ -1493,7 +1493,7 @@ public void getChatRoomListByUser(final Callback success, final Callback fail) {
14931493
ChatRoomManager.getChatRoomListByUser(new RequestCallback<List<ChatRoomInfo>>() {
14941494
@Override
14951495
public void gotResult(int status, String desc, List<ChatRoomInfo> list) {
1496-
mJMessageUtils.handleCallbackWithArray(status, desc, success, fail, ResultUtils.toJSArray(list, fail));
1496+
mJMessageUtils.handleCallbackWithArray(status, desc, success, fail, ResultUtils.toJSArray(list));
14971497
}
14981498
});
14991499
}
@@ -1516,7 +1516,36 @@ public void getChatRoomInfos(ReadableMap map, final Callback success, final Call
15161516
ChatRoomManager.getChatRoomInfos(idSet, new RequestCallback<List<ChatRoomInfo>>() {
15171517
@Override
15181518
public void gotResult(int status, String desc, List<ChatRoomInfo> list) {
1519-
mJMessageUtils.handleCallbackWithArray(status, desc, success, fail, ResultUtils.toJSArray(list, fail));
1519+
mJMessageUtils.handleCallbackWithArray(status, desc, success, fail, ResultUtils.toJSArray(list));
1520+
}
1521+
});
1522+
} catch (Exception e) {
1523+
e.printStackTrace();
1524+
mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER);
1525+
}
1526+
}
1527+
1528+
/**
1529+
* 获取聊天室拥有者 UserInfo
1530+
* @param roomId 聊天室 id
1531+
* @param success 成功回调
1532+
* @param fail 失败回调
1533+
*/
1534+
@ReactMethod
1535+
public void getChatRoomOwner(String roomId, final Callback success, final Callback fail) {
1536+
try {
1537+
long id = Long.parseLong(roomId);
1538+
Set<Long> set = new HashSet<>();
1539+
set.add(id);
1540+
ChatRoomManager.getChatRoomInfos(set, new RequestCallback<List<ChatRoomInfo>>() {
1541+
@Override
1542+
public void gotResult(int status, String desc, List<ChatRoomInfo> list) {
1543+
list.get(0).getOwnerInfo(new GetUserInfoCallback() {
1544+
@Override
1545+
public void gotResult(int status, String desc, UserInfo userInfo) {
1546+
mJMessageUtils.handleCallbackWithObject(status, desc, success, fail, ResultUtils.toJSObject(userInfo));
1547+
}
1548+
});
15201549
}
15211550
});
15221551
} catch (Exception e) {

android/src/io/jchat/android/utils/ResultUtils.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static WritableMap toJSObject(Conversation conversation) {
257257
map.putMap(Constant.TARGET, toJSObject(targetInfo));
258258
} else {
259259
ChatRoomInfo chatRoomInfo = (ChatRoomInfo) conversation.getTargetInfo();
260-
map.putMap(Constant.TARGET, toJSObject(chatRoomInfo, null));
260+
map.putMap(Constant.TARGET, toJSObject(chatRoomInfo));
261261
}
262262

263263
} catch (Exception e) {
@@ -267,29 +267,16 @@ public static WritableMap toJSObject(Conversation conversation) {
267267
return map;
268268
}
269269

270-
public static WritableMap toJSObject(ChatRoomInfo chatRoomInfo, final Callback fail) {
270+
public static WritableMap toJSObject(ChatRoomInfo chatRoomInfo) {
271271
final WritableMap map = Arguments.createMap();
272272
try {
273273
map.putString(Constant.ROOM_ID, String.valueOf(chatRoomInfo.getRoomID()));
274274
map.putString(Constant.TYPE, Constant.TYPE_CHAT_ROOM);
275275
map.putString(Constant.ROOM_NAME, chatRoomInfo.getName());
276276
map.putString(Constant.APP_KEY, chatRoomInfo.getAppkey());
277-
chatRoomInfo.getOwnerInfo(new GetUserInfoCallback() {
278-
@Override
279-
public void gotResult(int status, String desc, UserInfo userInfo) {
280-
if (status == 0) {
281-
map.putMap(Constant.OWNER, toJSObject(userInfo));
282-
} else if (fail != null) {
283-
WritableMap result = Arguments.createMap();
284-
result.putInt(Constant.CODE, status);
285-
result.putString(Constant.DESCRIPTION, desc);
286-
fail.invoke(result);
287-
}
288-
}
289-
});
290277
map.putInt(Constant.MAX_MEMBER_COUNT, chatRoomInfo.getMaxMemberCount());
291278
map.putString(Constant.DESCRIPTION, chatRoomInfo.getDescription());
292-
map.putInt(Constant.TOTAL_MEMBER_COUNT, chatRoomInfo.getTotalMemberCount());
279+
map.putInt(Constant.MEMBER_COUNT, chatRoomInfo.getTotalMemberCount());
293280
map.putInt(Constant.CREATE_TIME, chatRoomInfo.getCreateTime());
294281
} catch (Exception e) {
295282
e.printStackTrace();
@@ -309,6 +296,8 @@ public static WritableArray toJSArray(List list) {
309296
array.pushMap(toJSObject((Message) object));
310297
} else if (object instanceof Conversation) {
311298
array.pushMap(toJSObject((Conversation) object));
299+
} else if (object instanceof ChatRoomInfo) {
300+
array.pushMap(toJSObject((ChatRoomInfo) object));
312301
} else {
313302
array.pushString(object.toString());
314303
}
@@ -318,16 +307,6 @@ public static WritableArray toJSArray(List list) {
318307
return array;
319308
}
320309

321-
public static WritableArray toJSArray(List<ChatRoomInfo> list, Callback fail) {
322-
WritableArray array = Arguments.createArray();
323-
if (null != list) {
324-
for (ChatRoomInfo chatRoomInfo : list) {
325-
array.pushMap(toJSObject(chatRoomInfo, fail));
326-
}
327-
}
328-
return array;
329-
}
330-
331310
public static JSONObject toJSObject(String eventName, JSONObject value) {
332311
JSONObject result = new JSONObject();
333312
try {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jmessage-react-plugin",
3-
"version": "2.1.4",
3+
"version": "2.1.5",
44
"description": "a jmessage plugin for react native application",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)