User Profile Hosting
This document guides developers on how to implement user profile subscription, querying, and monitoring in the RC Instant Messaging Client SDK, while supporting modifications and queries of user profiles and permissions.
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
The profile hosting service is enabled by default and can be used directly.
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 and contains the following attributes:
| Attribute | Type | Description |
|---|---|---|
| name | string | Nickname, up to 32 characters. |
| portraitUri | string | Avatar URL, up to 128 characters. |
| uniqueId | string | User application ID, supporting uppercase/lowercase letters and numbers, up to 32 characters. Note: This field cannot be set via the SDK. |
| string | Email, up to 128 characters. | |
| birthday | string | Birthday, up to 32 characters. |
| gender | RCUserGender | Gender. |
| location | string | Location, up to 32 characters. |
| role | number | Role, supporting numbers 0-100. |
| level | number | Level, supporting numbers 0-100. |
| userExtProfile | { [key: string]: string } | Custom extended information. Up to 20 key-value pairs can be set (Keys must be configured in the developer console):
|
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('User profile update result:', res);
Get Current User Profile
Use the getMyUserProfile method 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 the getUserProfiles method to batch retrieve other users' profiles.
Interface
RongIMLib.getUserProfiles(userIds);
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| userIds | string[] | Yes | Array of user IDs. Maximum 100 users per query. |
Example Code
const userIds = ['user1', 'user2'];
const res = await RongIMLib.getUserProfiles(userIds);
console.log('Batch user profile results:', res);
User Permissions
The client SDK provides interfaces for setting and retrieving user permissions, represented by the UserProfileVisibility enum.
UserProfileVisibility enum values:
| Enum Value | Permission |
|---|---|
| NOT_SET | Not set: Follows AppKey-level permissions (default state). |
| INVISIBLE | Invisible: No one can search for my profile (except name and avatar). |
| EVERYONE | Everyone: All users in the app can view my profile. |
The default AppKey-level profile access permission is Invisible, while user-level permission defaults to Not set. When both are default, the SDK can only view others' names 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 the updateMyUserProfileVisibility method 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 update result:', res);
Get User Permissions
Use the getMyUserProfileVisibility method to retrieve the current user's profile access permissions.
Interface
RongIMLib.getMyUserProfileVisibility();
Parameter Description
None
Example Code
const res = await RongIMLib.getMyUserProfileVisibility();
console.log('Current permissions:', res);
User Search
Search User Profile by Application ID
Use the searchUserProfileByUniqueId method to search for user profiles by application ID.
Interface
RongIMLib.searchUserProfileByUniqueId(uniqueId);
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| uniqueId | string | Yes | User application ID. |
Example Code
const uniqueId = 'uniqueId';
const res = await RongIMLib.searchUserProfileByUniqueId(uniqueId);
console.log('Search result by application ID:', res);
Monitor User Profile Changes
To receive notifications for subscription events, set up subscription listeners using addEventListener. Listeners must be added before connecting.
- Subscribe to user profile changes
/**
* Notifies when subscribed users' profiles change.
* After subscription expires, RC SDK won't actively notify you - monitor expiration manually.
*/
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.
* Used to update user status on current device for 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.
* Used for subsequent business operations after successful sync 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
/**
* User profile changes.
* This notification is received when user profile is modified on another device, used to perform subsequent business operations.
*/
RongIMLib.addEventListener(Events.OWN_USER_PROFILE_CHANGED, (event) => {
console.log('User profile changed', event)
})