User Profile
Feature Description
Users can set and get their nicknames, profile photos, and statuses as well as the profile information of non-friend users. The methods are in the
TencentImSDKPlugin.v2TIMManager.getFriendshipManager()
core class.Relationship Chain Event Listener
To stop receiving contacts events, call
removeFriendListener
(Details) to remove the contacts event listener.Note:
You need to set the contacts event listener in advance to receive event notifications.
Sample code:
// Add a contacts listenerconst frindshipListener = {onBlackListAdd: (infoList) => {},onBlackListDeleted: (userids) => {},onFriendApplicationListAdded: (applicationlist) => {},onFriendApplicationListDeleted: (applicationlist) => {},onFriendApplicationListRead: () => {},onFriendInfoChanged: (frindInfolist) => {},onFriendListAdded: (frindInfolist) => {},onFriendListDeleted: (userd) => {},};friendshipManager.addFriendListener(frindshipListener);// Remove the contacts listenerfriendshipManager.removeFriendListener(frindshipListener);
User Profile Management
Querying and modifying your own profile
Call the
getUsersInfo
API (Details) and enter a user's UserID
for the userIDList
parameter to query the user's profile.Call the
setSelfInfo
API (Details) to modify a user's profile.
After the profile is modified successfully, you will receive the onSelfInfoUpdated
callback (Details).Sample code:
// Get a user's profileconst self = await TencentImSDKPlugin.v2TIMManager.getLoginUser();TencentImSDKPlugin.v2TIMManager.getUsersInfo([self.data]);// Set the user's profileTencentImSDKPlugin.v2TIMManager.setSelfInfo({nickName: "",role: 0,faceUrl: "",});
Querying the user profile of a non-friend
Call the
getUsersInfo
API (Details) and enter the UserID
of a non-friend user for the userIDList
parameter to query the profile of the non-friend user.Note:
The profile of a non-friend user cannot be modified.
Querying and modifying a friend's profile
Call the
getFriendsInfo
API (Details) to query the profile of the specified friend. The relationship between the user and the friend can be obtained through the relation
field of the V2TIMFriendInfoResult
in the callback:relation | Relationship |
V2TIM_FRIEND_RELATION_TYPE_NONE | Not a friend |
V2TIM_FRIEND_RELATION_TYPE_BOTH_WAY | Two-way friend |
V2TIM_FRIEND_RELATION_TYPE_IN_MY_FRIEND_LIST | The user is in your contacts. |
V2TIM_FRIEND_RELATION_TYPE_IN_OTHER_FRIEND_LIST | You are in the user's contacts. |
// Get the information of a friendconst friendsInfo = await friendshipManager.getFriendsInfo(["userID"]);
// Set the friend's informationTencentImSDKPlugin.v2TIMManager.setSelfInfo({nickName: "",role: 0,faceUrl: "",});
FAQs
What should I do if the user profile obtained in the Enhanced edition is not the latest?
There are two types of user profile updates in the enhanced SDK:
Friend's profile: When the profile of a friend is updated, the backend will send a system notification to the SDK, so the profile will be updated in real time.
Non-friend user's profile: When the profile of a non-friend user is updated, the backend cannot send a system notification to the SDK; therefore, the profile cannot be updated in real time. To avoid sending a network request to the backend every time the user profile is obtained, the SDK adds the caching logic and allows a user to pull the profile from the backend every ten minutes.