Host User Information

Update time: 2021/09/25 13:59:39

Overview

CommsEase provides user information hosting, which covers birthday, email, gender, mobile number, signature and extension field. The following interfaces are only valid when CommsEase is allowed to manage user data. If developers do not want CommsEase to obtain their own user data, they need to maintain the data by themselves.

Get User Information on Local Storage

  • API prototype
c++/** @fn static bool GetUserNameCard(const std::list<std::string>& accids, const GetUserNameCardCallback& cb, const std::string& json_extension = "")
* Get the namecard of the specified local account
* @param[in] accids user id list
* @param[in] cb operation result callback
* @param[in] json_extension json extension parameter is not required in some cases
* @return void No value is returned
* @note error code 200: success
* 414: Parameter error
*/
static bool GetUserNameCard(const std::list<std::string>& accids, const GetUserNameCardCallback& cb, const std::string& json_extension = "");
  • Example
c++void OnGetUserCard(const std::list<nim::UserNameCard> &result)
{
    for (auto& info : result)
    {
        //Process user information
    }
}

void foo()
{
    std::list<std::string> account_list;
    account_list.push_back("test1");
    account_list.push_back("test2");
    nim::User::GetUserNameCard(account_list, &OnGetUserCard);
}

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
c++/** @fn static bool GetUserNameCardOnline(const std::list<std::string>& accids, const GetUserNameCardCallback& cb, const std::string& json_extension = "")
* Online query of user namecard of the specified account
* @param[in] accids user id list
* @param[in] cb operation result callback
* @param[in] json_extension json extension parameter is not required in some cases
* @return bool Return "failure" if the checked parameter does not conform
* @note error code 200: success
* 414: Parameter error
* 419: Overflow
*/
static bool GetUserNameCardOnline(const std::list<std::string>& accids, const GetUserNameCardCallback& cb, const std::string& json_extension = "");
  • Example
c++void OnGetUserCard(const std::list<nim::UserNameCard> &result)
{
    for (auto& info : result)
    {
        //Process user information
    }
}

void foo()
{
    std::list<std::string> account_list;
    account_list.push_back("test1");
    account_list.push_back("test2");
    nim::User::GetUserNameCardOnline(account_list, &OnGetUserCard);
}

Update Personal Information

To update your user information, first construct thenim::UserNameCardobject, then set the attributes that need to be updated, after that, callnim::User::UpdateMyUserNameCardto perform the update.

  • API prototype
c++/** @fn static bool UpdateMyUserNameCard(const UserNameCard& namecard, const UpdateMyUserNameCardCallback& cb, const std::string& json_extension = "")
* Update your own namecard
* @param[in] namecard contents
* @param[in] cb operation result callback
* @param[in] json_extension json extension parameter is not required in some cases
* @return bool Return "failure" if the checked parameter does not conform
* @note Error code	200: success
* 400: Illegal parameter
*/
static bool UpdateMyUserNameCard(const UserNameCard& namecard, const UpdateMyUserNameCardCallback& cb, const std::string& json_extension = "");
  • Example
c++void OnUpdateMyInfo(nim::NIMResCode res)
{
    if (res == nim::kNIMResSuccess)
    {
        //Information updated successfully
    }
}

void foo()
{
    nim::UserNameCard info;
    //Set attributes
    info.SetName("new_name");
    nim::User::UpdateMyUserNameCard(info, &OnUpdateMyInfo);
}

Notification of User Information Update

The APP will be notified of user information change by calling the callback registered vianim::User::RegUserNameCardChangedCbfor user information change:

  • API prototype
c++/** @fn static void RegUserNameCardChangedCb(const UserNameCardChangedCallback& cb, const std::string& json_extension = "")
* (Global Callback) Uniformly registered callback function for notification of changes in user namecard
* @param[in] cb operation result callback
* @param[in] json_extension json extension parameter is not required in some cases
* @return void No value is returned
*/
static void RegUserNameCardChangedCb(const UserNameCardChangedCallback& cb, const std::string& json_extension = "");
  • Example
c++void OnUserInfoChange(const std::list<nim::UserNameCard> &uinfo_list)
{
    for (auto& info : uinfo_list)
    {
        if (info.ExistValue(nim::kUserNameCardKeyName) || info.ExistValue(nim::kUserNameCardKeyIconUrl)) //user name or avatar is changed
            //TODO
        if (info.ExistValue((nim::UserNameCardValueKey)(nim::kUserNameCardKeyAll - nim::kUserNameCardKeyName - nim::kUserNameCardKeyIconUrl))) //other user information is changed
            //TODO
    }
}

void foo()
{
    //Register with the SDK to observe user name card changes
    nim::User::RegUserNameCardChangedCb(&OnUserInfoChange);
}
Was this page helpful?
Yes
No
  • Overview
  • Get User Information on Local Storage
  • Get User Information on the server
  • Update Personal Information
  • Notification of User Information Update