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:
		@@ -1,3 +1,5 @@
 | 
			
		||||
import 'package:comunic/helpers/database/database_contract.dart';
 | 
			
		||||
import 'package:comunic/models/cache_model.dart';
 | 
			
		||||
import 'package:comunic/utils/date_utils.dart';
 | 
			
		||||
import 'package:meta/meta.dart';
 | 
			
		||||
 | 
			
		||||
@@ -5,15 +7,14 @@ import 'package:meta/meta.dart';
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class Friend {
 | 
			
		||||
  final int id;
 | 
			
		||||
class Friend extends CacheModel implements Comparable<Friend> {
 | 
			
		||||
  final bool accepted;
 | 
			
		||||
  final int lastActive;
 | 
			
		||||
  final bool following;
 | 
			
		||||
  final bool canPostTexts;
 | 
			
		||||
 | 
			
		||||
  Friend({
 | 
			
		||||
    @required this.id,
 | 
			
		||||
  const Friend({
 | 
			
		||||
    @required int id,
 | 
			
		||||
    @required this.accepted,
 | 
			
		||||
    @required this.lastActive,
 | 
			
		||||
    @required this.following,
 | 
			
		||||
@@ -22,8 +23,29 @@ class Friend {
 | 
			
		||||
        assert(accepted != null),
 | 
			
		||||
        assert(lastActive != null),
 | 
			
		||||
        assert(following != null),
 | 
			
		||||
        assert(canPostTexts != null);
 | 
			
		||||
        assert(canPostTexts != null),
 | 
			
		||||
        super(id: id);
 | 
			
		||||
 | 
			
		||||
  /// Check out whether friend is connected or not
 | 
			
		||||
  bool get isConnected => time() - 30 < lastActive;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  int compareTo(Friend other) => other.lastActive.compareTo(lastActive);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Map<String, dynamic> toMap() => {
 | 
			
		||||
        FriendsListTableContract.C_ID: id.toString(),
 | 
			
		||||
        FriendsListTableContract.C_ACCEPTED: accepted ? 1 : 0,
 | 
			
		||||
        FriendsListTableContract.C_LAST_ACTIVE: lastActive,
 | 
			
		||||
        FriendsListTableContract.C_FOLLOWING: following ? 1 : 0,
 | 
			
		||||
        FriendsListTableContract.C_CAN_POST_TEXTS: canPostTexts ? 1 : 0
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
  Friend.fromMap(Map<String, dynamic> map)
 | 
			
		||||
      : assert(map != null),
 | 
			
		||||
        accepted = map[FriendsListTableContract.C_ACCEPTED] == 1,
 | 
			
		||||
        lastActive = map[FriendsListTableContract.C_LAST_ACTIVE],
 | 
			
		||||
        following = map[FriendsListTableContract.C_FOLLOWING] == 1,
 | 
			
		||||
        canPostTexts = map[FriendsListTableContract.C_CAN_POST_TEXTS] == 1,
 | 
			
		||||
        super.fromMap(map);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user