mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Cache groups informations
This commit is contained in:
		@@ -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(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user