1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Cache groups informations

This commit is contained in:
Pierre HUBERT 2019-06-10 09:57:42 +02:00
parent ee864d3d98
commit 717ae3e316

View File

@ -32,13 +32,11 @@ const _APIGroupsPostsCreationLevelsMap = {
"members": GroupPostCreationLevel.MEMBERS "members": GroupPostCreationLevel.MEMBERS
}; };
final _groupsListCache = GroupsList();
class GroupsHelper { class GroupsHelper {
/// Get a list of groups from the server /// Download a list of groups information from the server
Future<GroupsList> getList(Set<int> groups) async { Future<GroupsList> _downloadList(Set<int> groups) async {
if(groups.length == 0)
return GroupsList();
final response = await APIRequest( final response = await APIRequest(
uri: "groups/get_multiple_info", uri: "groups/get_multiple_info",
needLogin: true, needLogin: true,
@ -56,6 +54,32 @@ class GroupsHelper {
return list; return list;
} }
/// Get a list of groups from the server
Future<GroupsList> getList(Set<int> groups, {bool force = false}) async {
final list = GroupsList();
// Check which groups information to download
final toDownload = Set<int>();
groups.forEach((groupID) {
if (_groupsListCache.containsKey(groupID))
list[groupID] = _groupsListCache[groupID];
else
toDownload.add(groupID);
});
// Download required groups information
if (toDownload.length > 0) {
final downloaded = await _downloadList(toDownload);
if (downloaded == null) return null;
list.addAll(downloaded);
_groupsListCache.addAll(downloaded);
}
return list;
}
/// Turn an API entry into a group object /// Turn an API entry into a group object
Group _getGroupFromAPI(Map<String, dynamic> map) { Group _getGroupFromAPI(Map<String, dynamic> map) {
return Group( return Group(