fetchUserList method
根据accIdList
批量获取用户信息
优先从缓存获取,失败则从服务端获取
不走数据库
Implementation
@override
Future<List<ContactInfo>> fetchUserList(List<String> accIdList) async {
final List<String> fetchList =
accIdList.where((element) => contactMap[element] == null).toList();
if (fetchList.isNotEmpty) {
int start = 0;
int end = fetchList.length > 150 ? 150 : fetchList.length;
while (start < fetchList.length) {
final fetchResult = await NimCore.instance.userService
.fetchUserInfoList(fetchList.sublist(start, end));
if (fetchResult.isSuccess && fetchResult.data != null) {
for (var e in fetchResult.data!) {
contactMap[e.userId!] = ContactInfo(e);
}
}
start = end;
end = start + 150;
if (end > fetchList.length) {
end = fetchList.length;
}
}
}
return accIdList.map((e) => contactMap[e]!).toList();
}