Instant Messaging
Android
Getting Started
Introduction
Overview
Benefits
Features
Features
Account Integration and Login
Group Chat
Chat Room
Chat Room Tags
Multi-device Login
Statistics Monitoring
Limits
Integration
Interface Overview
Integrate and Initialize SDK
Messaging
Basic Messaging
Message History
Message Sending
Message Receiving
Recent Chats
Server Sessions
User Profile
User Relationship
Online Status Subscription
Push and Message Alert
Superteam
Chat Room
Moderation
Chat Extension
Miscellaneous Features
Best Practice
Traffic Control in Chat Rooms
Reference
API Reference
Status Codes

User Information Management

Update time: 2021/09/25 21:40:33

SDK provides information management for user account, including birthday, email, gender, phone number, signature and extension field, etc. The following interface is valid only when CommsEase is preferred to host the user information. If developers do not want to store user data on CommsEase servers, they can use other solutions.

JSON Key of user information is defined in nim_user_def.h.

The callback registered via the interfacevoid nim_user_reg_user_name_card_changed_cb(const char *json_extension, nim_user_name_card_change_cb_func cb, const void *user_data)will be invoked to notify the program of user information change:

Get User Information on Local Storage

Get user information in bulk from locally cached data

  • API prototype
/** @fn void nim_user_get_user_name_card(const char *accids, const char *json_extension, nim_user_get_user_name_card_cb_func cb, const void *user_data)
* Get the namecard of the specified local account
* @param[in] accids e.g. ["litianyi01", "litianyi02", ...]
* @param[in] json_extension json extension parameter that is used in some cases
* @param[in] cb operation result callback
* @param[in] user_data APP's custom user data, which SDK is only responsible for passing back to the callback function cb (without any processing)
* @return void
* @note - Error code:200: Successful
* 414: Parameter error
*/
NIM_SDK_DLL_API	void nim_user_get_user_name_card(const char *accids, const char *json_extension, nim_user_get_user_name_card_cb_func cb, const void *user_data);
  • Example
void CallbackGetUserNameCard(const char *result_json, const char *json_extension, const void *callback)
{
    // parse result_json
}

typedef void (*nim_user_get_user_name_card)(const char *accids, const char *json_extension, nim_user_get_user_name_card_cb_func cb, const void *user_data);

void foo(const std::list<std::string>& accids)
{
    nim_user_get_user_name_card func = (nim_user_get_user_name_card) dlsym(hInst, "nim_user_get_user_name_card");

    Json::Value values;
    for (auto iter = accids.cbegin(); iter != accids.cend(); ++iter)
        values.append(*iter);

    Json::FastWriter fw;

    func(fw.write(values).c_str(), "", &CallbackGetUserNameCard, nullptr);
}

Get User Information on the server

User information is acquired from server and usually called when there is not local user information. After acquisition, SDK will update local database. 150 users can be acquired at most each time. The upper level may get user information in batch in the event of large quantity.

  • API prototype
/** @fn void nim_user_get_user_name_card_online(const char *accids, const char *json_extension, nim_user_get_user_name_card_cb_func cb, const void *user_data)
* Online query of user namecard of the specified account
* @param[in] accids e.g. ["litianyi01", "litianyi02", ...]
* @param[in] json_extension json extension parameter that is used in some cases
* @param[in] cb operation result callback
* @param[in] user_data APP's custom user data, which SDK is only responsible for passing back to the callback function cb (without any processing)
* @return void
* @note - Error code:200: Successful
* 414: Parameter error
* 419: Exceed limit
* 20000: Initialization is not executed or failed.
* 20001: Login is not executed or completed.
*/
NIM_SDK_DLL_API	void nim_user_get_user_name_card_online(const char *accids, const char *json_extension, nim_user_get_user_name_card_cb_func cb, const void *user_data);
  • Example
void CallbackGetUserNameCard(const char *result_json, const char *json_extension, const void *callback)
{
    // parse result_json
}

typedef void (*nim_user_get_user_name_card_online)(const char *accids, const char *json_extension, nim_user_get_user_name_card_cb_func cb, const void *user_data);

void foo(const std::list<std::string>& accids)
{
    nim_user_get_user_name_card_online func = (nim_user_get_user_name_card_online) dlsym(hInst, "nim_user_get_user_name_card_online");

    Json::Value values;
    for (auto iter = accids.cbegin(); iter != accids.cend(); ++iter)
        values.append(*iter);

    Json::FastWriter fw;

    func(fw.write(values).c_str(), "", &CallbackGetUserNameCard, nullptr);
}

Update Personal Information

  • API prototype
/** @fn void nim_user_update_my_user_name_card(const char *info_json, const char *json_extension, nim_user_update_my_name_card_cb_func cb, const void *user_data)
* Update your own namecard
* @param[in] info_json User information json
* @param[in] json_extension json extension parameter that is used in some cases
* @param[in] cb operation result callback
* @param[in] user_data APP's custom user data, which SDK is only responsible for passing back to the callback function cb (without any processing)
* @return void
* @note Error code	200: succeed
* 400: Illegal parameter
*/
NIM_SDK_DLL_API	void nim_user_update_my_user_name_card(const char *info_json, const char *json_extension, nim_user_update_my_name_card_cb_func cb, const void *user_data);
  • Example
void CallbackUpdateNameCard(int res_code, const char *json_extension, const void *callback)
{
    //Process operation results
}

typedef void (*nim_user_update_my_user_name_card)(const char *info_json, const char *json_extension, nim_user_update_my_name_card_cb_func cb, const void *user_data);

void foo()
{
    //change nickname
    Json::Value values;
    values[kUInfoKeyAccid] = "litianyi02";
    values[kUInfoKeyName] = "changed nickname";

    nim_user_update_my_user_name_card func = (nim_user_update_my_user_name_card) dlsym(hInst, "nim_user_update_my_user_name_card");
    func(values.toStyledString().c_str(), nullptr, &CallbackUpdateNameCard, nullptr);
}

Notification for User Information Change

The interface nim_user_reg_user_name_card_changed_cb is invoked to register callback, and results are acquired via callback function when the user information has any change.

  • API prototype
/** @fn void nim_user_reg_user_name_card_changed_cb(const char *json_extension, nim_user_name_card_change_cb_func cb, const void *user_data)
* (Global Callback) Uniformly registered callback function for notification of changes in user namecard
* @param[in] json_extension json extension parameter that is used in some cases
* @param[in] cb operation result callback
* @param[in] user_data APP's custom user data, which SDK is only responsible for passing back to the callback function cb (without any processing)
* @return void
*/
NIM_SDK_DLL_API	void nim_user_reg_user_name_card_changed_cb(const char *json_extension, nim_user_name_card_change_cb_func cb, const void *user_data);
  • Example
void CallbackUserNameCardChange(const char *result_json, const char *json_extension, const void *callback)
{
    // Parse result_json to get user information
}

typedef void (*nim_user_reg_user_name_card_changed_cb)(const char *json_extension, nim_user_name_card_change_cb_func cb, const void *user_data);

void foo()
{
    nim_user_reg_user_name_card_changed_cb func = (nim_user_reg_user_name_card_changed_cb) dlsym(hInst, "nim_user_reg_user_name_card_changed_cb");
    func("", &CallbackUserNameCardChange, nullptr);
}
Was this topic helpful?
Yes
No
  • Get User Information on Local Storage
  • Get User Information on the server
  • Update Personal Information
  • Notification for User Information Change