User Relationship
Update time: 2021/12/06 14:48:16
NIMUserManager
provides user relationship management and message settings for user sessions. If user relationships are not hosted to CommsEase, the developer need to maintain the relationships in the application server.
We currently provide three built-in user relationships, including friendship, blocklist, and Do Not Disturb. The three relationships are independent of each other.
User relationship
Get Friendship
@protocol NIMUserManager <NSObject>
/**
* Return to the list of my friends.
*
* @return The NIMUser list
*/
- (nullable NSArray<NIMUser *> *)myFriends;
@end
The friend list is locally cached, and will be synced and updated automatically with the server after a manual/automatic login. The API returns the NIMUser
list. NIMUser
encapsulates the friend IDs hosted by the developer to CommsEase, session settings for the friend (whether to require message notifications and blocklist users), and detailed user profile NIMUserInfo
.
Friendship management
Prototype
@protocol NIMUserManager <NSObject>
/**
* Manage friends.
*
* @param request - Manage requests of adding online friends
* @param completion The callback of completion.
*/
- (void)requestFriend:(NIMUserRequest *)request
completion:(NIMUserBlock)block;
@end
Request NIMUserRequest
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | The ID of a target user |
operation | NIMUserOperation | Operation types |
message | NSString | P.S. |
Operation types include:
Type | Description |
---|---|
NIMUserOperationAdd | add friends without a verification |
NIMUserOperationRequest | Request to add friends |
NIMUserOperationVerify | Approve the request |
NIMUserOperationReject | Reject a request |
User A can send a request for adding a friend or add a friend. User B can either accept or reject a request.
Example:
NIMUserRequest *request = [[NIMUserRequest alloc] init];
request.userId = self.user.usrId; //Encapsulate the user ID
request.operation = NIMUserOperationRequest; //Encapsulate the verification mode
request.message = @"Request for pass"; //Encapsulate a custom verification message
Monitor friendship-related operations
If user A manages his or her friends, User B will receive a notification message of NIMSystemNotification
. You can register addDelegate:
in NIMSystemNotificationManager
to monitor friendship-related operations. For more information, see See System Notification for details.
-
The field value of friendship-related system notification
NIMSystemNotification - Type
is unified asNIMSystemNotificationTypeFriendAdd
. -
NIMSystemNotification - sourceID
is the operator ID. -
NIMSystemNotification - targetID
is the target ID. -
Friendship-related system notification
NIMSystemNotification - attachment
isNIMUserAddAttachment
. Convert the notification in a strong type. -
NIMUserAddAttachment - operationType
can be divided into:- NIMUserOperationAdd: add friends
- NIMUserOperationRequest: request to add friends
- NIMUserOperationVerify: Accept a request
- NIMUserOperationReject: reject a request
Monitor friendship changes
If changes occur in friend management, a callback is triggered:
@protocol NIMUserManagerDelegate <NSObject>
@optional
/**
* Changes in the status (online)
*
* @param user - User object
*/
- (void)onFriendChanged:(NIMUser *)user;
@end
Delete a friend
A user can unfriend the other user.
/**
* Delete friends.
*
* @param userId - Friend ID.
* @param remove - Specifies whether to delete remarks.
* @param completion - The callback of completion.
*/
- (void)deleteFriend:(NSString *)userId
removeAlias:(BOOL)remove
completion:(nullable NIMUserBlock)completion;
@end
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | The ID of a target user |
remove | BOOL | Whether to remove remarks |
NIMUserBlock | NIMUserBlock | Callback completion |
Detect friendship
@protocol NIMUserManager <NSObject>
/**
* Specify whether user A is in my friend list
*
* @param userId - User ID
*
* @return - Specify whether user A is in my friend list
*/
- (BOOL)isMyFriend:(NSString *)userId;
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | Query the target user ID |
Modify friend remark
@protocol NIMUserManager <NSObject>
/**
* @param user - Target user
*/
- (void)updateUser:(NIMUser *)user
completion:(nullable NIMUserBlock)completion;
Blocklist
After blocklisting a contact, the user will not receive messages from the blocklisted contact.
Get a blocklist
@protocol NIMUserManager <NSObject>
/**
* Return the list of all users added to a blocklist.
*
* @return - A NIMUser list of users who are in a blocklist.
*/
- (nullable NSArray<NIMUser *> *)myBlackList;
@end
The list of blocklist is cached locally, and will be synced and updated automatically with the server after a manual or automatic login. The API returns the NIMUser
list. NIMUser
encapsulates the friend ID hosted by the developer to CommsEase, the session settings for the friend (whether to require message notifications, blocklist users.), and detailed user profile NIMUserInfo
.CommsEase is responsible for hosting user profile.
Blocklist a user
@protocol NIMUserManager <NSObject>
/**
* Add a user to a blocklist.
*
* @param userId - User ID
* @param completion - The completion of callback
*/
- (void)addToBlackList:(NSString *)userId
completion:(NIMUserBlock)completion;
@end
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | The ID of a target user |
NIMUserBlock | NIMUserBlock | Callback completion |
Remove a user from a blocklist
@protocol NIMUserManager <NSObject>
/**
* Remove a user from a blocklist.
*
* @param userId - User ID
* @param completion - The completion of callback
*/
- (void)removeFromBlackBlackList:(NSString *)userId
completion:(NIMUserBlock)completion;
@end
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | The ID of a target user |
NIMUserBlock | NIMUserBlock | Callback completion |
Monitor blocklist changes
After blocklisting a user, the local cache will be updated, and a callback will be triggered:
@protocol NIMUserManagerDelegate <NSObject>
@optional
/**
* Changes in a blocklist (online)
*/
- (void)onBlackListChanged;
@end
Specify whether a user is blocklisted
@protocol NIMUserManager <NSObject>
/**
* Specifies whether a user is added to a blocklist
*
* @param userId - User ID
*
* @return - whether a user is added to a blocklist
*/
- (BOOL)isUserInBlackList:(NSString *)userId;
@end
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | The ID of a target user |
Do Not Disturb
Get a list of Do Not Disturb
@protocol NIMUserManager <NSObject>
/**
* The list of Do Not Disturb
*
* @return - Return the NIMUser list whose message notifications are not displayed.
*/
- (NSArray<NIMUser *> *)myMuteUserList;
@end
The Do Not Disturb list is locally cached, and will be synced and updated automatically with the server after a manual or automatic login. The API returns the NIMUser
list. NIMUser
encapsulates the friend ID hosted by the developer to CommsEase, the session settings for the friend (whether to require message notification, blacklist users), and detailed user profile NIMUserInfo
. CommsEase is responsible for hosting user profile.
Set a Do Not Disturb mode
@protocol NIMUserManager <NSObject>
/**
* Set the Do Not Disturb mode
*
* @param notify - Specify whether to send notifications
* @param userId - User ID
* @param completion - The callback of completion
*/
- (void)updateNotifyState:(BOOL)notify
forUser:(NSString *)userId
completion:(nullable NIMUserBlock)completion
@end
Parameter List
Parameter | Type | Description |
---|---|---|
notify | BOOL | Send notifications or not |
userId | NSString | The ID of a target user |
NIMUserBlock | NIMUserBlock | Callback completion |
After the successful setting, locally cached data will be updated.
Monitor changes in a list of Do Not Disturb
@protocol NIMUserManagerDelegate <NSObject>
/**
* Changes in a list of Do Not Disturb (online)
*/
- (void)onMuteListChanged;
@end
Specify whether to set a Do Not Disturb mode
@protocol NIMUserManager <NSObject>
/**
* Whether to set a Do Not Disturb mode
*
* @param userId - User ID
*
* @return - Whether to set a Do Not Disturb mode
*/
- (BOOL)notifyForNewMsg:(NSString *)userId;
@end
Parameter List
Parameter | Type | Description |
---|---|---|
userId | NSString | The ID of a target user |