Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface FriendInterface

好友相关 API

Hierarchy

  • FriendInterface

Implemented by

Index

Methods

  • addFriend(options: { account: string; ps?: string; done?: any }): void
  • applyFriend(options: { account: string; ps?: string; done?: any }): void
  • deleteFriend(options: { account: string; delAlias?: boolean; done?: any }): void
  • getFriends(options: { updateTime?: number; done?: any }): void
  • 如果开发者在初始化SDK的时候设置了syncFriends为false, 那么就收不到onfriends回调, 可以调用此接口来获取好友列表

    注:由于 v8.9.0 之后好友数量上限变为 10000,远端协议不允许一口气下发 10000 个。想要一口气获取有两种手段:

    1. 如果开发者使用数据库,那么此接口将会返回所有数据库中有效的,且 updateTime > options.updateTime 的好友记录

    2. 如果开发者不使用数据库,那么使用此接口,传入时间戳,将会从服务器获取 updateTime > options.timetag 的 3000 条记录,分页逻辑请自行处理。

    示例

    nim.getFriends({
    updateTime: 0,
    done: function(err, friends) {
    if (err) {
    console.log('获取好友列表失败', err)
    } else {
    console.log('获取好友列表成功', friends)
    }
    }
    })

    Parameters

    Returns void

  • getFriendsFromDB(options: { accountIds?: string[]; done?: any }): void
  • 从数据库中批量获取好友信息, 不限个数

    注: indexDB 数据库专用接口.

    Parameters

    • options: { accountIds?: string[]; done?: any }
      • Optional accountIds?: string[]

        账号 id 列表. 不传则忽略这个过滤条件

        示例

        nim.getFriendsFromDB({
        accountIds: ['user1', 'user2'],
        done: function(err, friends) {
        if (err) {
        console.log('从数据库获取好友失败', err)
        } else {
        console.log('从数据库获取好友成功', friends)
        }
        }
        })
      • done?:function

    Returns void

  • isMyFriend(options: { account: string; done?: any }): void
  • 是否为我的好友

    注:该接口需要数据库支持,若没有开启本地数据库能力,done 回调里只会返回 false

    示例

    nim.isMyFriend({
    account: 'user1',
    done: function(err, isFriend) {
    if (err) {
    console.log('查询好友状态失败', err)
    } else {
    console.log('是否为我的好友:', isFriend)
    }
    }
    })

    Parameters

    Returns void

  • passFriendApply(options: { account: string; idServer?: string; ps?: string; done?: any }): void
  • rejectFriendApply(options: { account: string; idServer?: string; ps?: string; done?: any }): void
  • updateFriend(options: { account: string; alias?: string; custom?: string; done?: any }): void
  • 更新好友的备注和扩展字段。多端登录设备会收到 onsyncfriendaction 回调

    关联函数

    示例场景

    示例

    nim.updateFriend({
    account: 'user1',
    alias: '小明',
    custom: JSON.stringify({ group: 'work' }),
    done: function(err) {
    if (err) {
    console.log('更新好友备注失败', err)
    } else {
    console.log('更新好友备注成功')
    }
    }
    })

    Parameters

    • options: { account: string; alias?: string; custom?: string; done?: any }
      • account: string
      • Optional alias?: string

        备注

      • Optional custom?: string

        扩展字段, 选填, 开发者也可以使用JSON格式的字符串来扩展此内容

      • done?:function

    Returns void