Skip to main content

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.

tip

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:

AttributeTypeDescription
namestringNickname, up to 32 characters.
portraitUristringAvatar URL, up to 128 characters.
uniqueIdstringUser application ID, supporting uppercase/lowercase letters and numbers, up to 32 characters. Note: This field cannot be set via the SDK.
emailstringEmail, up to 128 characters.
birthdaystringBirthday, up to 32 characters.
genderRCUserGenderGender.
locationstringLocation, up to 32 characters.
rolenumberRole, supporting numbers 0-100.
levelnumberLevel, 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):
  1. Key: Supports uppercase/lowercase letters and numbers, up to 32 characters. Must be unique per AppKey. Returns an error if the Key doesn't exist.
  2. Value: String, up to 256 characters.

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

ParameterTypeRequiredDescription
userIdsstring[]YesArray 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 ValuePermission
NOT_SETNot set: Follows AppKey-level permissions (default state).
INVISIBLEInvisible: No one can search for my profile (except name and avatar).
EVERYONEEveryone: All users in the app can view my profile.
Permission Notes

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 PermissionUser-Level PermissionResult
Invisible/Friends Only/EveryoneNot setFollows AppKey-level permission
Invisible/Friends Only/EveryoneSet (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

ParameterTypeRequiredDescription
visibilityUserProfileVisibilityYesProfile 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);

Search User Profile by Application ID

Use the searchUserProfileByUniqueId method to search for user profiles by application ID.

Interface

RongIMLib.searchUserProfileByUniqueId(uniqueId);

Parameter Description

ParameterTypeRequiredDescription
uniqueIdstringYesUser 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)
})