User Profile Hosting
This document guides developers on implementing user profile subscription, querying, and monitoring in RC's instant messaging client SDK, while supporting user profile and permission modifications and queries. Through this document, developers will learn how to obtain and track user profiles, as well as receive notifications when status changes occur.
This feature is supported starting from version 5.10.1.
Enabling the Service
Before using this feature, you must enable the profile hosting service by submitting a ticket.
User Profile Management
The SDK provides interfaces for modifying, querying, and subscribing to user profiles.
Update Current User Profile
Use the updateMyUserProfile method to update the current user's profile.
Interface
RongIMLib.updateMyUserProfile(profile)
Parameter Description
The profile parameter is of type IUserProfileInfo, containing the following properties:
Property | Type | Description |
---|---|---|
name | string | Nickname, limited to 32 characters. |
portraitUri | string | Avatar URL, limited to 128 characters. |
uniqueId | string | User application ID, supporting uppercase/lowercase letters and numbers, limited to 32 characters. Note: This field cannot be set via SDK. |
string | Email, limited to 128 characters.| | |
birthday | string | Birthday, limited to 32 characters.| |
gender | RCUserGender | Gender| |
location | string | Location, limited to 32 characters. |
role | number | Role, supporting numbers 0-100. |
level | number | Level, supporting numbers 0-100. |
userExtProfile | { [key: string]: string } | Custom extended profile, supporting up to 20 user attributes (set as Key-Value pairs. Keys must be configured via developer backend)
|
Example Code
const profile = {
name: 'name',
portraitUri: 'portraitUri',
email: 'email',
birthday: 'birthday',
gender: 1,
location: 'location',
role: 1,
level: 1,
extraProfile: {
key1: 'value1',
key2: 'value2',
},
}
const res = await RongIMLib.updateMyUserProfile(profile);
console.log('Profile update result:', res);
Get Current User Profile
Use getMyUserProfile to retrieve the current user's profile for display.
Interface
RongIMLib.getMyUserProfile();
Parameter Description
None
Example Code
const res = await RongIMLib.getMyUserProfile();
console.log('Current user profile:', res);
Batch Get Other Users' Profiles
Use getUserProfiles to batch retrieve other users' profiles.
Interface
RongIMLib.getUserProfiles(userIds);
Parameter Description
Parameter | Type | Required | Description |
---|---|---|---|
userIds | string[] | Yes | User ID array, supporting up to 20 users per query. |
Example Code
const userIds = ['user1', 'user2'];
const res = await RongIMLib.getUserProfiles(userIds);
console.log('Batch profile retrieval result:', res);
User Permissions
The client SDK provides interfaces for setting and retrieving user permissions, represented by the UserProfileVisibility
enum.
UserProfileVisibility enum description:
Value | Permission |
---|---|
NOT_SET | Not set: Follows AppKey-level permissions (default state). |
INVISIBLE | Invisible: No one can search my profile (except name and avatar). |
EVERYONE | Everyone: All users in the app can view my profile. |
AppKey's default profile access permission is Invisible, while user-level defaults to Not set. When both are default, SDK can only view others' usernames and avatars.
Combined permission behavior:
AppKey-level Permission | User-level Permission | Result |
---|---|---|
Invisible/Friends-only/Everyone | Not set | Follows AppKey-level permission |
Invisible/Friends-only/Everyone | Set (Invisible/Everyone) | Follows user-level permission |
Set User Permissions
Use updateMyUserProfileVisibility to set the current user's profile access permissions.
Interface
RongIMLib.updateMyUserProfileVisibility(visibility)
Parameter Description
Parameter | Type | Required | Description |
---|---|---|---|
visibility | UserProfileVisibility | Yes | Profile access permission. |
Example Code
const visibility = RongIMLib.UserProfileVisibility.EVERYONE;
const res = await RongIMLib.updateMyUserProfileVisibility(visibility);
console.log('Permission setting result:', res);
Get User Permissions
Use getMyUserProfileVisibility to retrieve the current user's profile access permissions.
Interface
RongIMLib.getMyUserProfileVisibility();
Parameter Description
None
Example Code
const res = await RongIMLib.getMyUserProfileVisibility();
console.log('Permission retrieval result:', res);
User Search
Search User Profile by Application ID
Use searchUserProfileByUniqueId to search for user profiles by application ID.
Interface
RongIMLib.searchUserProfileByUniqueId(uniqueId);
Example Code
const uniqueId = 'uniqueId';
const res = await RongIMLib.searchUserProfileByUniqueId(uniqueId);
console.log('Exact user profile search result by Application ID:', res);
Listen for User Profile Changes
To receive notifications about subscription changes, you need to set up an event listener. Call addEventListener
before establishing a connection.
- Subscribe to user profile changes
/**
* Notifies when subscribed user profiles change.
* RC won't notify you after subscription expiration - monitor expiration time yourself.
*/
RongIMLib.addEventListener(Events.SUBSCRIBED_USER_STATUS_CHANGE, (event) => {
// Use subscribeType in data to determine whether it's profile or online status
console.log('Subscribed user status changed', event)
})
- Subscription relationship changes (multi-device sync)
/**
* Notifies when subscription information changes on other devices.
* Use this to update local user status and maintain subscription consistency.
*/
RongIMLib.addEventListener(Events.SUBSCRIBED_RELATION_CHANGE, (event) => {
// Use subscribeType in data to determine whether it's profile or online status
console.log('Subscription relationship changed', event)
})
- Subscription data sync completed
/**
* Notifies when subscription data sync completes.
* Triggered after successfully syncing subscription data to device/system.
*/
RongIMLib.addEventListener(Events.SYNC_SUBSCRIBED_USER_STATUS_FINISHED, (event) => {
// Use subscribeType in data to determine whether it's profile or online status
console.log('Subscription data synced', event)
})
- User profile changes
/**
* Notifies when user profiles change on other devices.
* Triggered after profile modifications on other endpoints.
*/
RongIMLib.addEventListener(Events.OWN_USER_PROFILE_CHANGED, (event) => {
console.log('User profile changed', event)
})