Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## NEXT

## 3.8.3+7
## 3.8.3+9

- 将设置推送相关操作从EMPushConfigs中移到EMPushManager中;

## 3.8.3+8

- 修复ios使用token登录失败;
- 修改Login方法和Logout方法返回值;
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Demo中使用的音视频是针对声网音视频封装的[EaseCallKit](https://

```dart
dependencies:
im_flutter_sdk: ^3.8.3+7
im_flutter_sdk: ^3.8.3+9
```

2. 执行`flutter pub get`;
Expand Down Expand Up @@ -1558,7 +1558,7 @@ try{

```dart
try{
EMImPushConfig pushManager = await EMClient.getInstance.pushManager.getImPushConfigFromServer();
EMPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromServer();
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
Expand All @@ -1568,7 +1568,7 @@ try{

```dart
try{
EMImPushConfig pushConfig = await EMClient.getInstance.pushManager.getImPushConfig();
EMPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromCache();
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
Expand All @@ -1578,21 +1578,21 @@ try{

```dart
try{
await pushConfig.setPushStyle(EMImPushStyle.Simple);
await EMClient.getInstance.pushManager.updatePushDisplayStyle(DisplayStyle.Simple);
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
```

> `EMImPushStyle`是收推送时样式,目前有两种样式:
> `DisplayStyle`是收推送时样式,目前有两种样式:
> `Simple`显示“您有一条新消息”;
> `Summary`显示推送详情;

#### 设置消息免打扰

```dart
try{
await pushConfig.setNoDisturb(true, 10, 22);
await EMClient.getInstance.pushManager.disableOfflinePush(10, 22);
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
Expand All @@ -1604,7 +1604,7 @@ try{

```dart
try{
await pushConfig.setNoDisturb(false);
await EMClient.getInstance.pushManager.enableOfflinePush();
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
Expand All @@ -1614,7 +1614,7 @@ try{

```dart
try{
await pushConfig.setGroupToDisturb(groupId, true);
await EMClient.getInstance.pushManager.updatePushServiceForGroup(groupId, false);
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
Expand All @@ -1624,7 +1624,7 @@ try{

```dart
try{
List groupIdsList = await pushConfig.noDisturbGroupsFromServer();
List<String> groupIdsList = await EMClient.getInstance.pushManager.getNoPushGroupsFromCache();
} on EMError catch(e) {
print('操作失败,原因是: $e');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ static EMImageMessageBody imageBodyFromJson(JSONObject json) throws JSONExceptio
body.setThumbnailUrl(json.getString("thumbnailRemotePath"));
body.setThumbnailSecret(json.getString("thumbnailSecret"));
body.setFileLength(json.getInt("fileSize"));
int width = json.getInt("height");
int height = json.getInt("width");
int width = json.getInt("width");
int height = json.getInt("height");
body.setThumbnailSize(width, height);
body.setSendOriginalImage(json.getBoolean("sendOriginalImage"));

Expand Down Expand Up @@ -770,8 +770,8 @@ static EMVideoMessageBody videoBodyFromJson(JSONObject json) throws JSONExceptio
}
body.setThumbnailSecret(json.getString("thumbnailSecret"));
body.setFileName(json.getString("displayName"));
int width = json.getInt("height");
int height = json.getInt("width");
int width = json.getInt("width");
int height = json.getInt("height");
body.setThumbnailSize(width, height);
body.setRemoteUrl(json.getString("remotePath"));
body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.hyphenate.chat.EMPushManager.DisplayStyle;
import com.hyphenate.exceptions.HyphenateException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -58,6 +59,15 @@ else if(EMSDKMethod.updateHMSPushToken.equals(call.method)){
else if(EMSDKMethod.updateFCMPushToken.equals(call.method)){
updateFCMPushToken(param, call.method, result);
}
else if (EMSDKMethod.enableOfflinePush.equals(call.method)) {
enableOfflinePush(param, call.method, result);
}
else if (EMSDKMethod.disableOfflinePush.equals(call.method)){
disableOfflinePush(param, call.method, result);
}
else if (EMSDKMethod.getNoPushGroups.equals(call.method)) {
getNoPushGroups(param, call.method, result);
}
else {
super.onMethodCall(call, result);
}
Expand Down Expand Up @@ -112,21 +122,57 @@ private void imPushNoDisturb(JSONObject params, String channelName, Result resu
});
}

private void enableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException
{
asyncRunnable(()-> {
try {
EMClient.getInstance().pushManager().enableOfflinePush();
onSuccess(result, channelName, null);
} catch(HyphenateException e) {
onError(result, e);
}
});
}

private void disableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException
{
int startTime = params.getInt("start");
int endTime = params.getInt("end");
asyncRunnable(()-> {
try {
EMClient.getInstance().pushManager().disableOfflinePush(startTime, endTime);
onSuccess(result, channelName, null);
} catch(HyphenateException e) {
onError(result, e);
}
});
}

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

}

private void updateImPushStyle(JSONObject params, String channelName, Result result) throws JSONException {
DisplayStyle style = params.getInt("pushStyle") == 0 ? DisplayStyle.SimpleBanner : DisplayStyle.MessageSummary;
EMClient.getInstance().pushManager().asyncUpdatePushDisplayStyle(style, new EMWrapperCallBack(result, channelName, true));
}

private void updateGroupPushService(JSONObject params, String channelName, Result result) throws JSONException {
String groupId = params.getString("group_id");
boolean enablePush = params.getBoolean("noDisturb");
JSONArray groupIds = params.getJSONArray("group_ids");
boolean noPush = params.getBoolean("noPush");
List<String> groupList = new ArrayList<>();
groupList.add(groupId);
for (int i = 0; i < groupIds.length(); i++) {
String groupId = groupIds.getString(i);
groupList.add(groupId);
}
asyncRunnable(()-> {
try {
EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, !enablePush);
EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId);
onSuccess(result, channelName, EMGroupHelper.toJson(group));
EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, noPush);
onSuccess(result, channelName, null);
} catch(HyphenateException e) {
onError(result, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ public class EMSDKMethod {
static final String updatePushNickname = "updatePushNickname";
static final String updateHMSPushToken = "updateHMSPushToken";
static final String updateFCMPushToken = "updateFCMPushToken";
static final String enableOfflinePush = "enableOfflinePush";
static final String disableOfflinePush = "disableOfflinePush";
static final String getNoPushGroups = "getNoPushGroups";

/// ImPushConfig
static final String imPushNoDisturb = "imPushNoDisturb";
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="easeim_flutter_demo"
android:theme="@style/NormalTheme"
android:icon="@mipmap/ic_launcher" android:usesCleartextTraffic="true">
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.31'
repositories {
google()
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void initSDK() async {
var options = EMOptions(appKey: 'easemob-demo#easeim');
options.deleteMessagesAsExitGroup = false;
options.deleteMessagesAsExitChatRoom = false;
options.autoAcceptGroupInvitation = true;
options.debugModel = true;
options.enableAPNs("EaseIM_APNS_Product");

Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/contacts/contacts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class ContactsPageState extends State<ContactsPage>
_contactList.addAll(list);
}
} on EMError {
_contactList.clear();
SmartDialog.showToast('获取失败');
_loadLocalContacts(count);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions ios/Classes/EMChatManagerWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call
channelName:call.method
result:result];
} else if ([EMMethodKeyAckGroupMessageRead isEqualToString:call.method]) {
[self ackMessageRead:call.arguments
channelName:call.method
result:result];
[self ackGroupMessageRead:call.arguments
channelName:call.method
result:result];
} else if ([EMMethodKeyAckConversationRead isEqualToString:call.method]) {
[self ackConversationRead:call.arguments
channelName:call.method
Expand Down
3 changes: 1 addition & 2 deletions ios/Classes/EMClientWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result:
password:pwdOrToken
completion:^(NSString *aUsername, EMError *aError)
{

[weakSelf wrapperCallBack:result
channelName:aChannelName
error:aError
Expand All @@ -241,7 +240,7 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result:
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:aError
object:EMClient.sharedClient.accessUserToken];
object:EMClient.sharedClient.currentUsername];
}];
}
}
Expand Down
70 changes: 64 additions & 6 deletions ios/Classes/EMPushManagerWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ - (void)handleMethodCall:(FlutterMethodCall*)call
[self bindDeviceToken:call.arguments
channelName:call.method
result:result];
} else if ([EMMethodKeyEnablePush isEqualToString:call.method]) {
[self enablePush:call.arguments
channelName:call.method
result:result];
} else if ([EMMethodKeyDisablePush isEqualToString:call.method]) {
[self disablePush:call.arguments
channelName:call.method
result:result];
} else if ([EMMethodKeyGetNoPushGroups isEqualToString:call.method]) {
[self getNoPushGroups:call.arguments
channelName:call.method
result:result];
}
else{
[super handleMethodCall:call result:result];
Expand Down Expand Up @@ -153,18 +165,17 @@ - (void)updateGroupPushService:(NSDictionary *)param
channelName:(NSString *)aChannelName
result:(FlutterResult)result {
__weak typeof(self) weakSelf = self;
NSString *groupId = param[@"group_id"];
bool enablePush = [param[@"enablePush"] boolValue];
NSArray *groupIds = param[@"group_ids"];
bool noPush = [param[@"noPush"] boolValue];

[EMClient.sharedClient.pushManager updatePushServiceForGroups:@[groupId]
disablePush:!enablePush
[EMClient.sharedClient.pushManager updatePushServiceForGroups:groupIds
disablePush:noPush
completion:^(EMError * _Nonnull aError)
{
EMGroup *aGroup = [EMGroup groupWithId:groupId];
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:aError
object:[aGroup toJson]];
object:nil];
}];
}

Expand Down Expand Up @@ -202,4 +213,51 @@ - (void)bindDeviceToken:(NSDictionary *)param
}


- (void)enablePush:(NSDictionary *)param
channelName:(NSString *)aChannelName
result:(FlutterResult)result {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
EMError *error = [EMClient.sharedClient.pushManager enableOfflinePush];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:error
object:nil];
});
});
}

- (void)disablePush:(NSDictionary *)param
channelName:(NSString *)aChannelName
result:(FlutterResult)result {
int startTime = [param[@"start"] intValue];
int endTime = [param[@"end"] intValue];
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
EMError *error = [EMClient.sharedClient.pushManager disableOfflinePushStart:startTime end:endTime];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:error
object:nil];
});
});
}

- (void)getNoPushGroups:(NSDictionary *)param
channelName:(NSString *)aChannelName
result:(FlutterResult)result {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSArray<NSString *>* groups = [EMClient.sharedClient.pushManager noPushGroups];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:nil
object:groups];
});
});
}

@end
7 changes: 6 additions & 1 deletion ios/Classes/EMSDKMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,17 @@ static NSString *const EMMethodKeyOnGroupChanged = @"onGroupChanged";
static NSString *const EMMethodKeyGetImPushConfig = @"getImPushConfig";
static NSString *const EMMethodKeyGetImPushConfigFromServer = @"getImPushConfigFromServer";
static NSString *const EMMethodKeyUpdatePushNickname = @"updatePushNickname";
static NSString *const EMMethodKeyBindDeviceToken = @"updateAPNsPushToken";
static NSString *const EMMethodKeyEnablePush = @"enableOfflinePush";
static NSString *const EMMethodKeyDisablePush = @"disableOfflinePush";
static NSString *const EMMethodKeyGetNoPushGroups = @"getNoPushGroups";


static NSString *const EMMethodKeyImPushNoDisturb = @"imPushNoDisturb";
static NSString *const EMMethodKeyUpdateImPushStyle = @"updateImPushStyle";
static NSString *const EMMethodKeyUpdateGroupPushService = @"updateGroupPushService";
static NSString *const EMMethodKeyGetNoDisturbGroups = @"getNoDisturbGroups";
static NSString *const EMMethodKeyBindDeviceToken = @"updateAPNsPushToken";



#pragma mark - EMUserInfoManagerWrapper
Expand Down
Loading