Skip to main content

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.

tip

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:

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

ParameterTypeRequiredDescription
userIdsstring[]YesUser 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:

ValuePermission
NOT_SETNot set: Follows AppKey-level permissions (default state).
INVISIBLEInvisible: No one can search my profile (except name and avatar).
EVERYONEEveryone: All users in the app can view my profile.
Permission Notes

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 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 updateMyUserProfileVisibility 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 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);

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