mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Cache the list of friends
This commit is contained in:
		@@ -47,7 +47,13 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
 | 
			
		||||
  @override
 | 
			
		||||
  void didChangeDependencies() {
 | 
			
		||||
    super.didChangeDependencies();
 | 
			
		||||
    _loadList();
 | 
			
		||||
    _getList();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Initialize list retrieving
 | 
			
		||||
  Future<void> _getList() async {
 | 
			
		||||
    await _loadList(false);
 | 
			
		||||
    await _loadList(true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Refresh the list of friends
 | 
			
		||||
@@ -56,11 +62,14 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Load the list of friends
 | 
			
		||||
  Future<void> _loadList() async {
 | 
			
		||||
  Future<void> _loadList(bool online) async {
 | 
			
		||||
    error = _ErrorsLevel.NONE;
 | 
			
		||||
 | 
			
		||||
    // Get the list of friends
 | 
			
		||||
    final list = await _friendsHelper.downloadList();
 | 
			
		||||
    final list = await _friendsHelper.getList(online: online);
 | 
			
		||||
 | 
			
		||||
    // Check if there is no cache yet
 | 
			
		||||
    if(!online && list.isEmpty) return;
 | 
			
		||||
 | 
			
		||||
    // Check for errors
 | 
			
		||||
    if (list == null) return _gotError();
 | 
			
		||||
@@ -73,7 +82,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
 | 
			
		||||
 | 
			
		||||
    // Apply new information
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _friendsList = list;
 | 
			
		||||
      _friendsList = list..sort();
 | 
			
		||||
      _usersInfo = users;
 | 
			
		||||
    });
 | 
			
		||||
    error = _ErrorsLevel.NONE;
 | 
			
		||||
@@ -107,7 +116,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
 | 
			
		||||
        Expanded(
 | 
			
		||||
          child: RefreshIndicator(
 | 
			
		||||
            key: _refreshIndicatorKey,
 | 
			
		||||
            onRefresh: _loadList,
 | 
			
		||||
            onRefresh: () => _loadList(true),
 | 
			
		||||
            child: ListView.builder(
 | 
			
		||||
                physics: AlwaysScrollableScrollPhysics(),
 | 
			
		||||
                itemCount: _friendsList.length,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user