|
16 | 16 | import com.facebook.react.bridge.ReactMethod; |
17 | 17 | import com.facebook.react.bridge.ReadableArray; |
18 | 18 | import com.facebook.react.bridge.ReadableMap; |
| 19 | +import com.facebook.react.bridge.ReadableMapKeySetIterator; |
19 | 20 | import com.facebook.react.bridge.WritableArray; |
20 | 21 | import com.facebook.react.bridge.WritableMap; |
21 | 22 | import com.facebook.react.modules.core.DeviceEventManagerModule; |
| 23 | +import com.google.gson.jpush.JsonObject; |
22 | 24 |
|
23 | 25 | import java.io.File; |
24 | 26 | import java.io.FileNotFoundException; |
|
34 | 36 | import cn.jpush.im.android.api.callback.GetBlacklistCallback; |
35 | 37 | import cn.jpush.im.android.api.callback.GetGroupIDListCallback; |
36 | 38 | import cn.jpush.im.android.api.callback.GetGroupInfoCallback; |
| 39 | +import cn.jpush.im.android.api.callback.GetGroupInfoListCallback; |
37 | 40 | import cn.jpush.im.android.api.callback.GetGroupMembersCallback; |
38 | 41 | import cn.jpush.im.android.api.callback.GetNoDisurbListCallback; |
39 | 42 | import cn.jpush.im.android.api.callback.GetUserInfoCallback; |
@@ -269,6 +272,14 @@ public void updateMyInfo(ReadableMap map, final Callback success, final Callback |
269 | 272 | if (map.hasKey(Constant.ADDRESS)) { |
270 | 273 | myInfo.setAddress(map.getString(Constant.ADDRESS)); |
271 | 274 | } |
| 275 | + if (map.hasKey(Constant.EXTRAS)) { |
| 276 | + ReadableMap extras = map.getMap(Constant.EXTRAS); |
| 277 | + ReadableMapKeySetIterator iterator = extras.keySetIterator(); |
| 278 | + while (iterator.hasNextKey()) { |
| 279 | + String key = iterator.nextKey(); |
| 280 | + myInfo.setUserExtras(key, extras.getString(key)); |
| 281 | + } |
| 282 | + } |
272 | 283 | JMessageClient.updateMyInfo(UserInfo.Field.all, myInfo, new BasicCallback() { |
273 | 284 | @Override |
274 | 285 | public void gotResult(int status, String desc) { |
@@ -632,7 +643,7 @@ public void createGroup(ReadableMap map, final Callback success, final Callback |
632 | 643 | JMessageClient.createGroup(name, desc, new CreateGroupCallback() { |
633 | 644 | @Override |
634 | 645 | public void gotResult(int status, String desc, long groupId) { |
635 | | - mJMessageUtils.handleCallbackWithValue(status, desc, success, fail,String.valueOf(groupId)); |
| 646 | + mJMessageUtils.handleCallbackWithValue(status, desc, success, fail, String.valueOf(groupId)); |
636 | 647 | } |
637 | 648 | }); |
638 | 649 | } catch (Exception e) { |
@@ -803,7 +814,7 @@ public void addUsersToBlacklist(ReadableMap map, final Callback success, final C |
803 | 814 | JMessageClient.addUsersToBlacklist(usernameList, appKey, new BasicCallback() { |
804 | 815 | @Override |
805 | 816 | public void gotResult(int status, String desc) { |
806 | | - mJMessageUtils.handleCallback(status, desc, success,fail); |
| 817 | + mJMessageUtils.handleCallback(status, desc, success, fail); |
807 | 818 | } |
808 | 819 | }); |
809 | 820 | } catch (Exception e) { |
@@ -953,14 +964,10 @@ public void gotResult(int status, String desc, UserInfo userInfo) { |
953 | 964 | public void gotResult(int status, String desc, Bitmap bitmap) { |
954 | 965 | if (status == 0) { |
955 | 966 | String packageName = mContext.getPackageName(); |
956 | | - String fileName = username + appKey; |
957 | | - String filePath = mJMessageUtils.getAvatarPath(packageName); |
958 | | - File avatarFile = new File(filePath + fileName + ".png"); |
959 | | - if (!avatarFile.exists()) { |
960 | | - mJMessageUtils.storeImage(bitmap, fileName, packageName); |
961 | | - } |
| 967 | + String fileName = username + appKey + "original"; |
| 968 | + String path = mJMessageUtils.storeImage(bitmap, fileName, packageName); |
962 | 969 | WritableMap result = Arguments.createMap(); |
963 | | - result.putString(Constant.FILE_PATH, filePath); |
| 970 | + result.putString(Constant.FILE_PATH, path); |
964 | 971 | mJMessageUtils.handleCallbackWithObject(status, desc, success, fail, result); |
965 | 972 | } else { |
966 | 973 | mJMessageUtils.handleError(fail, status, desc); |
@@ -1213,6 +1220,233 @@ public void gotResult(int status, String desc, UserInfo userInfo) { |
1213 | 1220 | } |
1214 | 1221 | } |
1215 | 1222 |
|
| 1223 | + @ReactMethod |
| 1224 | + public void isGroupBlocked(ReadableMap map, final Callback success, final Callback fail) { |
| 1225 | + try { |
| 1226 | + String groupId = map.getString(Constant.GROUP_ID); |
| 1227 | + JMessageClient.getGroupInfo(Long.parseLong(groupId), new GetGroupInfoCallback() { |
| 1228 | + @Override |
| 1229 | + public void gotResult(int status, String desc, GroupInfo groupInfo) { |
| 1230 | + if (status == 0) { |
| 1231 | + boolean isBlocked = groupInfo.isGroupBlocked() == 1; |
| 1232 | + WritableMap result = Arguments.createMap(); |
| 1233 | + result.putBoolean(Constant.IS_BLOCKED, isBlocked); |
| 1234 | + mJMessageUtils.handleCallbackWithObject(status, desc, success, fail, result); |
| 1235 | + } else { |
| 1236 | + mJMessageUtils.handleError(fail, status, desc); |
| 1237 | + } |
| 1238 | + } |
| 1239 | + }); |
| 1240 | + } catch (Exception e) { |
| 1241 | + e.printStackTrace(); |
| 1242 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER); |
| 1243 | + } |
| 1244 | + } |
| 1245 | + |
| 1246 | + @ReactMethod |
| 1247 | + public void getBlockedGroupList(final Callback success, final Callback fail) { |
| 1248 | + JMessageClient.getBlockedGroupsList(new GetGroupInfoListCallback() { |
| 1249 | + @Override |
| 1250 | + public void gotResult(int status, String desc, List<GroupInfo> list) { |
| 1251 | + if (status == 0) { |
| 1252 | + WritableArray array = Arguments.createArray(); |
| 1253 | + for (GroupInfo groupInfo : list) { |
| 1254 | + array.pushMap(ResultUtils.toJSObject(groupInfo)); |
| 1255 | + } |
| 1256 | + mJMessageUtils.handleCallbackWithArray(status, desc, success, fail, array); |
| 1257 | + } else { |
| 1258 | + mJMessageUtils.handleError(fail, status, desc); |
| 1259 | + } |
| 1260 | + } |
| 1261 | + }); |
| 1262 | + } |
| 1263 | + |
| 1264 | + @ReactMethod |
| 1265 | + public void updateGroupAvatar(final ReadableMap map, final Callback success, final Callback fail) { |
| 1266 | + try { |
| 1267 | + String groupId = map.getString(Constant.GROUP_ID); |
| 1268 | + JMessageClient.getGroupInfo(Long.parseLong(groupId), new GetGroupInfoCallback() { |
| 1269 | + @Override |
| 1270 | + public void gotResult(int status, String desc, GroupInfo groupInfo) { |
| 1271 | + if (status == 0) { |
| 1272 | + String path = map.getString("imgPath"); |
| 1273 | + String format = path.substring(path.lastIndexOf(".") + 1); |
| 1274 | + File file = new File(path); |
| 1275 | + if (file.exists()) { |
| 1276 | + groupInfo.updateAvatar(file, format, new BasicCallback() { |
| 1277 | + @Override |
| 1278 | + public void gotResult(int status, String desc) { |
| 1279 | + mJMessageUtils.handleCallback(status, desc, success, fail); |
| 1280 | + } |
| 1281 | + }); |
| 1282 | + } else { |
| 1283 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, "File is not exist!"); |
| 1284 | + } |
| 1285 | + } else { |
| 1286 | + mJMessageUtils.handleError(fail, status, desc); |
| 1287 | + } |
| 1288 | + } |
| 1289 | + }); |
| 1290 | + } catch (Exception e) { |
| 1291 | + e.printStackTrace(); |
| 1292 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER); |
| 1293 | + } |
| 1294 | + } |
| 1295 | + |
| 1296 | + @ReactMethod |
| 1297 | + public void downloadThumbGroupAvatar(ReadableMap map, final Callback success, final Callback fail) { |
| 1298 | + try { |
| 1299 | + final String groupId = map.getString(Constant.GROUP_ID); |
| 1300 | + JMessageClient.getGroupInfo(Long.parseLong(groupId), new GetGroupInfoCallback() { |
| 1301 | + @Override |
| 1302 | + public void gotResult(int status, String desc, final GroupInfo groupInfo) { |
| 1303 | + if (status == 0) { |
| 1304 | + if (groupInfo.getAvatar() != null) { |
| 1305 | + File file = groupInfo.getAvatarFile(); |
| 1306 | + final WritableMap result = Arguments.createMap(); |
| 1307 | + result.putString(Constant.ID, groupId); |
| 1308 | + if (file.exists()) { |
| 1309 | + result.putString(Constant.FILE_PATH, file.getAbsolutePath()); |
| 1310 | + mJMessageUtils.handleCallbackWithObject(status, desc, success, fail, result); |
| 1311 | + } else { |
| 1312 | + groupInfo.getAvatarBitmap(new GetAvatarBitmapCallback() { |
| 1313 | + @Override |
| 1314 | + public void gotResult(int status, String desc, Bitmap bitmap) { |
| 1315 | + if (status == 0) { |
| 1316 | + String fileName = groupId + groupInfo.getGroupName(); |
| 1317 | + String path = mJMessageUtils.storeImage(bitmap, fileName, |
| 1318 | + mContext.getPackageName()); |
| 1319 | + result.putString(Constant.FILE_PATH, path); |
| 1320 | + } else { |
| 1321 | + mJMessageUtils.handleError(fail, status, desc); |
| 1322 | + } |
| 1323 | + } |
| 1324 | + }); |
| 1325 | + } |
| 1326 | + } |
| 1327 | + } else { |
| 1328 | + mJMessageUtils.handleError(fail, status, desc); |
| 1329 | + } |
| 1330 | + } |
| 1331 | + }); |
| 1332 | + } catch (Exception e) { |
| 1333 | + e.printStackTrace(); |
| 1334 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER); |
| 1335 | + } |
| 1336 | + } |
| 1337 | + |
| 1338 | + @ReactMethod |
| 1339 | + public void downloadOriginalGroupAvatar(ReadableMap map, final Callback success, final Callback fail) { |
| 1340 | + try { |
| 1341 | + final String groupId = map.getString(Constant.GROUP_ID); |
| 1342 | + JMessageClient.getGroupInfo(Long.parseLong(groupId), new GetGroupInfoCallback() { |
| 1343 | + @Override |
| 1344 | + public void gotResult(int status, String desc, final GroupInfo groupInfo) { |
| 1345 | + if (status == 0) { |
| 1346 | + if (groupInfo.getAvatar() != null) { |
| 1347 | + File file = groupInfo.getBigAvatarFile(); |
| 1348 | + final WritableMap result = Arguments.createMap(); |
| 1349 | + result.putString(Constant.ID, groupId); |
| 1350 | + if (file.exists()) { |
| 1351 | + result.putString(Constant.FILE_PATH, file.getAbsolutePath()); |
| 1352 | + mJMessageUtils.handleCallbackWithObject(status, desc, success, fail, result); |
| 1353 | + } else { |
| 1354 | + groupInfo.getBigAvatarBitmap(new GetAvatarBitmapCallback() { |
| 1355 | + @Override |
| 1356 | + public void gotResult(int status, String desc, Bitmap bitmap) { |
| 1357 | + if (status == 0) { |
| 1358 | + String fileName = groupId + groupInfo.getGroupName() + "original"; |
| 1359 | + String path = mJMessageUtils.storeImage(bitmap, fileName, |
| 1360 | + mContext.getPackageName()); |
| 1361 | + result.putString(Constant.FILE_PATH, path); |
| 1362 | + } else { |
| 1363 | + mJMessageUtils.handleError(fail, status, desc); |
| 1364 | + } |
| 1365 | + } |
| 1366 | + }); |
| 1367 | + } |
| 1368 | + } |
| 1369 | + } |
| 1370 | + } |
| 1371 | + }); |
| 1372 | + } catch (Exception e) { |
| 1373 | + e.printStackTrace(); |
| 1374 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER); |
| 1375 | + } |
| 1376 | + } |
| 1377 | + |
| 1378 | + @ReactMethod |
| 1379 | + public void setConversationExtras(ReadableMap map, Callback success, Callback fail) { |
| 1380 | + try { |
| 1381 | + Conversation conversation = mJMessageUtils.getConversation(map); |
| 1382 | + ReadableMap extraMap = map.getMap(Constant.EXTRAS); |
| 1383 | + ReadableMapKeySetIterator iterator = extraMap.keySetIterator(); |
| 1384 | + JsonObject jsonObject = new JsonObject(); |
| 1385 | + while(iterator.hasNextKey()) { |
| 1386 | + String key = iterator.nextKey(); |
| 1387 | + jsonObject.addProperty(key, extraMap.getString(key)); |
| 1388 | + } |
| 1389 | + conversation.updateConversationExtra(jsonObject.toString()); |
| 1390 | + Log.e("JMessageModule", "extra : " + jsonObject.toString()); |
| 1391 | + WritableMap result = ResultUtils.toJSObject(conversation); |
| 1392 | + mJMessageUtils.handleCallbackWithObject(0, "Set extra succeed", success, fail, result); |
| 1393 | + } catch (Exception e) { |
| 1394 | + e.printStackTrace(); |
| 1395 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER); |
| 1396 | + } |
| 1397 | + } |
| 1398 | + |
| 1399 | + @ReactMethod |
| 1400 | + public void forwardMessage(ReadableMap map, final Callback success, final Callback fail) { |
| 1401 | + try { |
| 1402 | + Conversation conversation = mJMessageUtils.getConversation(map); |
| 1403 | + if (conversation != null) { |
| 1404 | + Message message = conversation.getMessage(Integer.parseInt(map.getString(Constant.ID))); |
| 1405 | + MessageSendingOptions options = null; |
| 1406 | + if (map.hasKey(Constant.SENDING_OPTIONS)) { |
| 1407 | + options = new MessageSendingOptions(); |
| 1408 | + ReadableMap optionMap = map.getMap(Constant.SENDING_OPTIONS); |
| 1409 | + options.setShowNotification(optionMap.getBoolean("isShowNotification")); |
| 1410 | + options.setRetainOffline(optionMap.getBoolean("isRetainOffline")); |
| 1411 | + |
| 1412 | + if (optionMap.hasKey("isCustomNotificationEnabled")) { |
| 1413 | + options.setCustomNotificationEnabled( |
| 1414 | + optionMap.getBoolean("isCustomNotificationEnabled")); |
| 1415 | + } |
| 1416 | + if (optionMap.hasKey("notificationTitle")) { |
| 1417 | + options.setNotificationText(optionMap.getString("notificationTitle")); |
| 1418 | + } |
| 1419 | + if (optionMap.hasKey("notificationText")) { |
| 1420 | + options.setNotificationText(optionMap.getString("notificationText")); |
| 1421 | + } |
| 1422 | + } |
| 1423 | + ReadableMap target = map.getMap(Constant.TARGET); |
| 1424 | + String type = target.getString(Constant.TYPE); |
| 1425 | + Conversation targetConversation = null; |
| 1426 | + if (type.equals(Constant.TYPE_USER)) { |
| 1427 | + String username = map.getString(Constant.USERNAME); |
| 1428 | + String appKey = ""; |
| 1429 | + if (map.hasKey(Constant.APP_KEY)) { |
| 1430 | + appKey = map.getString(Constant.APP_KEY); |
| 1431 | + } |
| 1432 | + targetConversation = Conversation.createSingleConversation(username, appKey); |
| 1433 | + } else { |
| 1434 | + String groupId = map.getString(Constant.GROUP_ID); |
| 1435 | + targetConversation = Conversation.createGroupConversation(Long.parseLong(groupId)); |
| 1436 | + } |
| 1437 | + JMessageClient.forwardMessage(message, targetConversation, options, new BasicCallback() { |
| 1438 | + @Override |
| 1439 | + public void gotResult(int status, String desc) { |
| 1440 | + mJMessageUtils.handleCallback(status, desc, success, fail); |
| 1441 | + } |
| 1442 | + }); |
| 1443 | + } |
| 1444 | + } catch (Exception e) { |
| 1445 | + e.printStackTrace(); |
| 1446 | + mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER); |
| 1447 | + } |
| 1448 | + } |
| 1449 | + |
1216 | 1450 | public void onEvent(LoginStateChangeEvent event) { |
1217 | 1451 | Log.d(TAG, "登录状态改变事件:event = " + event.toString()); |
1218 | 1452 | WritableMap map = Arguments.createMap(); |
@@ -1292,7 +1526,7 @@ public void onEvent(OfflineMessageEvent event) { |
1292 | 1526 | } |
1293 | 1527 | final WritableArray msgArray = Arguments.createArray(); |
1294 | 1528 | if (lastMediaMsgIndex == -1) { |
1295 | | - for (Message msg: offlineMsgList) { |
| 1529 | + for (Message msg : offlineMsgList) { |
1296 | 1530 | msgArray.pushMap(ResultUtils.toJSObject(msg)); |
1297 | 1531 | } |
1298 | 1532 | map.putArray(Constant.MESSAGE_ARRAY, msgArray); |
|
0 commit comments