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';
|
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
|
|
|
/// Single user Friend information
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2019-05-04 17:35:03 +00:00
|
|
|
class Friend extends CacheModel implements Comparable<Friend> {
|
2019-05-01 15:52:41 +00:00
|
|
|
final bool accepted;
|
|
|
|
final int lastActive;
|
|
|
|
final bool following;
|
|
|
|
final bool canPostTexts;
|
|
|
|
|
2019-05-04 17:35:03 +00:00
|
|
|
const Friend({
|
|
|
|
@required int id,
|
2019-05-01 15:52:41 +00:00
|
|
|
@required this.accepted,
|
|
|
|
@required this.lastActive,
|
|
|
|
@required this.following,
|
|
|
|
@required this.canPostTexts,
|
|
|
|
}) : assert(id != null),
|
|
|
|
assert(accepted != null),
|
|
|
|
assert(lastActive != null),
|
|
|
|
assert(following != null),
|
2019-05-04 17:35:03 +00:00
|
|
|
assert(canPostTexts != null),
|
|
|
|
super(id: id);
|
2019-05-01 15:52:41 +00:00
|
|
|
|
|
|
|
/// Check out whether friend is connected or not
|
|
|
|
bool get isConnected => time() - 30 < lastActive;
|
2019-05-04 17:35:03 +00:00
|
|
|
|
|
|
|
@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);
|
2019-05-01 15:52:41 +00:00
|
|
|
}
|