2020-05-05 16:49:50 +00:00
|
|
|
import 'package:comunic/models/conversation.dart';
|
|
|
|
import 'package:comunic/models/friend.dart';
|
|
|
|
|
|
|
|
/// Membership information
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
enum MembershipType { FRIEND, GROUP, CONVERSATION }
|
|
|
|
|
|
|
|
class Membership {
|
|
|
|
final MembershipType type;
|
2022-03-10 18:39:57 +00:00
|
|
|
final Conversation? conversation;
|
|
|
|
final Friend? friend;
|
|
|
|
final int? groupID;
|
|
|
|
final int? groupLastActive;
|
2020-05-05 16:49:50 +00:00
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
Membership.conversation(Conversation this.conversation)
|
2020-05-05 16:49:50 +00:00
|
|
|
: type = MembershipType.CONVERSATION,
|
|
|
|
friend = null,
|
|
|
|
groupID = null,
|
|
|
|
groupLastActive = null,
|
|
|
|
assert(conversation != null);
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
Membership.friend(Friend this.friend)
|
2020-05-05 16:49:50 +00:00
|
|
|
: type = MembershipType.FRIEND,
|
|
|
|
conversation = null,
|
|
|
|
groupID = null,
|
|
|
|
groupLastActive = null,
|
|
|
|
assert(friend != null);
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
Membership.group({required int this.groupID, required int this.groupLastActive})
|
2020-05-05 16:49:50 +00:00
|
|
|
: type = MembershipType.GROUP,
|
|
|
|
conversation = null,
|
|
|
|
friend = null,
|
|
|
|
assert(groupID != null),
|
|
|
|
assert(groupLastActive != null);
|
2020-05-05 17:33:04 +00:00
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
int? get lastActive {
|
2020-05-05 17:33:04 +00:00
|
|
|
switch (type) {
|
|
|
|
case MembershipType.FRIEND:
|
2022-03-10 18:39:57 +00:00
|
|
|
return friend!.lastActive;
|
2020-05-05 17:33:04 +00:00
|
|
|
case MembershipType.GROUP:
|
|
|
|
return groupLastActive;
|
|
|
|
case MembershipType.CONVERSATION:
|
2022-03-10 18:39:57 +00:00
|
|
|
return conversation!.lastActivity;
|
2020-05-05 17:33:04 +00:00
|
|
|
default:
|
|
|
|
throw Exception("Unreachable statment!");
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 16:49:50 +00:00
|
|
|
}
|