User Information Management
Update time: 2021/09/25 14:32:12
CommsEase provides the service of hosting user data, including birthday, Email, gender, phone number, signature and extension field. The user data is managed via NIM.User.UserAPI
. UserNameCard
indicates user data and defines all data of a user.
User Data
Description of NIM.User.UserNameCard
:
Property | Description |
---|---|
AccountId | User account |
NickName | Nickname |
IconUrl | Avatar URL |
Signature | Signature |
Gender | Gender: 0 means female; 1 means male. |
Birthday | Birthday |
Mobile | Phone number |
ExpandedData | Expansion information |
CreateTime | Creation timestamp |
UpdatedTime | Final update timestamp |
Get Local User Data
Get user data in bulk from locally cached data
- API prototype
csharp/// <summary>
///Get user card of designated account in cache data
/// </summary>
/// <param name="accountIdList">List of user account IDs</param>
/// <param name="resultDelegate">Callback for querying results</param>
public static void GetUserNameCard(List<string> accountIdList, GetUserNameCardResultDelegate resultDelegate)
- Example
csharpNIM.User.UserAPI.GetUserNameCard(new List<string>() { "id1","id2" }, OnGetNameCardCompleted);
private void OnGetNameCardCompleted(UserNameCard[] list)
{
if (list != null && list.Any())
{
//Query successfully, and process query results
}
}
Get User Data from the Server
User data is acquired from server and usually called when there is not local user data. After acquisition, SDK will update local database. 150 users can be acquired at most each time. The upper level may get user data in batch in the event of large quantity.
- API prototype
csharp/// <summary>
///Query user card of designated account online
/// </summary>
/// <param name="accountIdList">List of user account IDs</param>
/// <param name="resultDelegate"></param>
public static void QueryUserNameCardOnline(List<string> accountIdList, GetUserNameCardResultDelegate resultDelegate)
- Example
csharpNIM.User.UserAPI.QueryUserNameCardOnline(new List<string>() { "id1","id2" }, OnGetNameCardCompleted);
Notes: User data can be acquired from server in bulk via this interface. Considering user experience and flow cost, it is recommended not to invoke this interface frequently. For the pages under which the real-time performance requirement is not high, it is suggested to call the interface of reading local cache.
Update Personal Information
To update your user data, first construct theUserNameCard
object, then set the attributes that need to be updated, after that, callNIM.User.UserAPIUpdateMyCard
to perform the update.
- API prototype
csharp/// <summary>
/// Update user cards
/// </summary>
/// <param name="card"></param>
/// <param name="d"></param>
public static void UpdateMyCard(UserNameCard card, UpdateNameCardResultDelegate d)
- Example
csharpprivate void UpdateMyInfo()
{
UserNameCard card = new UserNameCard();
card.AccountId = "MYSELF ID";
card.Birthday = "1990.01.01";
card.Email = "xxxxxx@xxxx.com";
card.Mobile = "123456789";
card.NickName = "NEW NICKNAME";
card.Signature = "SIGNATURE";
card.Gender = 1;
NIM.User.UserAPI.UpdateMyCard(_card, OnUpdateMyNamecard);
}
private void OnUpdateMyNamecard(ResponseCode response)
{
//Process operation results
}
Notification for User Data Change
The event NIM.User.UserAPI.UserNameCardChangedHandler
is registered to get notification for data change of all users.
- Example
csharpNIM.User.UserAPI.UserNameCardChangedHandler += OnUserChanged;
private void OnUserChanged(object sender, UserNameCardChangedArgs e)
{
//Process user data change. The parameter e includes detailed information of a user.
}
Except your "user data", SDK cannot ensure real-time information updating for other users. Other user data update occasion:
-
Call the interface
QueryUserNameCardOnline
to get user data online. -
Receive messages from the user
-
When the program is start up again, information of friends will be synchronized.