Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Update your profile

Update the nickname, avatar URL, or account-level extension string of the authenticated user.

Copy

Invoke setSelfInfo() to update display attributes for the currently logged-in user. Pass only the properties being modified (nickname, faceURL, or ex); avoid accidentally overriding account-level policy fields when saving a nickname or avatar.

Parameters

ParameterTypeRequiredDescription
nicknamestring | nullNoNew account-level display nickname.
faceURLstring | nullNoNew account-level avatar URL.
exstring | nullNoNew custom extension string; completely overwrites the previous value.

Supply at least one field to update.

Code example

import { setSelfInfo } from '@/uni_modules/unix-openim-sdk'

await setSelfInfo({
  nickname: nickname.trim(),
  faceURL,
  ex: mergedExtra,
})

The ex property stores an opaque string. The SDK does not perform JSON patching. When multiple application modules share this attribute, read the current profile, merge changes into your application namespace, and submit the entire serialized string.

Account-level policy fields are documented in dedicated guides: refer to Set global message reception for notification preferences and Set friend request permissions for friend authorization policies. Submit these settings from their dedicated preference screens.

Return value

The Promise resolves with void once OpenIMServer accepts the profile modification request.

State changes after the call

A resolved Promise confirms that the profile update was accepted by OpenIMServer. It does not indicate that the profile update event has propagated to other devices or clients. To synchronize state immediately, await the event callback or call Get your profile to re-calibrate.

Monitor profile updates

Register the onSelfInfoUpdated event to observe profile changes for the active account. The callback delivers an updated OpenIMUserInfo | null object. When non-null, replace the cached profile matching userID:

import {
  OpenIMUserInfo,
  off,
  onSelfInfoUpdated,
} from '@/uni_modules/unix-openim-sdk'

const handleSelfInfoUpdated = (user: OpenIMUserInfo | null) => {
  if (user == null) return
  setCurrentUser(user)
}

const selfInfoSubscription = onSelfInfoUpdated(handleSelfInfoUpdated)

function removeSelfInfoListener() {
  off(selfInfoSubscription)
}

Unsubscribe from this listener when logging out, switching accounts, or tearing down the user store to prevent duplicate event execution.