Browse SDKs · Flutter
SDKsFlutter

Retrieve the blocklist

Retrieve the current user’s blocklist with the OpenIM Flutter SDK.

Copy

The OpenIMSDK blocklist records users whom the current user has blocked. Call getBlacklist() to retrieve the complete list as BlacklistInfo records. Use this data to build a blocklist settings page, show relationship state on a profile card, or restrict entry into a chat.

The blocklist and group administration are separate capabilities. To mute or remove a group member or change a group role, use the group member APIs. getBlacklist() reads only the blocklist maintained by the current user.

Retrieve the blocklist

After initializing the SDK and calling login(), use getBlacklist() to read the current user's blocklist. An empty result means that no users are blocked.

Future<List<BlacklistInfo>> loadBlockedUsers() async {
  try {
    return await OpenIM.iMManager.friendshipManager.getBlacklist();
  } catch (error) {
    debugPrint('getBlacklist failed: $error');
    rethrow;
  }
}

final blockedUsers = await loadBlockedUsers();
replaceBlockedUsers(blockedUsers);

Profile cards, conversation action menus, and contact lists generally need only determine whether a userID is present in the blocklist. Build a set by userID; use nicknames, avatars, and other fields only for display.

final blockedUserIDs = blockedUsers
    .map((user) => user.userID)
    .whereType<String>()
    .toSet();

bool isBlocked(String userID) => blockedUserIDs.contains(userID);

Blocklist fields

getBlacklist() returns List<BlacklistInfo>. Use userID as the stable list key; all other fields are display or relationship metadata.

FieldDescription
userIDID of the user blocked by the current user.
nicknameTarget user's nickname for display.
faceURLTarget user's avatar URL.
ownerUserIDOwner of this blocklist relationship, which is the current user.
blockUserIDBlocked user ID in the relationship record. Continue to use userID consistently when merging list data.
operatorUserIDID of the user who performed the block operation.
createTimeTime when the blocklist relationship was created.
addSourceSource through which the relationship was added.
genderTarget user's gender value.
exExtension field. Parse only content defined by your application.

If the blocklist UI also displays public profiles or friend remarks, merge those sources by userID and keep BlacklistInfo, FriendInfo, and PublicUserInfo clearly separated.

Call result and incremental changes

After getBlacklist() succeeds, replace the entire blocklist snapshot with the returned List<BlacklistInfo>. This query does not trigger callbacks for adding or removing a blocked user. Call it again when the page first opens or when the user refreshes. For write operations, see Block a user and Unblock a user.