Instant Messaging
Web
Quick Start
Product Introduction
Overview
Features
Limits
Features
Account integration and login
Messaging
Team Chat
Chat Room
Chat Room Tags
Multi-device Login
Statistics Monitoring
Development Integration
Integration
Initializing the SDK
Login and Logout
Messaging
Recent Chats
User Profile Hosting
Friends Data Hosting
User Relationship Data Hosting
Online Status Subscription
Message History
System Notification
Team
Superteam
Chat Room
High availability of domain name
Extension Features
Tools
API Reference
Status Code

Host user information

Update time: 2021/08/23 01:29:57

SDK provides a service of hosting user Information.

Initialization parameters

Sample codes

var nim = NIM.getInstance({
    onmyinfo: onMyInfo,
    onupdatemyinfo: onUpdateMyInfo,
    onusers: onUsers,
    onupdateuser: onUpdateUser
});
function onMyInfo(user) {
    console.log('receive my profile', user);
    data.myInfo = user;
    updateMyInfoUI();
}
function onUpdateMyInfo(user) {
    console.log('My profile is updated', user);
    data.myInfo = NIM.util.merge(data.myInfo, user);
    updateMyInfoUI();
}
function updateMyInfoUI() {
    // Refresh the interface
}
function onUsers(users) {
    console.log('receive user information list', users);
    data.users = nim.mergeUsers(data.users, users);
}
function onUpdateUser(user) {
    console.log('user information is updated', user);
    data.users = nim.mergeUsers(data.users, user);
}

Explanation for parameters

  • onmyinfo: It is a callback for synchronizing information of current user, by which User information is input
  • onupdatemyinfo: It is a callback by current user after updating personal information at other clients, by which User information is input.
  • onusers: It is a callback for synchronizing user information of friends, by which User information array is input.
    • It is an increment callback, and invoke nim.mergeUsers can be invoked to merge data.
  • onupdateuser: It is a callback after updating user information, by which User information is input. Please refer to Update time of user information.

Object of user information

The object of user information contains fields as below:

  • account: Account
  • nick: Nickname
  • avatar: Avatar
  • sign: Signature
  • gender: Gender
  • email: Email
  • birth: Birthday
  • tel: Telephone number
  • custom: Extension field.
    • It is recommended to create user information in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it normally.
  • createTime: Creation time
  • updateTime: Update time

Gender

  • 'unknown' (Unknown)
  • 'male' (Male)
  • 'female' (Female)

Update my information

nim.updateMyInfo({
    nick: 'newNick',
    avatar: 'http://newAvatar',
    sign: 'newSign',
    gender: 'male',
    email: 'new@email.com',
    birth: '1900-01-01',
    tel: '13523578129',
    custom: '{type: "newCustom", value: "new"}',
    done: updateMyInfoDone
});
function updateMyInfoDone(error, user) {
    console.log('update my profile' + (!error?'succeeded'':'failed'));
    console.log(error);
    console.log(user);
    if (!error) {
        onUpdateMyInfo(user);
    }
}

Update time of user information

  • Except own user information, it is impossible to ensure real-time update for information of other users. Only when a message is received from
    • the user , information of other users can be updated.
    • The user information of corresponding friends will be synchronized every time.
  • If you want to refresh user information manually, please refer to Get user information and Get user information array.

Get User Information

nim.getUser({
    account: 'account',
    done: getUserDone
});
function getUserDone(error, user) {
    console.log(error);
    console.log(user);
    console.log('get user information' + (!error?'succeeded'':'failed'));
    if (!error) {
        onUsers(user);
    }
}

Get user information array

nim.getUsers({
    accounts: ['account1', 'account2'],
    done: getUsersDone
});
function getUsersDone(error, users) {
    console.log(error);
    console.log(users);
    console.log('get user information array' + (!error?'succeeded'':'failed'));
    if (!error) {
        onUsers(users);
    }
}
Was this topic helpful?
Yes
No
  • Initialization parameters
  • Object of user information
  • Gender
  • Update my information
  • Update time of user information
  • Get User Information
  • Get user information array