Instant Messaging
Windows/macOS
Quick Start
Product Description
Overview
Features
Limits
Feature overview
Account Integration and Login
Messaging
Team
Chat Room
Chat Room Tags
Multi-device Login
Statistics Monitoring
Development Integration
Overview
Integration mode
Initialization
Login and Logout
Messaging
Recent Chats
History
Host user information
Host user relationship
Team Chat
Superteam
Chat room
System Notification
Event Subscription
Audio Recording and Playback
Document Conversion
API References
Status Codes
Reference Documents
Instructions for Upgrading
Development Example
Windows UI Library Tutorial
Package and Release
Description of class and constant definitions

Host user information

Update time: 2021/12/03 17:30:37

Hosting user profile

Overview

The SDK supports the management of a user profiles. The following interface is valid only when CommsEase is preferred to host the user profile. Developers must manage their user profiles if they do not want CommsEase to store the user profiles.

The field kUInfoKeyXXX of a user profile is defined in nim_user_def.h.

The app will be notified of a user profile changes by calling back the registered full notification for user profile change:

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 orprofile picture is changed
    			···;
    		if (info.ExistValue((nim::UserNameCardValueKey)(nim::kUserNameCardKeyAll - nim::kUserNameCardKeyName - nim::kUserNameCardKeyIconUrl))) //other user profile is changed
    			···;
    	}
    }
    
    void foo()
    {
    	//Register with the SDK to observe user name card changes
    	nim::User::RegUserNameCardChangedCb(&OnUserInfoChange);
    }

C#

    void OnUserNameCardChanged(object sender, UserNameCardChangedArgs e)
    {
            
    }
    
    void foo()
    {
    	NIM.User.UserAPI.UserNameCardChangedHandler += OnUserNameCardChanged;
    }

C

    void CallbackUserNameCardChange(const char *result_json, const char *json_extension, const void *callback)
    {
    	// parse result_json
    }
    
    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) GetProcAddress(hInst, "nim_user_reg_user_name_card_changed_cb");
    	func("", &CallbackUserNameCardChange, nullptr);
    }

Get local user profiles

C++

    void OnGetUserCard(const std::list<nim::UserNameCard> &json_result)
    {
    	for (auto& info : json_result)
    	{
    		···
    	}
    }
    
    void foo()
    {
    	std::list<std::string> account_list;
    	account_list.push_back("test1");
    	account_list.push_back("test2");
    	nim::User::GetUserNameCard(account_list, &OnGetUserCard);
    }

C#

    UserAPI.GetUserNameCard(new List<string>() {"test1", "test2"}, (ret) =>
    {
        if (ret.Any())
        {
            
        }
    });

C

    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) GetProcAddress(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 profiles on the server

The maximum number of users per query is 150.

C++

    void OnGetUserCard(const std::list<nim::UserNameCard> &json_result)
    {
    	for (auto& info : json_result)
    	{
    		···
    	}
    }
    
    void foo()
    {
    	std::list<std::string> account_list;
    	account_list.push_back("test1");
    	account_list.push_back("test2");
    	nim::User::GetUserNameCardOnline(account_list, &OnGetUserCard);
    }

C#

    NIM.User.UserAPI.QueryUserNameCardOnline(new List<string>() {"test1", "test2"}, (ret) =>
    {
        if (ret == null || !ret.Any())
        {
            return;
        }
     
    });

C

    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) GetProcAddress(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);
    }

Edit user profiles

Example:

C++

    void OnUpdateMyInfo(nim::NIMResCode res) 
    {
    	if (res == nim::kNIMResSuccess)
    	{
    		
    	}
    }
    
    void foo()
    {
    	nim::UserNameCard info;
    	info.SetName("new_name");
    	nim::User::UpdateMyUserNameCard(info, &OnUpdateMyInfo);
    }

C#

    void foo()
    {
    	NIM.User.UserNameCard user_card = new NIM.User.UserNameCard;
    	user_card.display name = "new_name";
    	NIM.User.UserAPI.UpdateMyCard(user_card, (a) =>
    	{
    	    if (a == NIM.ResponseCode.kNIMResSuccess)
    	    {
    	        MessageBox.Show("updated successfully");
    	    }
    	    else
    	    {
    	        MessageBox.Show("updated unsuccessfully");
    	    }
    	});
    }

C

    void CallbackUpdateNameCard(int res_code, const char *json_extension, const void *callback)
    {
    	if (res_code == kNIMResSuccess)
    	...
    	else
    	...
    }
    
    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 profile name
    	Json::Value values;
    	values[kUInfoKeyAccid] = "litianyi02";
    	values[kUInfoKeyName] = "changed profile name";
    
    	nim_user_update_my_user_name_card func = (nim_user_update_my_user_name_card) GetProcAddress(hInst, "nim_user_update_my_user_name_card");
    	func(values.toStyledString().c_str(), nullptr, &CallbackUpdateNameCard, nullptr);
    }
Was this topic helpful?
Yes
No
  • Hosting user profile
  • Overview
  • Get local user profiles
  • Get user profiles on the server
  • Edit user profiles