1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 16:26:27 +00:00
comunicmobile/lib/models/post.dart

85 lines
2.4 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';
2022-03-18 17:45:58 +00:00
import 'package:comunic/utils/account_utils.dart' as account;
2019-05-10 17:15:11 +00:00
/// 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;
2019-05-10 17:15:11 +00:00
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;
final CommentsList? comments;
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,
required this.comments,
required this.survey})
2022-03-11 16:09:37 +00:00
: assert(userPageID != 0 || groupID != 0),
2019-05-10 17:15:11 +00:00
assert(kind != PostKind.COUNTDOWN || timeEnd != null),
2022-03-11 16:09:37 +00:00
assert(kind != PostKind.SURVEY || survey != null);
2019-05-11 07:48:01 +00:00
bool get isGroupPost => groupID != null && groupID! > 0;
2019-05-23 16:27:43 +00:00
2022-03-11 16:09:37 +00:00
bool get hasContent => !content.isNull && !content.isEmpty;
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
2022-03-18 17:45:58 +00:00
bool get isOwner => userID == account.userID();
2020-04-15 17:17:29 +00:00
@override
LikesType get likeType => LikesType.POST;
2019-05-10 17:15:11 +00:00
}