//先获取数据,设置回调
c
///获取好友资料
getUserArchivesInfo(int? userId,
{Function(bool isCache, ArchivesInfo archivesInfo)? onSuccess,
Function(String error)? onError}) {
RxHttp<ArchivesInfo>()
..init()
..setBaseUrl(Api.BASE_API)
..setPath(Api.GET_OTHER_ARCHIVES_INFO)
..setCacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
..setParams({"user_id": userId})
..setJsonTransFrom((data) {
PrintUtil.prints('$TAG 获取好友资料 ===> $data');
return ArchivesInfo.fromJson(json.decoder.convert(data)['data']);
})
..call(
NetCallback(onNetFinish: (archivesInfo) {
if (onSuccess != null) {
CacheFileString().loadStringAsync(archivesInfo.avatar ?? '');
CacheFileString().loadStringAsync(archivesInfo.avatarThumb ?? '');
archivesInfo.userIMID = '${archivesInfo.userID}';
archivesInfo.conversationID = 'c2c_${archivesInfo.userID}';
onSuccess(false, archivesInfo);
}
}, onCacheFinish: (archivesInfo) {
if (onSuccess != null) {
onSuccess(true, archivesInfo);
}
}, onNetError: (errorCode, error) {
if (onError != null) {
onError('$error ($errorCode)');
}
}),
server: Servers.microServices);
}
//在回调处处理数据和刷新页面
c
///获取好友的档案资料
_getOtherArchivesInfo() {
WsImUserInfoUtil().getUserArchivesInfo(int.parse(userID),
onSuccess: (isCache, archivesInfo) {
if (!isCache) {
WsImDBUtil().updateUserInfo('c2c_$userID', archivesInfo, false);
}
print('回调了多少次');
setOtherArchivesInfo(archivesInfo);
}, onError: (error) {
showToast(error);
});
}
//处理数据的方法
c
setOtherArchivesInfo(data) {
mySetState(() {
// archivesInfo = ArchivesInfo.fromJson(data);
archivesInfo = data;
String photoIds = '';
String videoIds = '';
if (archivesInfo != null) {
if (archivesInfo!.photos != null) {
for (int i = 0; i < archivesInfo!.photos!.length; i++) {
if (i == archivesInfo!.photos!.length - 1) {
photoIds += '${archivesInfo!.photos![i].photoId}';
} else {
photoIds += '${archivesInfo!.photos![i].photoId},';
}
}
}
if (archivesInfo!.videos != null) {
for (int i = 0; i < archivesInfo!.videos!.length; i++) {
if (i == archivesInfo!.videos!.length - 1) {
videoIds += '${archivesInfo!.videos![i].videoId}';
} else {
videoIds += '${archivesInfo!.videos![i].videoId},';
}
}
}
}
if (photoIds != '') {
_getPhotoState(archivesInfo!.photos!, photoIds);
}
if (videoIds != '') {
_getVideoState(archivesInfo!.videos!, videoIds);
}
});
}