Profile

Update time: 2024/03/07 11:13:40

Profiles

CommsEase manages user profiles, including user nickname, avatar, birthday, email, gender, mobile phone number, bio, and extension fields. The NIMUser in the SDK hold the profile data.

  • NIMUser interface
Parameter Type Description
userId String? User account
avatar String? URL of the avatar
nick String? Nickname
birth String? Birthday
email String ? Email address
ext String? Extension field
gender NIMUserGenderEnum? Gender
mobile String? Mobile phone number
sign String? Bio

Get the user profile

Get the user profile from local database

Since updating the user profile requires cross-process asynchronous calls, your app can store the profile information in the cache and access the profile information from the local cache when querying user information. When the profile changes, the SDK will notify the registered observers. At this time, your app can update the cache and refresh the interface.

Get the profiles of a specified user

Get a user profile from the local database.

  • API prototype
dart/// Get a user profile from the local database
/// Query and return the user profile by the user account [userId]
Future<NIMResult<NIMUser>> getUserInfo(String userId);
  • Example
dartNIMResult<NIMUser> result = await NimCore.instance.userService
            .getUserInfo(account);

Update user profiles

The cached user profile in the SDK is not always updated. To update profiles of other users:

  • Get and refresh user information by calling fetchUserInfo.

  • When receiving a message from a user with profile information updated, the SDK will update the user profile and notify the current user..

  • In the data synchronization after login, the SDK will automatically update the user information of friends.

Get user profiles from the cloud server

  • API introduction

Retrieve multiple user profiles at a time if the the required profiles are unavailable in the local storage. The SDK updates the local cache after retrieval. Up to 150 user profiles can be fetched per call. If a large number of profiles must be retrieved, the upper layer of your app can handle the data by part.

  • API prototype
dart* Get user profiles from the server, 150 user profiles can be fetched per call. If a large number of profiles must be retrieved, the upper layer of your app can handle the profile data by segment.
/// Query and return all user profiles in the `userIdList` list.
Future<NIMResult<List<NIMUser>>> fetchUserInfoList(List<String> userIdList);
  • Example
dartNIMResult<List<NIMUser>> result = await NimCore.instance.userService.fetchUserInfoList([account]);

Note: This interface can obtain multiple user profiles from the server at a time. Considering user experience and traffic cost, it is not recommended for applications to call this interface frequently. For pages that do not require high real-time user data, read data from the local cache.

Edit user profiles

  • API prototype
dart/// Update the user profile of the current user.
/// Edit the information provided by [user]
Future<NIMResult<void>> updateMyUserInfo(NIMUser user);
  • Parameters

You can change the avatar URL, birthday, email address, extension field, gender, mobile phone, nickname, and bio.

  • The SDK checks the format of some fields:
Field Description
Email a valid email address
Mobile phone number A valid mobile phone number such as 13588888888, (86)-13055555555
Birthday in "yyyy-MM-dd" format
  • Example
dartNIMResult<void> result =
              await NimCore.instance.userService.updateMyUserInfo(user);

Avatar resources

If you want to update the avatar, you must upload the avatar picture to the cloud first, and then pass the URL to the SDK. You can use the upload and download services provided by CommsEase, or other third-party services.

The upload and download service uses the NimCore.instance.nosService interface. For more information, see the client API reference..

Callback for user profile changes

  • API prototype

Implement the callback by listening to NimCore.instance.userService.onUserInfoChange

  • Example
dartNimCore.instance.userService.onUserInfoChange.listen((userInfoList) {
  /// List of profile changes
});

Search for users

Search by nickname

Get friend accounts by nickname from the local database.

  • API prototype
dart/// Search accounts using nicknames
/// Search accounts by nickname [nick]
Future<NIMResult<List<String>>> searchUserIdListByNick(String nick);
  • Example
dartNIMResult<List<String>> result = await NimCore.instance.userService.searchUserIdListByNick(account);

Search by keyword

Search all users with matched keywords.

dart/// Search all users with matched keywords
/// Return a list of all users that match the keyword [keyword]
NIMResult<List<NIMUser>> searchUserResult = await NimCore.instance.userService.searchUserInfoListByKeyword(keyword);
Was this page helpful?
Yes
No
  • Get the user profile
  • Get the user profile from local database
  • Get the profiles of a specified user
  • Update user profiles
  • Get user profiles from the cloud server
  • Edit user profiles
  • Avatar resources
  • Callback for user profile changes
  • Search for users
  • Search by nickname
  • Search by keyword