1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-26 21:08:52 +00:00
comunicmobile/lib/models/post.dart

92 lines
2.6 KiB
Dart
Raw Normal View History

2020-04-15 17:17:29 +00:00
import 'package:comunic/enums/likes_type.dart';
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';
2020-04-16 12:07:21 +00:00
import 'package:comunic/models/displayed_content.dart';
2019-05-18 14:04:21 +00:00
import 'package:comunic/models/like_element.dart';
2019-06-28 09:32:36 +00:00
import 'package:comunic/models/survey.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;
2020-04-16 12:07:21 +00:00
DisplayedString 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-06-28 09:32:36 +00:00
final Survey survey;
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,
2019-06-28 09:32:36 +00:00
@required this.comments,
@required this.survey})
2019-05-19 12:54:09 +00:00
: 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),
2019-06-28 09:32:36 +00:00
assert(kind != PostKind.SURVEY || survey != null),
2019-05-10 17:15:11 +00:00
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;
2020-04-16 12:07:21 +00:00
bool get hasContent => content != null && !content.isNull;
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-06-24 18:27:20 +00:00
bool get hasLinkImage => linkImage != null;
2019-05-19 12:54:09 +00:00
bool get canDelete =>
access == UserAccessLevels.FULL ||
access == UserAccessLevels.INTERMEDIATE;
2020-04-15 17:17:29 +00:00
@override
LikesType get likeType => LikesType.POST;
2019-05-10 17:15:11 +00:00
}