Skip to content

Commit 847c2dd

Browse files
authored
Merge pull request #492 from easemob/flutter2_dev
Flutter2 dev
2 parents dd0fd89 + 9cc2b6f commit 847c2dd

23 files changed

+339
-108
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## NEXT
22

3-
## 3.8.3+7
3+
## 3.8.3+9
4+
5+
- 将设置推送相关操作从EMPushConfigs中移到EMPushManager中;
6+
7+
## 3.8.3+8
48

59
- 修复ios使用token登录失败;
610
- 修改Login方法和Logout方法返回值;

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Demo中使用的音视频是针对声网音视频封装的[EaseCallKit](https://
2929

3030
```dart
3131
dependencies:
32-
im_flutter_sdk: ^3.8.3+7
32+
im_flutter_sdk: ^3.8.3+9
3333
```
3434

3535
2. 执行`flutter pub get`;
@@ -1558,7 +1558,7 @@ try{
15581558

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

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

15791579
```dart
15801580
try{
1581-
await pushConfig.setPushStyle(EMImPushStyle.Simple);
1581+
await EMClient.getInstance.pushManager.updatePushDisplayStyle(DisplayStyle.Simple);
15821582
} on EMError catch(e) {
15831583
print('操作失败,原因是: $e');
15841584
}
15851585
```
15861586

1587-
> `EMImPushStyle`是收推送时样式,目前有两种样式:
1587+
> `DisplayStyle`是收推送时样式,目前有两种样式:
15881588
> `Simple`显示“您有一条新消息”;
15891589
> `Summary`显示推送详情;
15901590
15911591
#### 设置消息免打扰
15921592

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

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

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

16251625
```dart
16261626
try{
1627-
List groupIdsList = await pushConfig.noDisturbGroupsFromServer();
1627+
List<String> groupIdsList = await EMClient.getInstance.pushManager.getNoPushGroupsFromCache();
16281628
} on EMError catch(e) {
16291629
print('操作失败,原因是: $e');
16301630
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,8 @@ static EMImageMessageBody imageBodyFromJson(JSONObject json) throws JSONExceptio
732732
body.setThumbnailUrl(json.getString("thumbnailRemotePath"));
733733
body.setThumbnailSecret(json.getString("thumbnailSecret"));
734734
body.setFileLength(json.getInt("fileSize"));
735-
int width = json.getInt("height");
736-
int height = json.getInt("width");
735+
int width = json.getInt("width");
736+
int height = json.getInt("height");
737737
body.setThumbnailSize(width, height);
738738
body.setSendOriginalImage(json.getBoolean("sendOriginalImage"));
739739

@@ -770,8 +770,8 @@ static EMVideoMessageBody videoBodyFromJson(JSONObject json) throws JSONExceptio
770770
}
771771
body.setThumbnailSecret(json.getString("thumbnailSecret"));
772772
body.setFileName(json.getString("displayName"));
773-
int width = json.getInt("height");
774-
int height = json.getInt("width");
773+
int width = json.getInt("width");
774+
int height = json.getInt("height");
775775
body.setThumbnailSize(width, height);
776776
body.setRemoteUrl(json.getString("remotePath"));
777777
body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus")));

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

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.hyphenate.chat.EMPushManager.DisplayStyle;
99
import com.hyphenate.exceptions.HyphenateException;
1010

11+
import org.json.JSONArray;
1112
import org.json.JSONException;
1213
import org.json.JSONObject;
1314

@@ -58,6 +59,15 @@ else if(EMSDKMethod.updateHMSPushToken.equals(call.method)){
5859
else if(EMSDKMethod.updateFCMPushToken.equals(call.method)){
5960
updateFCMPushToken(param, call.method, result);
6061
}
62+
else if (EMSDKMethod.enableOfflinePush.equals(call.method)) {
63+
enableOfflinePush(param, call.method, result);
64+
}
65+
else if (EMSDKMethod.disableOfflinePush.equals(call.method)){
66+
disableOfflinePush(param, call.method, result);
67+
}
68+
else if (EMSDKMethod.getNoPushGroups.equals(call.method)) {
69+
getNoPushGroups(param, call.method, result);
70+
}
6171
else {
6272
super.onMethodCall(call, result);
6373
}
@@ -112,21 +122,57 @@ private void imPushNoDisturb(JSONObject params, String channelName, Result resu
112122
});
113123
}
114124

125+
private void enableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException
126+
{
127+
asyncRunnable(()-> {
128+
try {
129+
EMClient.getInstance().pushManager().enableOfflinePush();
130+
onSuccess(result, channelName, null);
131+
} catch(HyphenateException e) {
132+
onError(result, e);
133+
}
134+
});
135+
}
136+
137+
private void disableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException
138+
{
139+
int startTime = params.getInt("start");
140+
int endTime = params.getInt("end");
141+
asyncRunnable(()-> {
142+
try {
143+
EMClient.getInstance().pushManager().disableOfflinePush(startTime, endTime);
144+
onSuccess(result, channelName, null);
145+
} catch(HyphenateException e) {
146+
onError(result, e);
147+
}
148+
});
149+
}
150+
151+
private void getNoPushGroups(JSONObject params, String channelName, Result result) {
152+
asyncRunnable(()-> {
153+
List<String> groups = EMClient.getInstance().pushManager().getNoPushGroups();
154+
onSuccess(result, channelName, groups);
155+
});
156+
157+
}
158+
115159
private void updateImPushStyle(JSONObject params, String channelName, Result result) throws JSONException {
116160
DisplayStyle style = params.getInt("pushStyle") == 0 ? DisplayStyle.SimpleBanner : DisplayStyle.MessageSummary;
117161
EMClient.getInstance().pushManager().asyncUpdatePushDisplayStyle(style, new EMWrapperCallBack(result, channelName, true));
118162
}
119163

120164
private void updateGroupPushService(JSONObject params, String channelName, Result result) throws JSONException {
121-
String groupId = params.getString("group_id");
122-
boolean enablePush = params.getBoolean("noDisturb");
165+
JSONArray groupIds = params.getJSONArray("group_ids");
166+
boolean noPush = params.getBoolean("noPush");
123167
List<String> groupList = new ArrayList<>();
124-
groupList.add(groupId);
168+
for (int i = 0; i < groupIds.length(); i++) {
169+
String groupId = groupIds.getString(i);
170+
groupList.add(groupId);
171+
}
125172
asyncRunnable(()-> {
126173
try {
127-
EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, !enablePush);
128-
EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId);
129-
onSuccess(result, channelName, EMGroupHelper.toJson(group));
174+
EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, noPush);
175+
onSuccess(result, channelName, null);
130176
} catch(HyphenateException e) {
131177
onError(result, e);
132178
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ public class EMSDKMethod {
200200
static final String updatePushNickname = "updatePushNickname";
201201
static final String updateHMSPushToken = "updateHMSPushToken";
202202
static final String updateFCMPushToken = "updateFCMPushToken";
203+
static final String enableOfflinePush = "enableOfflinePush";
204+
static final String disableOfflinePush = "disableOfflinePush";
205+
static final String getNoPushGroups = "getNoPushGroups";
203206

204207
/// ImPushConfig
205208
static final String imPushNoDisturb = "imPushNoDisturb";

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 29
29+
compileSdkVersion 31
3030

3131
sourceSets {
3232
main.java.srcDirs += 'src/main/kotlin'

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
additional functionality it is fine to subclass or reimplement
77
FlutterApplication and put your custom class here. -->
88
<application
9-
android:name="io.flutter.app.FlutterApplication"
9+
android:name="${applicationName}"
1010
android:label="easeim_flutter_demo"
1111
android:theme="@style/NormalTheme"
1212
android:icon="@mipmap/ic_launcher" android:usesCleartextTraffic="true">

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.50'
2+
ext.kotlin_version = '1.5.31'
33
repositories {
44
google()
55
mavenCentral()

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void initSDK() async {
3030
var options = EMOptions(appKey: 'easemob-demo#easeim');
3131
options.deleteMessagesAsExitGroup = false;
3232
options.deleteMessagesAsExitChatRoom = false;
33+
options.autoAcceptGroupInvitation = true;
3334
options.debugModel = true;
3435
options.enableAPNs("EaseIM_APNS_Product");
3536

example/lib/pages/contacts/contacts_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class ContactsPageState extends State<ContactsPage>
249249
_contactList.addAll(list);
250250
}
251251
} on EMError {
252+
_contactList.clear();
252253
SmartDialog.showToast('获取失败');
253254
_loadLocalContacts(count);
254255
} finally {

0 commit comments

Comments
 (0)