Host user information

Update time: 2024/03/14 18:45:31

SDK provides a service of hosting user Information.

Initialization parameters

Sample codes

javascriptvar 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

javascriptnim.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

javascriptnim.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

javascriptnim.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 page 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