用户关系托管

SDK 提供了用户好友关系管理,以及对用户会话的消息设置。在网易云通信中,不是好友也允许聊天。好友关系如果不托管给网易云通信,开发者需要自己在应用服务器维护。

添加/被添加,请求/被请求,删除/被删除的通知以及多端同步等通知通过注册的好友数据变更通知回调告知APP:

例:

C++

void OnFriendListChange(const nim::FriendChangeEvent& change_event)
{
    switch (change_event.type_)
    {
    case nim::kNIMFriendChangeTypeDel:
    {
        break;
    }
    case nim::kNIMFriendChangeTypeRequest:
    {
        break;
    }
    case nim::kNIMFriendChangeTypeSyncList:
    {
        break;
    }
    case nim::kNIMFriendChangeTypeUpdate:
    {
        break;
    }
    default:
        break;
    }
}

void foo()
{
    //向SDK注册监听好友列表变化
    nim::Friend::RegChangeCb(&OnFriendListChange);
}

C#

void OnFriendChanged(object sender, NIM.Friend.NIMFriendProfileChangedArgs args)
{
    if (args.ChangedInfo == null)
        return;

    if (args.ChangedInfo.ChangedType == NIM.Friend.NIMFriendChangeType.kNIMFriendChangeTypeDel)
    {

    }
    if (args.ChangedInfo.ChangedType == NIM.Friend.NIMFriendChangeType.kNIMFriendChangeTypeRequest)
    {

    }
    if (args.ChangedInfo.ChangedType == NIM.Friend.NIMFriendChangeType.kNIMFriendChangeTypeSyncList)
    {

    }
    if (args.ChangedInfo.ChangedType == NIM.Friend.NIMFriendChangeType.kNIMFriendChangeTypeUpdate)
    {

    }
}

void foo()
{
    NIM.Friend.FriendAPI.FriendProfileChangedHandler += OnFriendChanged;
}

C

void CallbackFriendChange(NIMFriendChangeType type, const char *result_json, const char *json_extension, const void *user_data)
{
    switch (type)
    {
        case kNIMFriendChangeTypeRequest:
            // 解析result_json
            break;
        case kNIMFriendChangeTypeDel:
            // 解析result_json
            break;
        ...
}

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

void foo()
{
    nim_friend_reg_changed_cb func = (nim_friend_reg_changed_cb) GetProcAddress(hInst, "nim_friend_reg_changed_cb");
    func("", &CallbackFriendChange, nullptr);
}

好友关系

黑名单

网易云通信中,黑名单和用户关系是互相独立的,即修改用户关系不会影响黑名单关系,同时,修改黑名单也不会对用户关系进行操作。

黑名单列表有本地缓存,缓存会在手动/自动登录后与服务器自动进行同步更新。通过注册用户关系变更通知回调获取当前数据变化:

例:

C++

void OnMuteBlackEventCallback(const nim::SpecialRelationshipChangeEvent& change_event)
{
    switch (change_event.type_)
    {
    case nim::NIMUserSpecialRelationshipChangeType::kNIMUserSpecialRelationshipChangeTypeMarkBlack:
    {
        break;
    }
    case nim::NIMUserSpecialRelationshipChangeType::kNIMUserSpecialRelationshipChangeTypeMarkMute:
    {
        break;
    }
    case nim::NIMUserSpecialRelationshipChangeType::kNIMUserSpecialRelationshipChangeTypeSyncMuteAndBlackList:
    {
        break;
    }
    }
}

void foo()
{
    nim::User::RegSpecialRelationshipChangedCb(&OnMuteBlackEventCallback);
}

C#

void OnUserRelationshipSync(object sender, UserRelationshipSyncArgs e)
{
    if (e.Items == null)
        return;
}

void OnUserRelationshipChanged(object sender, UserRelationshipChangedArgs e)
{
    if (e.ChangedType == NIMUserRelationshipChangeType.AddRemoveBlacklist)
    {
    }
}

void foo()
{
    NIM.User.UserAPI.UserRelationshipListSyncHander += OnUserRelationshipSync;
    NIM.User.UserAPI.UserRelationshipChangedHandler += OnUserRelationshipChanged;
}

C

void CallbackUserRelationshipChanged(NIMUserSpecialRelationshipChangeType type, const char *result_json ,const char *json_extension, const void *user_data)
{
    switch (type)
    {
        case kNIMUserSpecialRelationshipChangeTypeMarkBlack:
            //解析result_json
            break;
        case kNIMUserSpecialRelationshipChangeTypeMarkMute:
            //解析result_json
            break;
        ...
    }
}

typedef    void (*nim_user_reg_special_relationship_changed_cb)(const char *json_extension, nim_user_special_relationship_change_cb_func cb, const void *user_data);

void foo()
{
    nim_user_reg_special_relationship_changed_cb func = (nim_user_reg_special_relationship_changed_cb) GetProcAddress(hInst, "nim_user_reg_special_relationship_changed_cb");
    func(nullptr, &CallbackUserRelationshipChanged, nullptr);
}

消息提醒

网易云通信中,可以单独设置是否开启某个用户的消息提醒,即对某个用户静音。静音关系和用户关系是互相独立的,修改用户关系不会影响静音关系,同时,修改静音关系也不会对用户关系进行操作。

静音名单列表有本地缓存,缓存会在手动/自动登录后与服务器自动进行同步更新。通过注册用户关系变更通知回调获取当前数据变化:

C++

void OnMuteBlackEventCallback(const nim::SpecialRelationshipChangeEvent& change_event)
{
    switch (change_event.type_)
    {
    case nim::NIMUserSpecialRelationshipChangeType::kNIMUserSpecialRelationshipChangeTypeMarkBlack:
    {
        break;
    }
    case nim::NIMUserSpecialRelationshipChangeType::kNIMUserSpecialRelationshipChangeTypeMarkMute:
    {
        break;
    }
    case nim::NIMUserSpecialRelationshipChangeType::kNIMUserSpecialRelationshipChangeTypeSyncMuteAndBlackList:
    {
        break;
    }
    }
}

void foo()
{
    nim::User::RegSpecialRelationshipChangedCb(&OnMuteBlackEventCallback);
}

C#

void OnUserRelationshipSync(object sender, UserRelationshipSyncArgs e)
{
    if (e.Items == null)
        return;
}

void OnUserRelationshipChanged(object sender, UserRelationshipChangedArgs e)
{
    if (e.ChangedType == NIMUserRelationshipChangeType.AddRemoveBlacklist)
    {
    }
}

void foo()
{
    NIM.User.UserAPI.UserRelationshipListSyncHander += OnUserRelationshipSync;
    NIM.User.UserAPI.UserRelationshipChangedHandler += OnUserRelationshipChanged;
}

C

void CallbackUserRelationshipChanged(NIMUserSpecialRelationshipChangeType type, const char *result_json ,const char *json_extension, const void *user_data)
{
    switch (type)
    {
        case kNIMUserSpecialRelationshipChangeTypeMarkBlack:
            //解析result_json
            break;
        case kNIMUserSpecialRelationshipChangeTypeMarkMute:
            //解析result_json
            break;
        ...
    }
}

typedef    void (*nim_user_reg_special_relationship_changed_cb)(const char *json_extension, nim_user_special_relationship_change_cb_func cb, const void *user_data);

void foo()
{
    nim_user_reg_special_relationship_changed_cb func = (nim_user_reg_special_relationship_changed_cb) GetProcAddress(hInst, "nim_user_reg_special_relationship_changed_cb");
    func(nullptr, &CallbackUserRelationshipChanged, nullptr);
}