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