2019-05-04 17:35:03 +00:00
|
|
|
import 'package:comunic/helpers/database/database_contract.dart';
|
|
|
|
import 'package:comunic/models/cache_model.dart';
|
2019-05-01 15:52:41 +00:00
|
|
|
import 'package:comunic/utils/date_utils.dart';
|
|
|
|
|
|
|
|
/// Single user Friend information
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2019-05-04 17:35:03 +00:00
|
|
|
class Friend extends CacheModel implements Comparable<Friend> {
|
2020-05-06 11:38:11 +00:00
|
|
|
bool accepted;
|
2022-03-10 18:39:57 +00:00
|
|
|
final int? lastActive;
|
2019-05-01 15:52:41 +00:00
|
|
|
final bool following;
|
|
|
|
final bool canPostTexts;
|
|
|
|
|
2020-05-06 11:38:11 +00:00
|
|
|
Friend({
|
2022-03-10 18:39:57 +00:00
|
|
|
required int id,
|
|
|
|
required this.accepted,
|
|
|
|
required int this.lastActive,
|
|
|
|
required this.following,
|
|
|
|
required this.canPostTexts,
|
2022-03-11 16:16:46 +00:00
|
|
|
}) : super(id: id);
|
2019-05-01 15:52:41 +00:00
|
|
|
|
|
|
|
/// Check out whether friend is connected or not
|
2022-03-10 18:39:57 +00:00
|
|
|
bool get isConnected => time() - 30 < lastActive!;
|
2019-05-04 17:35:03 +00:00
|
|
|
|
|
|
|
@override
|
2022-03-10 18:39:57 +00:00
|
|
|
int compareTo(Friend other) => other.lastActive!.compareTo(lastActive!);
|
2019-05-04 17:35:03 +00:00
|
|
|
|
|
|
|
@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)
|
2022-03-11 16:16:46 +00:00
|
|
|
: accepted = map[FriendsListTableContract.C_ACCEPTED] == 1,
|
2019-05-04 17:35:03 +00:00
|
|
|
lastActive = map[FriendsListTableContract.C_LAST_ACTIVE],
|
|
|
|
following = map[FriendsListTableContract.C_FOLLOWING] == 1,
|
|
|
|
canPostTexts = map[FriendsListTableContract.C_CAN_POST_TEXTS] == 1,
|
|
|
|
super.fromMap(map);
|
2019-05-01 15:52:41 +00:00
|
|
|
}
|