User Profile and Relationship Chain (iOS)

Last updated: 2021-04-30 17:46:27

    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 the 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:

    • 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 Messages from a Specified User

    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 allowType to V2TIM_FRIEND_ALLOW_ANY.
     3. User A becomes user B’s friend simply by calling addFriend to send a friend request.

    • If addType in the request parameter 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;
    • If this value is set to 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 allowType to V2TIM_FRIEND_NEED_CONFIRM.
    3. User A calls addFriend to send a friend request to user B. 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.
    4. User B receives the onFriendApplicationListAdded callback. If type in the parameter V2TIMFriendApplication is set to 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 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.

    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


    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 blocked users try to send a message?

    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.