|
8 | 8 | import com.hyphenate.chat.EMPushManager.DisplayStyle; |
9 | 9 | import com.hyphenate.exceptions.HyphenateException; |
10 | 10 |
|
| 11 | +import org.json.JSONArray; |
11 | 12 | import org.json.JSONException; |
12 | 13 | import org.json.JSONObject; |
13 | 14 |
|
@@ -58,6 +59,15 @@ else if(EMSDKMethod.updateHMSPushToken.equals(call.method)){ |
58 | 59 | else if(EMSDKMethod.updateFCMPushToken.equals(call.method)){ |
59 | 60 | updateFCMPushToken(param, call.method, result); |
60 | 61 | } |
| 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 | + } |
61 | 71 | else { |
62 | 72 | super.onMethodCall(call, result); |
63 | 73 | } |
@@ -112,21 +122,57 @@ private void imPushNoDisturb(JSONObject params, String channelName, Result resu |
112 | 122 | }); |
113 | 123 | } |
114 | 124 |
|
| 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 | + |
115 | 159 | private void updateImPushStyle(JSONObject params, String channelName, Result result) throws JSONException { |
116 | 160 | DisplayStyle style = params.getInt("pushStyle") == 0 ? DisplayStyle.SimpleBanner : DisplayStyle.MessageSummary; |
117 | 161 | EMClient.getInstance().pushManager().asyncUpdatePushDisplayStyle(style, new EMWrapperCallBack(result, channelName, true)); |
118 | 162 | } |
119 | 163 |
|
120 | 164 | 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"); |
123 | 167 | 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 | + } |
125 | 172 | asyncRunnable(()-> { |
126 | 173 | 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); |
130 | 176 | } catch(HyphenateException e) { |
131 | 177 | onError(result, e); |
132 | 178 | } |
|
0 commit comments