User Profiles and Relationship Chains (Android)

Last updated: 2020-06-30 10:58:14

    User Profile Management

    Querying and modifying your own profile

    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.

    Querying the profile of a non-friend

    Use getUsersInfo to query the user profile of a non-friend, where userIDList indicates the UserID of the user to query.

    Querying and modifying a friend’s profile

    Use getFriendsInfo to query the profile of a specified friend. Use getRelation() of 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.

    Blocking Messages from a Specified User

    • 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.

    Friend Management

    Determining whether a friend request is required

    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.

    Friend list management

    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.

    Friend request approval is not required

    1. User A and user B call setFriendListener to set a relationship chain listener.
    2. User B calls setSelfInfo and sets info to V2TIM_FRIEND_ALLOW_ANY through the setAllowType API.
    3. User A becomes user B’s friend simply by calling addFriend to send a friend request. If setAddType in the request parameter V2TIMFriendAddApplication is set to V2TIMFriendInfo.V2TIM_FRIEND_TYPE_BOTH (that is, setting as a two-way friend), both users A and B receive the onFriendListAdded callback.
      If this value is set to V2TIMFriendInfo.V2TIM_FRIEND_TYPE_SINGLE (that is, setting as a one-way friend), only user A receives the onFriendListAdded callback.

    Friend request approval is required

    1. User A and user B call setFriendListener to set a relationship chain listener.
    2. User B calls setSelfInfo and sets info to V2TIM_FRIEND_NEED_CONFIRM through the setAllowType API.
    3. User A calls addFriend to send a friend request to user B. getResultCode 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.
    4. User B receives the onFriendApplicationListAdded callback. If getType in the parameter V2TIMFriendApplication is set to V2TIMFriendApplication.V2TIM_FRIEND_APPLICATION_COME_IN, user B can accept or reject the request.
      • User B calls acceptFriendApplication to accept the friend request. If the acceptance type is 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.
      • If the acceptance type is 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.
      • User B calls refuseFriendApplication to reject the friend request and both users receive the onFriendApplicationListDeleted callback.

    Friend group management

    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

    FAQs

    How can I disable messaging between two users who are not friends?

    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.

    2. How do I enable error messages when blacklisted users try to send a message?

    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.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help