mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Make use of cached user information
This commit is contained in:
parent
de1ef7fd6d
commit
f8298919c2
@ -11,14 +11,13 @@ import 'package:comunic/models/user.dart';
|
|||||||
/// @author Pierre HUBERT
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
class UsersHelper {
|
class UsersHelper {
|
||||||
|
|
||||||
final UsersDatabaseHelper _usersDatabaseHelper = UsersDatabaseHelper();
|
final UsersDatabaseHelper _usersDatabaseHelper = UsersDatabaseHelper();
|
||||||
|
|
||||||
/// Download information about some given users ID
|
/// Download information about some given users ID
|
||||||
///
|
///
|
||||||
/// Return the list of users information in case of success, null in case of
|
/// Return the list of users information in case of success, null in case of
|
||||||
/// failure
|
/// failure
|
||||||
Future<UsersList> downloadInfo(List<int> users) async {
|
Future<UsersList> _downloadInfo(List<int> users) async {
|
||||||
// Execute the request
|
// Execute the request
|
||||||
final response = await APIRequest(
|
final response = await APIRequest(
|
||||||
uri: "user/getInfoMultiple", args: {"usersID": users.join(",")}).exec();
|
uri: "user/getInfoMultiple", args: {"usersID": users.join(",")}).exec();
|
||||||
@ -51,4 +50,35 @@ class UsersHelper {
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get users information
|
||||||
|
///
|
||||||
|
/// If [forceDownload] is set to true, the data will always be retrieved from
|
||||||
|
/// the server, otherwise cached data will be used if available
|
||||||
|
Future<UsersList> getUsersInfo(List<int> users,
|
||||||
|
{bool forceDownload = false}) async {
|
||||||
|
|
||||||
|
List<int> toDownload = List();
|
||||||
|
UsersList list = UsersList();
|
||||||
|
|
||||||
|
// Check cache
|
||||||
|
for(int userID in users){
|
||||||
|
if(!forceDownload && await _usersDatabaseHelper.has(userID))
|
||||||
|
list.add(await _usersDatabaseHelper.get(userID));
|
||||||
|
else
|
||||||
|
toDownload.add(userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process download if required
|
||||||
|
if(toDownload.length > 0) {
|
||||||
|
final downloadedList = await _downloadInfo(toDownload);
|
||||||
|
|
||||||
|
if(downloadedList == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
list.addAll(downloadedList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class _ConversationScreenState extends State<ConversationsScreen> {
|
|||||||
if (list == null) return _gotLoadingError();
|
if (list == null) return _gotLoadingError();
|
||||||
|
|
||||||
//Get information about the members of the conversations
|
//Get information about the members of the conversations
|
||||||
list.users = await _usersHelper.downloadInfo(list.allUsersID);
|
list.users = await _usersHelper.getUsersInfo(list.allUsersID);
|
||||||
if(list.users == null) return _gotLoadingError();
|
if(list.users == null) return _gotLoadingError();
|
||||||
|
|
||||||
//Save list
|
//Save list
|
||||||
|
Loading…
Reference in New Issue
Block a user