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 the 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 getRelation()
of V2TIMFriendInfoResult
to obtain your relationship from the callback information:
V2TIM_FRIEND_RELATION_TYPE_NONE
: the user is not a friend.V2TIM_FRIEND_RELATION_TYPE_BOTH_WAY
: the user is a two-way friend.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.
Blocking a user
To block messages from a specified user, call the addToBlackList API to block the user.
By default, the blocked user is unaware of the "blocked" status. An error code indicating blocking will not be returned after the user sends a message. If you want blocked users to receive error message in this situation, see How to display an error message to a blocked user after the user sends a message.
Removing a user from the blocklist
Call deleteFromBlackList to remove a user from the blocklist and receive the user’s messages again.
Obtaining the blocklist
Call getBlackList to view and manage the blocklist.
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.
1. User A and user B call setFriendListener to set a relationship chain listener.
2. User B calls setSelfInfo and sets allowType to V2TIM_FRIEND_ALLOW_ANY
.
3. User A becomes user B’s friend simply by calling addFriend to send a friend request.
V2TIMFriendAddApplication
is set to V2TIM_FRIEND_TYPE_BOTH
(that is, setting as a two-way friend), both users A and B receive the onFriendListAdded callback;V2TIM_FRIEND_TYPE_SINGLE
(that is, setting as a one-way friend), only user A receives the onFriendListAdded callback.V2TIM_FRIEND_NEED_CONFIRM
.resultCode
in the success callback parameter V2TIMFriendOperationResult
returns 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.V2TIMFriendApplication
is set to V2TIM_FRIEND_APPLICATION_COME_IN
, user B can accept or reject the request.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.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.
Feature | API |
---|---|
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 blocklist, by default, the user does not know that he/she is in the blocklist. 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 blocklist to know that his/her message failed to be sent, log in to the IM console, choose Feature Configuration > Login and Messages > Blocklist 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 blocklist sends a message.
Was this page helpful?