AI Integration Quick Reference
AI Integration Quick Reference
Block Users
In other words, as a logged-in user, how do I block a user from sending me messages? You can block users using theblockUsers() method. Once any user is blocked, all the communication to and from the respective user will be completely blocked. You can block multiple users in a single operation. The blockUsers() method takes a List<String> as a parameter which holds the list of UIDs to be blocked.
- Dart
onSuccess() callback, you receive a Map which contains UIDs as the keys and success or fail as the value based on if the block operation for the UID was successful or not.
Unblock Users
In other words, as a logged-in user, how do I unblock a user I previously blocked? You can unblock the already blocked users using theunblockUsers() method. You can unblock multiple users in a single operation. The unblockUsers() method takes a List<String> as a parameter which holds the list of UIDs to be unblocked.
- Dart
onSuccess() callback, you receive a Map which contains UIDs as the keys and success or fail as the value based on if the unblock operation for the UID was successful or not.
Get list of blocked users
In other words, as a logged-in user, how do I get a list of all users I’ve blocked? In order to fetch the list of blocked users, you can use theBlockedUsersRequest class. To use this class i.e to create an object of the BlockedUsersRequest class, you need to use the BlockedUsersRequestBuilder class. The BlockedUsersRequestBuilder class allows you to set the parameters based on which the blocked users are to be fetched.
The BlockedUsersRequestBuilder class allows you to set the below parameters:
Set Limit
This method sets the limit i.e. the number of blocked users that should be fetched in a single iteration.- Dart
Set Search Keyword
With offline support on, the cached page is filtered by this keyword on the device too, as a case-insensitive substring match on the user’s name.
- Dart
Set Direction
CometChatBlockedUsersDirection.directionBlockedByMe - This will ensure that the list of blocked users only contains the users blocked by the logged in user.CometChatBlockedUsersDirection.directionHasBlockedMe - This will ensure that the list of blocked users only contains the users that have blocked the logged in user.CometChatBlockedUsersDirection.directionBoth - This will make sure the list of users includes both the above cases. This is the default value for the direction variable if it is not set.
- Dart
build() method to get the object of the BlockedUsersRequest class.
Once you have the object of the BlockedUsersRequest class, you need to call the fetchNext() method. Calling this method will return a list of User objects containing n number of blocked users where N is the limit set in the builder class.
Starting with v5.1.0, `fetchNext()` accepts a
listener: parameter. Pass a `BlockedUsersFetchListener` to receive the on-device cached result. The listener: parameter requires cometchat_sdk 5.1.0 or later, so on 5.0.x keep using onSuccess/onError. With offline support off, the listener behaves exactly like the callbacks: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, the listener also delivers the cached result first, then the server result. onSuccess/onError keep working and receive only the server result. See Show Cached Data.- Dart
Offline Behaviour
With offline support enabled,BlockedUsersRequest.fetchNext() with a BlockedUsersFetchListener first delivers onCachedBlockedUsers from the SDK’s own blocked-users list, which it refreshes on login and on reconnect and updates when you call blockUsers() or unblockUsers(). Then onServerBlockedUsers delivers the live page to reconcile by uid; the server page is not saved to the device. The cached page is empty when no users are blocked; with searchKeyword set, it holds the cached blocked users whose name contains the keyword. Offline, the read ends with onError with code ERR_CONNECTION (details ERROR_INTERNET_UNAVAILABLE) after the cached page. See Show Cached Data.