1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/models/post.dart

81 lines
2.3 KiB
Dart
Raw Normal View History

2019-05-10 17:15:11 +00:00
import 'package:comunic/enums/post_kind.dart';
import 'package:comunic/enums/post_visibility_level.dart';
import 'package:comunic/enums/user_access_levels.dart';
2019-05-16 12:52:22 +00:00
import 'package:comunic/lists/comments_list.dart';
2019-05-18 14:04:21 +00:00
import 'package:comunic/models/like_element.dart';
2019-05-10 17:15:11 +00:00
import 'package:meta/meta.dart';
/// Single post information
///
/// @author Pierre HUBERT
2019-05-18 14:04:21 +00:00
class Post implements LikeElement {
2019-05-10 17:15:11 +00:00
final int id;
final int userID;
final int userPageID;
final int groupID;
final int timeSent;
2019-05-19 15:42:09 +00:00
String content;
2019-05-23 16:27:43 +00:00
PostVisibilityLevel visibilityLevel;
2019-05-10 17:15:11 +00:00
final PostKind kind;
final int fileSize;
final String fileType;
final String filePath;
final String fileURL;
final int timeEnd;
final String linkURL;
final String linkTitle;
final String linkDescription;
final String linkImage;
2019-05-11 13:35:07 +00:00
int likes;
2019-05-18 14:04:21 +00:00
bool userLike;
2019-05-10 17:15:11 +00:00
final UserAccessLevels access;
2019-05-16 12:52:22 +00:00
final CommentsList comments;
2019-05-10 17:15:11 +00:00
2019-05-19 12:54:09 +00:00
Post(
{@required this.id,
@required this.userID,
@required this.userPageID,
@required this.groupID,
@required this.timeSent,
@required this.content,
@required this.visibilityLevel,
@required this.kind,
@required this.fileSize,
@required this.fileType,
@required this.filePath,
@required this.fileURL,
@required this.timeEnd,
@required this.linkURL,
@required this.linkTitle,
@required this.linkDescription,
@required this.linkImage,
@required this.likes,
@required this.userLike,
@required this.access,
@required this.comments})
: assert(id != null),
2019-05-10 17:15:11 +00:00
assert(userID != null),
assert(userPageID != 0 || groupID != 0),
assert(timeSent != null),
assert(kind != PostKind.TEXT || content != null),
assert(visibilityLevel != null),
assert(kind != null),
assert(kind != PostKind.COUNTDOWN || timeEnd != null),
assert(likes != null),
2019-05-18 14:04:21 +00:00
assert(userLike != null),
2019-05-10 17:15:11 +00:00
assert(access != null);
2019-05-11 07:48:01 +00:00
2019-05-23 16:27:43 +00:00
bool get isGroupPost => groupID != null && groupID > 0;
2019-05-11 07:48:01 +00:00
bool get hasContent => content != null;
2019-05-16 12:52:22 +00:00
bool get hasComments => comments != null;
2019-05-19 12:54:09 +00:00
2019-05-19 15:42:09 +00:00
bool get canUpdate => access == UserAccessLevels.FULL;
2019-05-19 12:54:09 +00:00
bool get canDelete =>
access == UserAccessLevels.FULL ||
access == UserAccessLevels.INTERMEDIATE;
2019-05-10 17:15:11 +00:00
}