2021-04-23 17:32:34 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
2019-06-10 07:47:02 +00:00
|
|
|
|
|
|
|
/// Group information
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
|
|
|
enum GroupMembershipLevel {
|
|
|
|
ADMINISTRATOR,
|
|
|
|
MODERATOR,
|
|
|
|
MEMBER,
|
|
|
|
INVITED,
|
|
|
|
PENDING,
|
|
|
|
VISITOR
|
|
|
|
}
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
String membershipToText(GroupMembershipLevel level) {
|
2021-04-25 15:06:28 +00:00
|
|
|
switch (level) {
|
|
|
|
case GroupMembershipLevel.ADMINISTRATOR:
|
2022-03-10 18:39:57 +00:00
|
|
|
return tr("Administrator")!;
|
2021-04-25 15:06:28 +00:00
|
|
|
case GroupMembershipLevel.MODERATOR:
|
2022-03-10 18:39:57 +00:00
|
|
|
return tr("Moderator")!;
|
2021-04-25 15:06:28 +00:00
|
|
|
case GroupMembershipLevel.MEMBER:
|
2022-03-10 18:39:57 +00:00
|
|
|
return tr("Member")!;
|
2021-04-25 15:06:28 +00:00
|
|
|
case GroupMembershipLevel.INVITED:
|
2022-03-10 18:39:57 +00:00
|
|
|
return tr("Invited")!;
|
2021-04-25 15:06:28 +00:00
|
|
|
case GroupMembershipLevel.PENDING:
|
2022-03-10 18:39:57 +00:00
|
|
|
return tr("Requested")!;
|
2021-04-25 15:06:28 +00:00
|
|
|
case GroupMembershipLevel.VISITOR:
|
2022-03-10 18:39:57 +00:00
|
|
|
return tr("Visitor")!;
|
2021-04-25 15:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 07:47:02 +00:00
|
|
|
enum GroupVisibilityLevel { OPEN, PRIVATE, SECRETE }
|
|
|
|
|
|
|
|
enum GroupRegistrationLevel { OPEN, MODERATED, CLOSED }
|
|
|
|
|
|
|
|
enum GroupPostCreationLevel { MODERATORS, MEMBERS }
|
|
|
|
|
2021-04-22 13:15:40 +00:00
|
|
|
class Group implements Comparable<Group> {
|
2019-06-10 07:47:02 +00:00
|
|
|
final int id;
|
2020-05-01 13:39:54 +00:00
|
|
|
String name;
|
2020-04-15 10:04:19 +00:00
|
|
|
final String iconURL;
|
2019-06-10 07:47:02 +00:00
|
|
|
final int numberMembers;
|
2020-04-15 11:56:59 +00:00
|
|
|
GroupMembershipLevel membershipLevel;
|
2020-05-01 18:52:24 +00:00
|
|
|
GroupVisibilityLevel visibilityLevel;
|
2020-05-01 19:04:50 +00:00
|
|
|
GroupRegistrationLevel registrationLevel;
|
2020-05-01 19:13:31 +00:00
|
|
|
GroupPostCreationLevel postCreationLevel;
|
2020-05-01 18:10:25 +00:00
|
|
|
String virtualDirectory;
|
2020-04-15 16:39:07 +00:00
|
|
|
bool following;
|
2019-06-10 07:47:02 +00:00
|
|
|
|
|
|
|
Group({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.id,
|
|
|
|
required this.name,
|
|
|
|
required this.iconURL,
|
|
|
|
required this.numberMembers,
|
|
|
|
required this.membershipLevel,
|
|
|
|
required this.visibilityLevel,
|
|
|
|
required this.registrationLevel,
|
|
|
|
required this.postCreationLevel,
|
|
|
|
required this.virtualDirectory,
|
|
|
|
required this.following,
|
2022-03-11 16:13:54 +00:00
|
|
|
});
|
2019-06-10 07:47:02 +00:00
|
|
|
|
|
|
|
get displayName => this.name;
|
2020-04-15 16:06:20 +00:00
|
|
|
|
2020-04-15 16:39:07 +00:00
|
|
|
bool get isAtLeastMember =>
|
2020-04-15 16:06:20 +00:00
|
|
|
membershipLevel == GroupMembershipLevel.ADMINISTRATOR ||
|
|
|
|
membershipLevel == GroupMembershipLevel.MODERATOR ||
|
|
|
|
membershipLevel == GroupMembershipLevel.MEMBER;
|
2020-04-16 06:52:26 +00:00
|
|
|
|
2020-05-01 13:12:55 +00:00
|
|
|
bool get isAdmin => membershipLevel == GroupMembershipLevel.ADMINISTRATOR;
|
|
|
|
|
2020-05-02 07:57:33 +00:00
|
|
|
bool get isAtLeastModerator =>
|
|
|
|
membershipLevel == GroupMembershipLevel.ADMINISTRATOR ||
|
|
|
|
membershipLevel == GroupMembershipLevel.MODERATOR;
|
|
|
|
|
2020-04-16 06:52:26 +00:00
|
|
|
bool get canCreatePost =>
|
|
|
|
membershipLevel == GroupMembershipLevel.ADMINISTRATOR ||
|
|
|
|
membershipLevel == GroupMembershipLevel.MODERATOR ||
|
|
|
|
(membershipLevel == GroupMembershipLevel.MEMBER &&
|
|
|
|
postCreationLevel == GroupPostCreationLevel.MEMBERS);
|
2021-04-22 13:15:40 +00:00
|
|
|
|
2021-04-25 15:06:28 +00:00
|
|
|
String get membershipText => membershipToText(membershipLevel);
|
2021-04-23 17:32:34 +00:00
|
|
|
|
2021-04-22 13:15:40 +00:00
|
|
|
@override
|
|
|
|
int compareTo(Group other) => id.compareTo(other.id);
|
2019-06-10 07:47:02 +00:00
|
|
|
}
|