getContact method

  1. @override
Future<ContactInfo?> getContact(
  1. String accId, {
  2. bool needRefresh = false,
  3. bool needFriend = true,
})
override

返回特定用户的信息 优先从缓存获取,失败则从SDK数据库本地获取,最后从服务端获取 如果needRefresh为true,则从服务端获取 如果needFriend为true,则获取好友信息

Implementation

@override
Future<ContactInfo?> getContact(String accId,
    {bool needRefresh = false, bool needFriend = true}) async {
  if (!needRefresh && contactMap[accId] != null) {
    return contactMap[accId]!;
  }
  NIMUserInfo? user = await _getUser(accId, needRefresh: needRefresh);
  if (user != null) {
    ContactInfo? contactInfo;
    if (needFriend) {
      contactInfo = await _getFriend(user);
    } else {
      contactInfo = ContactInfo(user);
    }
    //重新设置是否在黑名单
    contactInfo?.isInBlack = contactMap[accId]?.isInBlack;
    //如果没有好友信息则使用原来的好友信息
    contactInfo?.friend ??= contactMap[accId]?.friend;
    contactMap[accId] = contactInfo;
    if (needRefresh && contactInfo != null) {
      _onContactUpdated.add(contactInfo);
    }
    return contactInfo;
  } else {
    return null;
  }
}