1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-22 22:43:22 +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
};
final _groupsListCache = GroupsList();
class GroupsHelper {
/// Get a list of groups from the server
Future<GroupsList> getList(Set<int> groups) async {
if(groups.length == 0)
return GroupsList();
/// Download a list of groups information from the server
Future<GroupsList> _downloadList(Set<int> groups) async {
final response = await APIRequest(
uri: "groups/get_multiple_info",
needLogin: true,
@ -56,6 +54,32 @@ class GroupsHelper {
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
Group _getGroupFromAPI(Map<String, dynamic> map) {
return Group(