Skip to content

Commit

Permalink
Merge pull request #538 from easemob/dev_4.0.0
Browse files Browse the repository at this point in the history
Dev 4.0.0
  • Loading branch information
dujiepeng committed Feb 24, 2023
2 parents a8a50b2 + 46c1d44 commit c451ec8
Show file tree
Hide file tree
Showing 54 changed files with 826 additions and 671 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
## NEXT

## 4.0.0 Easemob IM Flutter 端发版说明

#### 新增特性

- 依赖的原生平台 `iOS``Android` 的 SDK 升级为 v4.0.0 版本。
- 新增 `EMChatManager#fetchConversationListFromServer` 方法实现从服务器分页获取会话列表。
- 新增 `EMMessage#chatroomMessagePriority` 属性实现聊天室消息优先级功能,确保高优先级消息优先处理。

#### 优化

修改发送消息结果的回调由 `EMMessage#setMessageStatusCallBack` 修改为 `EMChatManager#addMessageEvent`

#### 修复

修复 `EMChatManager#deleteMessagesBeforeTimestamp` 执行失败的问题。

# 3.9.9+1
修复:
Expand Down
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,7 @@ void _signIn() async {
targetId: _chatId,
content: _messageContent,
);
msg.setMessageStatusCallBack(MessageStatusCallBack(
onSuccess: () {
_addLogToConsole("send message succeed");
},
onError: (e) {
_addLogToConsole(
"send message failed, code: ${e.code}, desc: ${e.description}",
);
},
));
EMClient.getInstance.chatManager.sendMessage(msg);
}
```
Expand All @@ -341,6 +332,26 @@ void _signIn() async {

```dart
void _addChatListener() {
// 添加消息状态变更监听
EMClient.getInstance.chatManager.addMessageEvent(
// ChatMessageEvent 对应的 key。
"UNIQUE_HANDLER_ID",
ChatMessageEvent(
onSuccess: (msgId, msg) {
_addLogToConsole("send message succeed");
},
onProgress: (msgId, progress) {
_addLogToConsole("send message succeed");
},
onError: (msgId, msg, error) {
_addLogToConsole(
"send message failed, code: ${error.code}, desc: ${error.description}",
);
},
));
// 添加收消息监听
EMClient.getInstance.chatManager.addEventHandler(
// EMChatEventHandle 对应的 key。
"UNIQUE_HANDLER_ID",
Expand Down Expand Up @@ -400,7 +411,7 @@ void _addChatListener() {
break;
case MessageType.CMD:
{
// 当前回调中不会有 CMD 类型消息,CMD 类型消息通过 `EMChatEventHandler#onCmdMessagesReceived` 回调接收
// 当前回调中不会有 CMD 类型消息,CMD 类型消息通过 [EMChatEventHandler.onCmdMessagesReceived] 回调接收
}
break;
}
Expand All @@ -418,6 +429,7 @@ void _addChatListener() {
```dart
@override
void dispose() {
EMClient.getInstance.chatManager.removeMessageEvent("UNIQUE_HANDLER_ID");
EMClient.getInstance.chatManager.removeEventHandler("UNIQUE_HANDLER_ID");
super.dispose();
}
Expand Down
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
}

dependencies {
// classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.2.0'
}
}
Expand Down Expand Up @@ -49,5 +48,5 @@ tasks.withType(JavaCompile){

dependencies {
api 'androidx.appcompat:appcompat:1.1.0'
implementation 'io.hyphenate:hyphenate-chat:3.9.9'
implementation 'io.hyphenate:hyphenate-chat:4.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.hyphenate.EMConversationListener;
import com.hyphenate.EMMessageListener;
import com.hyphenate.EMValueCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.*;
import com.hyphenate.chat.EMConversation.EMSearchDirection;
Expand Down Expand Up @@ -110,6 +111,12 @@ public void onMethodCall(MethodCall call, Result result) {
fetchReactionDetail(param, call.method, result);
} else if (EMSDKMethod.reportMessage.equals(call.method)) {
reportMessage(param, call.method, result);
} else if (EMSDKMethod.fetchConversationsFromServerWithPage.equals(call.method)) {
getConversationsFromServerWithPage(param, call.method, result);
} else if (EMSDKMethod.removeMessagesFromServerWithMsgIds.equals(call.method)) {
removeMessagesFromServerWithMsgIds(param, call.method, result);
} else if (EMSDKMethod.removeMessagesFromServerWithTs.equals(call.method)) {
removeMessagesFromServerWithTs(param, call.method, result);
}
else {
super.onMethodCall(call, result);
Expand All @@ -121,13 +128,14 @@ public void onMethodCall(MethodCall call, Result result) {

private void sendMessage(JSONObject param, String channelName, Result result) throws JSONException {
final EMMessage msg = EMMessageHelper.fromJson(param);
final String localId = msg.getMsgId();
msg.setMessageStatusCallback(new EMWrapperCallBack(result, channelName, null) {
@Override
public void onSuccess() {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(msg));
map.put("localTime", msg.localTime());
map.put("localId", localId);
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
});
}
Expand All @@ -137,7 +145,7 @@ public void onProgress(int progress, String status) {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("progress", progress);
map.put("localTime", msg.localTime());
map.put("localId", localId);
messageChannel.invokeMethod(EMSDKMethod.onMessageProgressUpdate, map);
});
}
Expand All @@ -150,7 +158,7 @@ public void onError(int code, String desc) {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(msg));
map.put("localTime", msg.localTime());
map.put("localId", localId);
map.put("error", data);
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
});
Expand All @@ -170,13 +178,14 @@ private void resendMessage(JSONObject param, String channelName, Result result)
}
msg.setStatus(EMMessage.Status.CREATE);
EMMessage finalMsg = msg;
final String localId = finalMsg.getMsgId();
finalMsg.setMessageStatusCallback(new EMWrapperCallBack(result, channelName, null) {
@Override
public void onSuccess() {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(finalMsg));
map.put("localTime", finalMsg.localTime());
map.put("localId", localId);
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
});
}
Expand All @@ -186,7 +195,7 @@ public void onProgress(int progress, String status) {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("progress", progress);
map.put("localTime", finalMsg.localTime());
map.put("localId", localId);
messageChannel.invokeMethod(EMSDKMethod.onMessageProgressUpdate, map);
});
}
Expand All @@ -200,7 +209,7 @@ public void onError(int code, String desc) {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(finalMsg));
map.put("localTime", finalMsg.localTime());
map.put("localId", localId);
map.put("error", data);
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
});
Expand Down Expand Up @@ -327,6 +336,82 @@ private void getUnreadMessageCount(JSONObject param, String channelName, Result
});
}

private void getConversationsFromServerWithPage(JSONObject param, String channelName, Result result) throws JSONException {
int pageNum = param.getInt("pageNum");
int pageSize = param.getInt("pageSize");
EMValueWrapperCallBack<Map<String, EMConversation>> callBack = new EMValueWrapperCallBack<Map<String, EMConversation>>(result,
channelName) {
@Override
public void onSuccess(Map<String, EMConversation> object) {
ArrayList<EMConversation>list = new ArrayList<>(object.values());
asyncRunnable(() -> {
boolean retry = false;
List<Map> conversations = new ArrayList<>();
do{
try{
retry = false;
Collections.sort(list, new Comparator<EMConversation>() {
@Override
public int compare(EMConversation o1, EMConversation o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1.getLastMessage() == null) {
return 1;
}

if (o2.getLastMessage() == null) {
return -1;
}

if (o1.getLastMessage().getMsgTime() == o2.getLastMessage().getMsgTime()) {
return 0;
}

return o2.getLastMessage().getMsgTime() - o1.getLastMessage().getMsgTime() > 0 ? 1 : -1;
}
});
for (EMConversation conversation : list) {
conversations.add(EMConversationHelper.toJson(conversation));
}

}catch(IllegalArgumentException e) {
retry = true;
}
}while (retry);
updateObject(conversations);
});
}
};
EMClient.getInstance().chatManager().asyncFetchConversationsFromServer(pageNum, pageSize, callBack);
}

private void removeMessagesFromServerWithMsgIds(JSONObject params, String channelName, Result result) throws JSONException {
String conversationId = params.getString("convId");
EMConversation.EMConversationType type = EMConversationHelper.typeFromInt(params.getInt("type"));
EMConversation conversation = EMClient.getInstance().chatManager().getConversation(conversationId, type, true);

JSONArray jsonArray = params.getJSONArray("msgIds");

ArrayList<String> msgIds = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
msgIds.add((String) jsonArray.get(i));
}

conversation.removeMessagesFromServer(msgIds, new EMWrapperCallBack(result, channelName, null));
}

private void removeMessagesFromServerWithTs(JSONObject params, String channelName, Result result) throws JSONException {
String conversationId = params.getString("convId");
EMConversation.EMConversationType type = EMConversationHelper.typeFromInt(params.getInt("type"));
EMConversation conversation = EMClient.getInstance().chatManager().getConversation(conversationId, type, true);
long timestamp = 0;
if(params.has("timestamp")) {
timestamp = params.getLong("timestamp");
}
conversation.removeMessagesFromServer(timestamp, new EMWrapperCallBack(result, channelName, null));
}

private void updateChatMessage(JSONObject param, String channelName, Result result) throws JSONException {
EMMessage msg = EMMessageHelper.fromJson(param.getJSONObject("message"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void fetchChatRoomMembers(JSONObject param, String channelName, MethodCh
private void muteChatRoomMembers(JSONObject param, String channelName, MethodChannel.Result result)
throws JSONException {
String roomId = param.getString("roomId");
long duration = Long.parseLong(param.getString("duration"));
long duration = param.getLong("duration");
JSONArray muteMembers = param.getJSONArray("muteMembers");
List<String> muteMembersList = new ArrayList<>();
for (int i = 0; i < muteMembers.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
getGroupWithId(param, call.method, result);
} else if (EMSDKMethod.getJoinedGroups.equals(call.method)) {
getJoinedGroups(param, call.method, result);
} else if (EMSDKMethod.getGroupsWithoutPushNotification.equals(call.method)) {
getGroupsWithoutPushNotification(param, call.method, result);
} else if (EMSDKMethod.getJoinedGroupsFromServer.equals(call.method)) {
getJoinedGroupsFromServer(param, call.method, result);
} else if (EMSDKMethod.getPublicGroupsFromServer.equals(call.method)) {
Expand Down Expand Up @@ -159,14 +157,6 @@ private void getJoinedGroups(JSONObject param, String channelName, Result result
onSuccess(result, channelName, groupList);
}

private void getGroupsWithoutPushNotification(JSONObject param, String channelName, Result result)
throws JSONException {
asyncRunnable(() -> {
List<String> groups = EMClient.getInstance().pushManager().getNoPushGroups();
onSuccess(result, channelName, groups);
});
}

private void getJoinedGroupsFromServer(JSONObject param, String channelName, Result result) throws JSONException {

int pageSize = 0;
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class EMMessageHelper {

static EMMessage fromJson(JSONObject json) throws JSONException {
EMMessage message = null;

JSONObject bodyJson = json.getJSONObject("body");
String type = bodyJson.getString("type");
if (json.getString("direction").equals("send")) {
Expand Down Expand Up @@ -446,6 +447,16 @@ static EMMessage fromJson(JSONObject json) throws JSONException {
}

message.setStatus(statusFromInt(json.getInt("status")));
if (json.has("chatroomMessagePriority")) {
int intPriority = json.getInt("chatroomMessagePriority");
if (intPriority == 0) {
message.setPriority(EMMessage.EMChatRoomMessagePriority.PriorityHigh);
}else if (intPriority == 1) {
message.setPriority(EMMessage.EMChatRoomMessagePriority.PriorityNormal);
}else if (intPriority == 2) {
message.setPriority(EMMessage.EMChatRoomMessagePriority.PriorityLow);
}
}
message.setChatType(chatTypeFromInt(json.getInt("chatType")));
if (json.has("msgId")){
message.setMsgId(json.getString("msgId"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class EMSDKMethod {
static final String fetchReactionList = "fetchReactionList";
static final String fetchReactionDetail = "fetchReactionDetail";
static final String reportMessage = "reportMessage";
static final String fetchConversationsFromServerWithPage = "fetchConversationsFromServerWithPage";
static final String removeMessagesFromServerWithMsgIds = "removeMessagesFromServerWithMsgIds";
static final String removeMessagesFromServerWithTs = "removeMessagesFromServerWithTs";

/// EMChatManager listener
static final String onMessagesReceived = "onMessagesReceived";
Expand Down Expand Up @@ -177,7 +180,6 @@ public class EMSDKMethod {
/// EMGroupManager
static final String getGroupWithId = "getGroupWithId";
static final String getJoinedGroups = "getJoinedGroups";
static final String getGroupsWithoutPushNotification = "getGroupsWithoutPushNotification";
static final String getJoinedGroupsFromServer = "getJoinedGroupsFromServer";
static final String getPublicGroupsFromServer = "getPublicGroupsFromServer";
static final String createGroup = "createGroup";
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.5.30'
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
4 changes: 3 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -200,6 +200,7 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -214,6 +215,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
Loading

0 comments on commit c451ec8

Please sign in to comment.