iOS

身份组相关查询

更新时间: 2024/03/14 17:08:36

服务器身份组相关查询

查询服务器身份组列表

调用getServerRoles:completion:通过分页方式查询服务器身份组列表,查询结果按照身份组优先级从大到小排序。查询参数中priority设为0,会从最大优先级开始返回,也就是第一页。第一页查询结果还会额外包含 @everyone 身份组,放在返回列表的第一项。

  • API 原型

    - (void)getServerRoles:(NIMQChatGetServerRolesParam *)param
                    completion:(nullable NIMQChatGetServerRolesHandler)completion;
    

    其中NIMQChatGetServerRolesParam参数说明如下:

    参数 类型 必填 说明
    serverId unsigned long long 服务器 ID
    priority unsigned long long 分页锚点优先级(即每页的页尾数据的优先级),填 0 从最高优先级开始查询
    limit NSInteger 查询数量限制。第一页返回结果额外包含@ everyone身份组,自定义身份组数量充足的情况下会返回 limit+1 个身份组
    categoryId unsigned long long 以频道分组 ID 的名义查询。如果传入该参数,则只需要有该频道分组的频道管理权限(NIMQChatPermissionTypeManageChannel)即可,否则需要有服务器的管理权限(NIMQChatPermissionTypeManageServer
    channelId unsigned long long 以频道 ID 的名义查询。如果传入该参数,则只需要拥有该频道的管理权限(NIMQChatPermissionTypeManageChannel)即可,否则需要有服务器的管理权限(NIMQChatPermissionTypeManageServer
  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetServerRolesParam *param = [[NIMQChatGetServerRolesParam alloc] init];
    param.serverId = 123456;
    param.limit = 20;
    param.priority = @(2);
    param.channelId = 5423642;
    [qchatRoleManager getServerRoles:param
                completion:^(NSError *__nullable error, NIMQChatGetServerRolesResult *__nullable result) {
        // your code
    }];
    

查询服务器身份组的成员列表

可调用 getServerRoleMembers: completion:方法分页查询某服务器身份组下的的成员列表。

该方法仅支持查询自定义身份组下的成员列表。创建服务器时默认创建的 @everyone 身份组不支持调用该方法进行查询。 如调用该方法查询 @everyone 身份组的成员, 将报错(错误码 403)。

  • API 原型

    - (void)getServerRoleMembers:(NIMQChatGetServerRoleMembersParam *)param
                        completion:(nullable NIMQChatGetServerRoleMembersHandler)completion;
    

    其中 >NIMQChatGetServerRoleMembersParam需要传入服务器 ID、服务器身份组ID、查询锚点时间戳和查询数量限制。其中查询下一页时需要传入查询锚点的 accid

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetServerRoleMembersParam *param = [[NIMQChatGetServerRoleMembersParam alloc] init];
    param.serverId = 123456;
    param.roleId = 111;
    param.timeTag = 0;
    param.accid = @"yunxin1";
    param.limit = 20;
    [qchatRoleManager getServerRoleMembers:param
                    completion:^(NSError *__nullable error, NIMQChatGetServerRoleMembersResult *__nullable result) {
        // your code
    }];
    

查询用户的服务器身份组列表

调用getServerRolesByAccid:completion:方法,可根据某用户的accid分页查询该用户所属的服务器身份组列表。

查询结果只会返回自定义身份组,不包含 @everyone 身份组。

  • API 原型

    - (void)getServerRolesByAccid:(NIMQChatGetServerRolesByAccidParam *)param
                        completion:(nullable NIMQChatGetServerRolesByAccidHandler)completion;
    

    其中NIMQChatGetServerRolesByAccidParam需要传入服务器ID、用户的 IM 账号(accid)、查询锚点时间戳和查询数量限制。

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetServerRolesByAccidParam *param = [[NIMQChatGetServerRolesByAccidParam alloc] init];
    param.serverId = 123456;
    param.accid = @"yunxin1";
    param.timeTag = 0;
    param.limit = 20;
    [qchatRoleManager getServerRolesByAccid:param
                    completion:^(NSError *__nullable error, NIMQChatGetServerRolesByAccidResult *__nullable result) {
        // your code
    }];
    

批量查询某些用户的服务器身份组列表

调用getExistingServerRolesByAccids:completion:方法,可通过一批用户的accid查询这些用户所属的自定义服务器身份组列表。

  • 查询结果只会返回自定义身份组,不包含@everyone身份组。
  • 单次调用该方法最多可传入 100 个 accid
  • API 原型

    - (void)getExistingServerRolesByAccids:(NIMQChatGetExistingServerRolesByAccidsParam *)param
                        completion:(nullable NIMQChatGetExistingServerRolesByAccidsHandler)completion;
    
  • 示例代码

    - (void)testGetExistingServerRolesByAccids {
    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetExistingServerRolesByAccidsParam *param = [[NIMQChatGetExistingServerRolesByAccidsParam alloc] init];
    param.serverId = 123456;
    param.accids = @[@"yunxin1", @"yunxin2", @"yunxin3"];
    [qchatRoleManager getExistingServerRolesByAccids:param
                                completion:^(NSError *__nullable error, NIMQChatGetExistingServerRolesByAccidsResult *__nullable result) {
        // your code
    }];
    
    

批量查询某些用户是否为指定服务器身份组成员

调用getExistingAccidsInServerRole方法,可查询一批 accids 是否在某个服务器身份组,并返回存在于该身份组的成员信息。

  • API 原型

    - (void)getExistingServerRoleMembersByAccids:(NIMQChatGetExistingServerRoleMembersByAccidsParam *)param
                        completion:(nullable NIMQChatGetExistingServerRoleMembersByAccidsHandler)completion;
    

    其中NIMQChatGetExistingServerRoleMembersByAccidsParam需要传入需要查询的服务器 ID、服务器身份组 ID 和 accid 列表。

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetExistingServerRoleMembersByAccidsParam *param = [[NIMQChatGetExistingServerRoleMembersByAccidsParam alloc] init];
    param.serverId = 123456;
    param.roleId = 53455;
    param.accids = @[@"yunxin1", @"yunxin2", @"yunxin3"];
    
    [qchatRoleManager getExistingServerRoleMembersByAccids:param
                completion:^(NSError *__nullable error, NIMQChatGetExistingServerRoleMembersByAccidsResult *__nullable result) {
        // your code
    }];
    

频道身份组相关查询

查询频道身份组列表

调用getChannelRoles:completion:方法可查询某频道下的身份组列表。

  • API 原型

    - (void)getChannelRoles:(NIMQChatGetChannelRolesParam *)param
                    completion:(nullable NIMQChatGetChannelRolesHandler)completion;
    

    其中NIMQChatGetChannelRolesParam需要传入查询的serverIdchannelId、查询锚点时间戳 timeTag 和查询数量限制 limit

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetChannelRolesParam *param = [[NIMQChatGetChannelRolesParam alloc] init];
    param.serverId = 123456;
    param.channelId = 121212;
    param.timeTag = 0;
    param.limit = 20;
    [qchatRoleManager getChannelRoles:param
                completion:^(NSError *__nullable error, NIMQChatGetChannelRolesResult *__nullable result) {
        // your code
    }];
    

根据一批服务器身份组查询相应的频道身份组

调用getExistingChannelRolesByServerRoleIds:completion:方法,可通过传入一组服务器身份组 ID 查询这些服务器身份组被继承到的频道身份组列表。

  • API 原型

    - (void)getExistingChannelRolesByServerRoleIds:(NIMQChatGetExistingChannelRolesByServerRoleIdsParam *)param
                        completion:(nullable NIMQChatGetExistingChannelRolesByServerRoleIdsHandler)completion;
    
    

    其中NIMQChatGetExistingChannelRolesByServerRoleIdsParam需要传入需要查询的serverIdchannelId和身份组 ID 列表。

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetExistingChannelRolesByServerRoleIdsParam *param = [[NIMQChatGetExistingChannelRolesByServerRoleIdsParam alloc] init];
    param.serverId = 123456;
    param.channelId = 121212;
    param.roleIds = @[@(111), @(222), @(333)];
    [qchatRoleManager getExistingChannelRolesByServerRoleIds:param
                                        completion:^(NSError *__nullable error, NIMQChatGetExistingChannelRolesByServerRoleIdsResult *__nullable result) {
        // your code
    }];
    

用户定制权限相关查询

查询频道成员的定制权限

调用getMemberRoles:completion:方法,分页查询某频道下某个成员的定制权限列表。

该方法需要拥有 NIMQChatPermissionTypeManageRole 权限才能调用。

  • API 原型

    - (void)getMemberRoles:(NIMQChatGetMemberRolesParam *)param
                completion:(nullable NIMQChatGetMemberRolesHandler)completion;
    

    其中NIMQChatGetMemberRolesParam需要传入服务器 ID、频道 ID、查询锚点时间戳和查询数量限制。

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetMemberRolesParam *param = [[NIMQChatGetMemberRolesParam alloc] init];
    param.serverId = 123456;
    param.channelId = 121212;
    param.timeTag = 0;
    param.limit = 20;
    [qchatRoleManager getMemberRoles:param
                completion:^(NSError *__nullable error, NIMQChatGetMemberRolesResult *__nullable result) {
        // your code
    }];
    
    

批量查询某些用户是否配置定制权限

调用getExistingAccidsOfMemberRoles:completion:方法,可通过传入用户的accid列表查询这些accid对应的用户是否拥有该频道下的成员定制权限。

  • API 原型

    /**
     * 查询一批accids在频道中配置了权限的,只会返回存在的
     *
     * @param param 传入参数
     * @param completion 结果回调
     */
    - (void)getExistingAccidsOfMemberRoles:(NIMQChatGetExistingAccidsOfMemberRolesParam *)param
                     completion:(nullable NIMQChatGetExistingAccidsOfMemberRolesHandler)completion;
    

    其中NIMQChatGetExistingAccidsOfMemberRolesParam需要传入需要查询的serverIdchannelIdaccid列表。

  • 示例代码

    id<NIMQChatRoleManager> qchatRoleManager = [[NIMSDK sharedSDK] qchatRoleManager];
    NIMQChatGetExistingAccidsOfMemberRolesParam *param = [[NIMQChatGetExistingAccidsOfMemberRolesParam alloc] init];
    param.serverId = 123456;
    param.channelId = 121212;
    param.accids = @[@"yunxin1", @"yunxin2", @"yunxin3"];
    [qchatRoleManager getExistingAccidsOfMemberRoles:param
                                        completion:^(NSError *__nullable error, NIMQChatGetExistingAccidsOfMemberRolesResult *__nullable result) {
        // your code
    }];
    

查询自己拥有的权限

查询自己是否拥有某个权限

调用checkPermission:completion:方法,可通过传入某个身份组权限资源项查询自己是否拥有某个权限。

  • API 原型

    - (void)checkPermission:(NIMQChatCheckPermissionParam *)param
                        completion:(nullable NIMQChatCheckPermissionHandler)completion;
    

    其中NIMQChatCheckPermissionParam需要传入需要查询的serverIdchannelId(可选)和身份组权限资源项。

    身份组权限资源项NIMQChatPermissionType会区分权限是否为服务器专有。如果查询服务器专有的权限,则NIMQChatCheckPermissionParam中的channelId不需要传,其他情况则channelId必须要传。

  • 示例代码

    NIMQChatCheckPermissionParam *param = [[NIMQChatCheckPermissionParam alloc] init];
    param.serverId = 62363463;
    // channelId为可选,如果不传,则查server权限;否则查channel权限
    param.channelId = 645374;
    param.permissionType = NIMQChatPermissionTypeKickOthersInServer;
    
    [[NINSDK sharedSDK].qchatServerManager checkPermission:param completion:^{
        //code here
    }];
    

查询自己是否拥有某些权限

调用checkPermissions:completion:方法查询自己是否拥有某些权限。

单次最多可查 10 个权限。

  • API 原型

    - (void)checkPermissions:(NIMQChatCheckPermissionsParam *)param
                        completion:(nullable NIMQChatCheckPermissionsHandler)completion;
    

    其中NIMQChatCheckPermissionsParam中需要传入需要查询的serverIdchannelId(可选)和身份组权限资源项。

    身份组权限资源项NIMQChatPermissionType会区分权限是否为服务器专有。如果查询服务器专有的权限,则NIMQChatCheckPermissionParam中的channelId不需要传,其他情况则channelId必须要传。

  • 示例代码

    NIMQChatCheckPermissionsParam *param = [[NIMQChatCheckPermissionsParam alloc] init];
    param.serverId = 1432214;
    param.channelId = 543252;
    param.permissions = @[@(NIMQChatPermissionTypeRemindAll), @(NIMQChatPermissionTypeManageServer), @(NIMQChatPermissionTypeManageBlackWhiteList)];
    
    [[NIMSDK sharedSDK].qchatRoleManager checkPermissions:param completion:^(NSError * _Nullable error, NIMQChatCheckPermissionsResult * _Nullable result) {
        //your code
    }];
    
此文档是否对你有帮助?
有帮助
去反馈
  • 服务器身份组相关查询
  • 查询服务器身份组列表
  • 查询服务器身份组的成员列表
  • 查询用户的服务器身份组列表
  • 批量查询某些用户的服务器身份组列表
  • 批量查询某些用户是否为指定服务器身份组成员
  • 频道身份组相关查询
  • 查询频道身份组列表
  • 根据一批服务器身份组查询相应的频道身份组
  • 用户定制权限相关查询
  • 查询频道成员的定制权限
  • 批量查询某些用户是否配置定制权限
  • 查询自己拥有的权限
  • 查询自己是否拥有某个权限
  • 查询自己是否拥有某些权限