Skip to content

Commit c07ac73

Browse files
authored
Merge pull request #149 from weiruiyang/master
getChatRoomConversation 调用无数据时错误问题
2 parents 1fe6ac0 + 736e546 commit c07ac73

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

android/src/main/java/com/jiguang/jmessageflutter/JsonUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ static Message JsonToMessage(JSONObject json) {
414414
static HashMap toJson(Conversation conversation) {
415415

416416
final HashMap json = new HashMap<String, Object>();
417+
if (null == conversation){
418+
return json;
419+
}
420+
417421
json.put("title", conversation.getTitle() != null ? conversation.getTitle() : "");
418422
json.put("unreadCount", conversation.getUnReadMsgCnt());
419423

example/lib/main.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ class _MyHomePageState extends State<MyHomePage> {
10031003
});
10041004

10051005
test('getChatRoomConversation', () async {
1006-
JMConversationInfo conv =
1006+
JMConversationInfo? conv =
10071007
await jmessage.getChatRoomConversation(roomId: kMockChatRoomid);
10081008
verifyConversation(conv);
10091009
});
@@ -1267,8 +1267,11 @@ void verifyGroupMember(JMGroupMemberInfo groupMember) {
12671267
verifyUser(groupMember.user);
12681268
}
12691269

1270-
void verifyConversation(JMConversationInfo conversation) {
1270+
void verifyConversation(JMConversationInfo? conversation) {
12711271
expect(conversation, isNotNull, reason: 'conversation is null');
1272+
if(null == conversation){
1273+
return;
1274+
}
12721275
expect(conversation.conversationType, isNotNull,
12731276
reason: 'conversation conversationType is null');
12741277
expect(conversation.title, isNotNull, reason: 'conversation title is null');

lib/jmessage_flutter.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,12 +1508,14 @@ class JmessageFlutter {
15081508
return;
15091509
}
15101510

1511-
Future<JMConversationInfo> getChatRoomConversation({
1511+
Future<JMConversationInfo?> getChatRoomConversation({
15121512
required String? roomId,
15131513
}) async {
15141514
Map resJson = await _channel.invokeMethod('getChatRoomConversation',
15151515
{'roomId': roomId}..removeWhere((key, value) => value == null));
1516-
1516+
if(resJson == null || resJson.isEmpty){
1517+
return null;
1518+
}
15171519
return JMConversationInfo.fromJson(resJson);
15181520
}
15191521

0 commit comments

Comments
 (0)