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 Relationship Management

Update time: 2021/09/25 21:39:36

SDK supports user relationship (friends) management and message settings for user sessions. CommsEase allows chats between users who are not friends. User relationship not managed by CommsEase needs to be maintained by the developer on the application server.

Notifications are returned to the client by registering the nim_friend_reg_changed_cb callback when a user adds friends or is added, requests or is requested, deletes friends or is deleted.

void nim_friend_reg_changed_cb(const char *json_extension, nim_friend_change_cb_func cb, const void *user_data);

Friendship

  • Get friends list
void nim_friend_get_list(const char *json_extension, nim_friend_get_list_cb_func cb, const void *user_data);
  • Friend request

    There are two types of friend request, namely friend request and accept/reject friend request.

    The friend verification covers "directly add as friends" (kNIMVerifyTypeAdd Verification not required) and "request for adding friends" (kNIMVerifyTypeAsk Verification required), and can carry client custom message to complete additional feature, for example, the feature of adding friend postscript.

    Use the callback function to get notified about the result of interface call. Take a friend request that does not require verification as an example:

    void CallbackFriendOpt(int res_code, const char *json_extension, const void *user_data)
    {
        //Process operation results
    }
    
    void foo()
    {
        nim_friend_request("id", kNIMVerifyTypeAdd, NULL, NULL, &CallbackFriendOpt, NULL);
    }
    

    If friend verification mode is "verification required" (kNIMVerifyTypeAsk), when the other party receives the message, he can accept (kNIMVerifyTypeAgree)or reject (kNIMVerifyTypeReject) friend request. Similarly, now the interface nim_friend_request can be invoked to input ID of rejected object and verify reply type.

  • Delete friend

    void nim_friend_delete(const char *accid, const char *json_extension, nim_friend_opt_cb_func cb, const void *user_data);
    
  • Update information

    void CallbackFriendOpt(int res_code, const char *json_extension, const void *user_data)
    {
        //Process operation results
    }
    
    void foo()
    {
        //Update alias of a friend
        Json::Value friend_profile_json;
        friend_profile_json[kNIMFriendKeyAccid] = "accid";
        friend_profile_json[kNIMFriendKeyAlias] = "alias_name";
        Json::FastWriter fw;
    
        nim_friend_update(fw.write(friend_profile_json).c_str(), NULL, &CallbackFriendOpt, NULL);
    }
    
  • Query user relationship

    nim_friend_query_friendship_blockQuery that a designated account is my friend in locally cached data

Blacklist

In CommsEase, blacklist and user relationship are independent of each other, so updating either of the two won't affect the other.

Local cache is available for blacklist, and will be synced and updated automatically with the server after manual/auto login. Get the current data changes by registering callbacknim_user_reg_special_relationship_changed_cb of user relationship change notification.

  • Get blacklist

    void nim_user_get_mute_blacklist(const char *json_extension, nim_user_sync_muteandblacklist_cb_func cb, const void *user_data);
    
  • Add to/Remove from the blacklist

    void nim_user_set_black(const char *accid, bool set_black, const char *json_extension, nim_user_opt_cb_func cb, const void *user_data);
    

Message Reminder

CommsEase contains setting option on whether to enable reminder for individual user's message (i.e. mute or unmute the user). Mute and user relationship are mutually independent, so updating either of the two won't affect the other.

Local cache is available for mute list, and will be synced and updated automatically with the server after manual/auto login. Get the current data changes by registering callbacknim_user_special_relationship_change_cb_func of user relationship change notification.

  • Add to/remove from mute list

    void nim_user_set_mute(const char *accid, bool set_mute, const char *json_extension, nim_user_opt_cb_func cb, const void *user_data);
    
  • Get mute list

    void nim_user_get_mute_blacklist(const char *json_extension, nim_user_sync_muteandblacklist_cb_func cb, const void *user_data);
    
Was this topic helpful?
Yes
No
  • Friendship
  • Blacklist
  • Message Reminder