Use getUsersInfo to query your own profile, where
userIDList indicates your own UserID.
Use setSelfInfo to modify your own profile. You will receive the onSelfInfoUpdated callback after your profile is modified successfully.
Use getUsersInfo to query the user profile of a non-friend, where
userIDList indicates the UserID of the user to query.
Use getFriendsInfo to query the profile of a specified friend. Use
V2TIMFriendInfoResult to obtain your relationship from the callback information:
V2TIMCheckFriendResult.V2TIM_FRIEND_RELATION_TYPE_NONE: the user is not a friend.
V2TIMCheckFriendResult.V2TIM_FRIEND_RELATION_TYPE_BOTH_WAY: the user is a two-way friend.
V2TIMCheckFriendResult.V2TIM_FRIEND_RELATION_TYPE_IN_MY_FRIEND_LIST: the user is in your friend list.
Use setFriendInfo to modify the information of a specified friend, such as friend remarks.
Blacklisting a user
To block messages from a specified user, call the addToBlackList API to blacklist the user.
By default, the blacklisted user is unaware of the "blacklisted" status. An error code indicating blacklisting will not be returned after the user sends a message. If you want blacklisted users to receive the blacklisting message in this situation, see How to display an error message to a blacklisted user after the user sends a message.
Removing a user from the blacklist
Call deleteFromBlackList to remove a user from your blacklist and receive the user’s messages again.
Obtaining the blacklist
Call getBlackList to view and manage the blacklist.
By default, the IM SDK does not check the relationship between two parties when sending one-to-one chat messages. This default setting is generally applied in customer service scenarios, where having to friend a customer service agent before chatting is inefficient.
If you want to demand users to be friends before they can chat, as in WeChat and QQ, log in to the IM console, choose Feature Configuration > Login and Message > Relationship Check, and enable "Check Relationship for One-to-One Chat Messages". With this feature enabled, users can only send messages to friends and will receive the 20009 error code from the SDK when sending a message to a non-friend user.
The IM SDK supports relationship chain logic. You can call getFriendList to obtain the friend list, call deleteFromFriendList to delete a friend from the friend list, or call addFriend to add a friend.
The process has the following varations depending on whether friend verification is required.
V2TIM_FRIEND_ALLOW_ANYthrough the setAllowType API.
V2TIMFriendAddApplicationis set to
V2TIMFriendInfo.V2TIM_FRIEND_TYPE_BOTH(that is, setting as a two-way friend), both users A and B receive the onFriendListAdded callback.
V2TIMFriendInfo.V2TIM_FRIEND_TYPE_SINGLE(that is, setting as a one-way friend), only user A receives the onFriendListAdded callback.
V2TIM_FRIEND_NEED_CONFIRMthrough the setAllowType API.
V2TIMFriendOperationResultreturns the 30539 error code, indicating that user B’s approval is required in this case. At this time, both users A and B receive the onFriendApplicationListAdded callback.
V2TIMFriendApplicationis set to
V2TIMFriendApplication.V2TIM_FRIEND_APPLICATION_COME_IN, user B can accept or reject the request.
V2TIMFriendApplication.V2TIM_FRIEND_ACCEPT_AGREE(that is, accepting as a one-way friend), user A receives the onFriendListAdded callback, indicating that a one-way relationship has been established. Meanwhile, user B receives the onFriendApplicationListDeleted callback, indicating that user B is now in user A’s friend list, but user A is not in user B’s friend list.
V2TIMFriendApplication.V2TIM_FRIEND_ACCEPT_AGREE_AND_ADD(that is, accepting as a two-way friend), both users A and B receive the onFriendListAdded callback, indicating that they are now in each other’s friend list.
To group friends into categories such as "classmates" and "coworkers", call the following APIs.
|Create a friend group||createFriendGroup|
|Delete a friend group||deleteFriendGroup|
|Modify a friend group||renameFriendGroup|
|Obtain the list of friend groups||getFriendGroupList|
|Add friends to a friend group||addFriendsToFriendGroup|
|Delete friends from a friend group||deleteFriendsFromFriendGroup|
By default, the IM SDK does not prevent message sending and receiving between strangers. If you want messages to be sent or received only between friends, log in to the IM console, choose Feature Configuration > Login and Messages > Relationship Check, and enable Check Relationship for One-to-One Chat Messages. After this feature is enabled, you can send messages only to friends. When you try to send messages to strangers, the IM SDK returns the 20009 error code.
When a user is added to the blacklist, by default, the user does not know that he/she is in the blacklist. That is, after this user sends a message, the user is still prompted that the message was sent successfully, but in fact, the recipient will not receive the message. If you want a user in the blacklist to know that his/her message failed to be sent, log in to the IM console, choose Feature Configuration > Login and Messages > Blacklist Check, and disable Show "Sent successfully" After Sending Messages. After this feature is disabled, the IM SDK will return the 20007 error code when a user in the blacklist sends a message.