Skip to content

Commit c451ec8

Browse files
authored
Merge pull request #538 from easemob/dev_4.0.0
Dev 4.0.0
2 parents a8a50b2 + 46c1d44 commit c451ec8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+826
-671
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
## NEXT
22

3+
## 4.0.0 Easemob IM Flutter 端发版说明
4+
5+
#### 新增特性
6+
7+
- 依赖的原生平台 `iOS``Android` 的 SDK 升级为 v4.0.0 版本。
8+
- 新增 `EMChatManager#fetchConversationListFromServer` 方法实现从服务器分页获取会话列表。
9+
- 新增 `EMMessage#chatroomMessagePriority` 属性实现聊天室消息优先级功能,确保高优先级消息优先处理。
10+
11+
#### 优化
12+
13+
修改发送消息结果的回调由 `EMMessage#setMessageStatusCallBack` 修改为 `EMChatManager#addMessageEvent`
14+
15+
#### 修复
16+
17+
修复 `EMChatManager#deleteMessagesBeforeTimestamp` 执行失败的问题。
318

419
# 3.9.9+1
520
修复:

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,7 @@ void _signIn() async {
321321
targetId: _chatId,
322322
content: _messageContent,
323323
);
324-
msg.setMessageStatusCallBack(MessageStatusCallBack(
325-
onSuccess: () {
326-
_addLogToConsole("send message succeed");
327-
},
328-
onError: (e) {
329-
_addLogToConsole(
330-
"send message failed, code: ${e.code}, desc: ${e.description}",
331-
);
332-
},
333-
));
324+
334325
EMClient.getInstance.chatManager.sendMessage(msg);
335326
}
336327
```
@@ -341,6 +332,26 @@ void _signIn() async {
341332

342333
```dart
343334
void _addChatListener() {
335+
336+
// 添加消息状态变更监听
337+
EMClient.getInstance.chatManager.addMessageEvent(
338+
// ChatMessageEvent 对应的 key。
339+
"UNIQUE_HANDLER_ID",
340+
ChatMessageEvent(
341+
onSuccess: (msgId, msg) {
342+
_addLogToConsole("send message succeed");
343+
},
344+
onProgress: (msgId, progress) {
345+
_addLogToConsole("send message succeed");
346+
},
347+
onError: (msgId, msg, error) {
348+
_addLogToConsole(
349+
"send message failed, code: ${error.code}, desc: ${error.description}",
350+
);
351+
},
352+
));
353+
354+
// 添加收消息监听
344355
EMClient.getInstance.chatManager.addEventHandler(
345356
// EMChatEventHandle 对应的 key。
346357
"UNIQUE_HANDLER_ID",
@@ -400,7 +411,7 @@ void _addChatListener() {
400411
break;
401412
case MessageType.CMD:
402413
{
403-
// 当前回调中不会有 CMD 类型消息,CMD 类型消息通过 `EMChatEventHandler#onCmdMessagesReceived` 回调接收
414+
// 当前回调中不会有 CMD 类型消息,CMD 类型消息通过 [EMChatEventHandler.onCmdMessagesReceived] 回调接收
404415
}
405416
break;
406417
}
@@ -418,6 +429,7 @@ void _addChatListener() {
418429
```dart
419430
@override
420431
void dispose() {
432+
EMClient.getInstance.chatManager.removeMessageEvent("UNIQUE_HANDLER_ID");
421433
EMClient.getInstance.chatManager.removeEventHandler("UNIQUE_HANDLER_ID");
422434
super.dispose();
423435
}

android/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ buildscript {
88
}
99

1010
dependencies {
11-
// classpath 'com.android.tools.build:gradle:3.5.0'
1211
classpath 'com.android.tools.build:gradle:4.2.0'
1312
}
1413
}
@@ -49,5 +48,5 @@ tasks.withType(JavaCompile){
4948

5049
dependencies {
5150
api 'androidx.appcompat:appcompat:1.1.0'
52-
implementation 'io.hyphenate:hyphenate-chat:3.9.9'
51+
implementation 'io.hyphenate:hyphenate-chat:4.0.0'
5352
}

android/src/main/java/com/easemob/im_flutter_sdk/EMChatManagerWrapper.java

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.hyphenate.EMConversationListener;
44
import com.hyphenate.EMMessageListener;
5+
import com.hyphenate.EMValueCallBack;
56
import com.hyphenate.chat.EMClient;
67
import com.hyphenate.chat.*;
78
import com.hyphenate.chat.EMConversation.EMSearchDirection;
@@ -110,6 +111,12 @@ public void onMethodCall(MethodCall call, Result result) {
110111
fetchReactionDetail(param, call.method, result);
111112
} else if (EMSDKMethod.reportMessage.equals(call.method)) {
112113
reportMessage(param, call.method, result);
114+
} else if (EMSDKMethod.fetchConversationsFromServerWithPage.equals(call.method)) {
115+
getConversationsFromServerWithPage(param, call.method, result);
116+
} else if (EMSDKMethod.removeMessagesFromServerWithMsgIds.equals(call.method)) {
117+
removeMessagesFromServerWithMsgIds(param, call.method, result);
118+
} else if (EMSDKMethod.removeMessagesFromServerWithTs.equals(call.method)) {
119+
removeMessagesFromServerWithTs(param, call.method, result);
113120
}
114121
else {
115122
super.onMethodCall(call, result);
@@ -121,13 +128,14 @@ public void onMethodCall(MethodCall call, Result result) {
121128

122129
private void sendMessage(JSONObject param, String channelName, Result result) throws JSONException {
123130
final EMMessage msg = EMMessageHelper.fromJson(param);
131+
final String localId = msg.getMsgId();
124132
msg.setMessageStatusCallback(new EMWrapperCallBack(result, channelName, null) {
125133
@Override
126134
public void onSuccess() {
127135
post(() -> {
128136
Map<String, Object> map = new HashMap<>();
129137
map.put("message", EMMessageHelper.toJson(msg));
130-
map.put("localTime", msg.localTime());
138+
map.put("localId", localId);
131139
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
132140
});
133141
}
@@ -137,7 +145,7 @@ public void onProgress(int progress, String status) {
137145
post(() -> {
138146
Map<String, Object> map = new HashMap<>();
139147
map.put("progress", progress);
140-
map.put("localTime", msg.localTime());
148+
map.put("localId", localId);
141149
messageChannel.invokeMethod(EMSDKMethod.onMessageProgressUpdate, map);
142150
});
143151
}
@@ -150,7 +158,7 @@ public void onError(int code, String desc) {
150158
post(() -> {
151159
Map<String, Object> map = new HashMap<>();
152160
map.put("message", EMMessageHelper.toJson(msg));
153-
map.put("localTime", msg.localTime());
161+
map.put("localId", localId);
154162
map.put("error", data);
155163
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
156164
});
@@ -170,13 +178,14 @@ private void resendMessage(JSONObject param, String channelName, Result result)
170178
}
171179
msg.setStatus(EMMessage.Status.CREATE);
172180
EMMessage finalMsg = msg;
181+
final String localId = finalMsg.getMsgId();
173182
finalMsg.setMessageStatusCallback(new EMWrapperCallBack(result, channelName, null) {
174183
@Override
175184
public void onSuccess() {
176185
post(() -> {
177186
Map<String, Object> map = new HashMap<>();
178187
map.put("message", EMMessageHelper.toJson(finalMsg));
179-
map.put("localTime", finalMsg.localTime());
188+
map.put("localId", localId);
180189
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
181190
});
182191
}
@@ -186,7 +195,7 @@ public void onProgress(int progress, String status) {
186195
post(() -> {
187196
Map<String, Object> map = new HashMap<>();
188197
map.put("progress", progress);
189-
map.put("localTime", finalMsg.localTime());
198+
map.put("localId", localId);
190199
messageChannel.invokeMethod(EMSDKMethod.onMessageProgressUpdate, map);
191200
});
192201
}
@@ -200,7 +209,7 @@ public void onError(int code, String desc) {
200209
post(() -> {
201210
Map<String, Object> map = new HashMap<>();
202211
map.put("message", EMMessageHelper.toJson(finalMsg));
203-
map.put("localTime", finalMsg.localTime());
212+
map.put("localId", localId);
204213
map.put("error", data);
205214
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
206215
});
@@ -327,6 +336,82 @@ private void getUnreadMessageCount(JSONObject param, String channelName, Result
327336
});
328337
}
329338

339+
private void getConversationsFromServerWithPage(JSONObject param, String channelName, Result result) throws JSONException {
340+
int pageNum = param.getInt("pageNum");
341+
int pageSize = param.getInt("pageSize");
342+
EMValueWrapperCallBack<Map<String, EMConversation>> callBack = new EMValueWrapperCallBack<Map<String, EMConversation>>(result,
343+
channelName) {
344+
@Override
345+
public void onSuccess(Map<String, EMConversation> object) {
346+
ArrayList<EMConversation>list = new ArrayList<>(object.values());
347+
asyncRunnable(() -> {
348+
boolean retry = false;
349+
List<Map> conversations = new ArrayList<>();
350+
do{
351+
try{
352+
retry = false;
353+
Collections.sort(list, new Comparator<EMConversation>() {
354+
@Override
355+
public int compare(EMConversation o1, EMConversation o2) {
356+
if (o1 == null && o2 == null) {
357+
return 0;
358+
}
359+
if (o1.getLastMessage() == null) {
360+
return 1;
361+
}
362+
363+
if (o2.getLastMessage() == null) {
364+
return -1;
365+
}
366+
367+
if (o1.getLastMessage().getMsgTime() == o2.getLastMessage().getMsgTime()) {
368+
return 0;
369+
}
370+
371+
return o2.getLastMessage().getMsgTime() - o1.getLastMessage().getMsgTime() > 0 ? 1 : -1;
372+
}
373+
});
374+
for (EMConversation conversation : list) {
375+
conversations.add(EMConversationHelper.toJson(conversation));
376+
}
377+
378+
}catch(IllegalArgumentException e) {
379+
retry = true;
380+
}
381+
}while (retry);
382+
updateObject(conversations);
383+
});
384+
}
385+
};
386+
EMClient.getInstance().chatManager().asyncFetchConversationsFromServer(pageNum, pageSize, callBack);
387+
}
388+
389+
private void removeMessagesFromServerWithMsgIds(JSONObject params, String channelName, Result result) throws JSONException {
390+
String conversationId = params.getString("convId");
391+
EMConversation.EMConversationType type = EMConversationHelper.typeFromInt(params.getInt("type"));
392+
EMConversation conversation = EMClient.getInstance().chatManager().getConversation(conversationId, type, true);
393+
394+
JSONArray jsonArray = params.getJSONArray("msgIds");
395+
396+
ArrayList<String> msgIds = new ArrayList<>();
397+
for (int i = 0; i < jsonArray.length(); i++) {
398+
msgIds.add((String) jsonArray.get(i));
399+
}
400+
401+
conversation.removeMessagesFromServer(msgIds, new EMWrapperCallBack(result, channelName, null));
402+
}
403+
404+
private void removeMessagesFromServerWithTs(JSONObject params, String channelName, Result result) throws JSONException {
405+
String conversationId = params.getString("convId");
406+
EMConversation.EMConversationType type = EMConversationHelper.typeFromInt(params.getInt("type"));
407+
EMConversation conversation = EMClient.getInstance().chatManager().getConversation(conversationId, type, true);
408+
long timestamp = 0;
409+
if(params.has("timestamp")) {
410+
timestamp = params.getLong("timestamp");
411+
}
412+
conversation.removeMessagesFromServer(timestamp, new EMWrapperCallBack(result, channelName, null));
413+
}
414+
330415
private void updateChatMessage(JSONObject param, String channelName, Result result) throws JSONException {
331416
EMMessage msg = EMMessageHelper.fromJson(param.getJSONObject("message"));
332417

android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private void fetchChatRoomMembers(JSONObject param, String channelName, MethodCh
296296
private void muteChatRoomMembers(JSONObject param, String channelName, MethodChannel.Result result)
297297
throws JSONException {
298298
String roomId = param.getString("roomId");
299-
long duration = Long.parseLong(param.getString("duration"));
299+
long duration = param.getLong("duration");
300300
JSONArray muteMembers = param.getJSONArray("muteMembers");
301301
List<String> muteMembersList = new ArrayList<>();
302302
for (int i = 0; i < muteMembers.length(); i++) {

android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
4545
getGroupWithId(param, call.method, result);
4646
} else if (EMSDKMethod.getJoinedGroups.equals(call.method)) {
4747
getJoinedGroups(param, call.method, result);
48-
} else if (EMSDKMethod.getGroupsWithoutPushNotification.equals(call.method)) {
49-
getGroupsWithoutPushNotification(param, call.method, result);
5048
} else if (EMSDKMethod.getJoinedGroupsFromServer.equals(call.method)) {
5149
getJoinedGroupsFromServer(param, call.method, result);
5250
} else if (EMSDKMethod.getPublicGroupsFromServer.equals(call.method)) {
@@ -159,14 +157,6 @@ private void getJoinedGroups(JSONObject param, String channelName, Result result
159157
onSuccess(result, channelName, groupList);
160158
}
161159

162-
private void getGroupsWithoutPushNotification(JSONObject param, String channelName, Result result)
163-
throws JSONException {
164-
asyncRunnable(() -> {
165-
List<String> groups = EMClient.getInstance().pushManager().getNoPushGroups();
166-
onSuccess(result, channelName, groups);
167-
});
168-
}
169-
170160
private void getJoinedGroupsFromServer(JSONObject param, String channelName, Result result) throws JSONException {
171161

172162
int pageSize = 0;

android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class EMMessageHelper {
324324

325325
static EMMessage fromJson(JSONObject json) throws JSONException {
326326
EMMessage message = null;
327+
327328
JSONObject bodyJson = json.getJSONObject("body");
328329
String type = bodyJson.getString("type");
329330
if (json.getString("direction").equals("send")) {
@@ -446,6 +447,16 @@ static EMMessage fromJson(JSONObject json) throws JSONException {
446447
}
447448

448449
message.setStatus(statusFromInt(json.getInt("status")));
450+
if (json.has("chatroomMessagePriority")) {
451+
int intPriority = json.getInt("chatroomMessagePriority");
452+
if (intPriority == 0) {
453+
message.setPriority(EMMessage.EMChatRoomMessagePriority.PriorityHigh);
454+
}else if (intPriority == 1) {
455+
message.setPriority(EMMessage.EMChatRoomMessagePriority.PriorityNormal);
456+
}else if (intPriority == 2) {
457+
message.setPriority(EMMessage.EMChatRoomMessagePriority.PriorityLow);
458+
}
459+
}
449460
message.setChatType(chatTypeFromInt(json.getInt("chatType")));
450461
if (json.has("msgId")){
451462
message.setMsgId(json.getString("msgId"));

android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public class EMSDKMethod {
8787
static final String fetchReactionList = "fetchReactionList";
8888
static final String fetchReactionDetail = "fetchReactionDetail";
8989
static final String reportMessage = "reportMessage";
90+
static final String fetchConversationsFromServerWithPage = "fetchConversationsFromServerWithPage";
91+
static final String removeMessagesFromServerWithMsgIds = "removeMessagesFromServerWithMsgIds";
92+
static final String removeMessagesFromServerWithTs = "removeMessagesFromServerWithTs";
9093

9194
/// EMChatManager listener
9295
static final String onMessagesReceived = "onMessagesReceived";
@@ -177,7 +180,6 @@ public class EMSDKMethod {
177180
/// EMGroupManager
178181
static final String getGroupWithId = "getGroupWithId";
179182
static final String getJoinedGroups = "getJoinedGroups";
180-
static final String getGroupsWithoutPushNotification = "getGroupsWithoutPushNotification";
181183
static final String getJoinedGroupsFromServer = "getJoinedGroupsFromServer";
182184
static final String getPublicGroupsFromServer = "getPublicGroupsFromServer";
183185
static final String createGroup = "createGroup";

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
2-
ext.kotlin_version = '1.5.30'
2+
ext.kotlin_version = '1.6.21'
33
repositories {
44
google()
55
mavenCentral()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:4.1.0'
9+
classpath 'com.android.tools.build:gradle:7.2.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

0 commit comments

Comments
 (0)