@Override public void onEvent(FriendChangedNotify friendChangedNotify) { List<Friend> addedOrUpdatedFriends = friendChangedNotify.getAddedOrUpdatedFriends(); List<String> myFriendAccounts = new ArrayList<>(addedOrUpdatedFriends.size()); List<String> friendAccounts = new ArrayList<>(addedOrUpdatedFriends.size()); List<String> deletedFriendAccounts = friendChangedNotify.getDeletedFriends(); // 如果在黑名单中,那么不加到好友列表中 String account; for (Friend f : addedOrUpdatedFriends) { account = f.getAccount(); friendMap.put(account, f); friendAccounts.add(account); if (NIMClient.getService(FriendService.class).isInBlackList(account)) { continue; } myFriendAccounts.add(account); } // 更新我的好友关系 if (!myFriendAccounts.isEmpty()) { // update cache friendAccountSet.addAll(myFriendAccounts); // log DataCacheManager.Log(myFriendAccounts, "on add friends", UIKitLogTag.FRIEND_CACHE); } // 通知好友关系更新 if (!friendAccounts.isEmpty()) { for (FriendDataChangedObserver o : friendObservers) { o.onAddedOrUpdatedFriends(friendAccounts); } } // 处理被删除的好友关系 if (!deletedFriendAccounts.isEmpty()) { // update cache friendAccountSet.removeAll(deletedFriendAccounts); for (String a : deletedFriendAccounts) { friendMap.remove(a); } // log DataCacheManager.Log( deletedFriendAccounts, "on delete friends", UIKitLogTag.FRIEND_CACHE); // notify for (FriendDataChangedObserver o : friendObservers) { o.onDeletedFriends(deletedFriendAccounts); } } }