Host user information
Update time: 2024/03/14 18:45:31
SDK provides a service of hosting user Information.
Initialization parameters
- Not all initialization parameters are listed here. Please refer to Initialize SDK, and initialization parameters given in other chapters.
- Initialization parameters for connection
- Initialization parameters for multi-terminal login
- Initialization parameters for message
- Initialization parameters for team
- Initialization parameters for user information
- Initialization parameters for friendship
- Initialization parameters for user relationship
- Initialization parameters for session
- Initialization parameters for system message
- Synchronization completed
- Complete initialization codes
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 inputonupdatemyinfo
: 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
: Accountnick
: Nicknameavatar
: Avatarsign
: Signaturegender
: Genderemail
: Emailbirth
: Birthdaytel
: Telephone numbercustom
: Extension field.- It is recommended to create user information in
JSON
format. If it is notJSON
format, other clients may abandon the information, although Web client will receive it normally.
- It is recommended to create user information in
createTime
: Creation timeupdateTime
: 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
- Please refer to Update time of user information.
- The parameter
sync=true
can be input to forcibly get the latest data from server.
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
- Please refer to Update time of user information.
- The parameter
sync=true
can be input to forcibly get the latest data from server. - Up to 150 each time.
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?