2020-04-15 19:17:29 +02:00
|
|
|
import 'package:comunic/enums/likes_type.dart';
|
2019-05-10 19:15:11 +02: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 14:52:22 +02:00
|
|
|
import 'package:comunic/lists/comments_list.dart';
|
2020-04-16 14:07:21 +02:00
|
|
|
import 'package:comunic/models/displayed_content.dart';
|
2019-05-18 16:04:21 +02:00
|
|
|
import 'package:comunic/models/like_element.dart';
|
2019-06-28 11:32:36 +02:00
|
|
|
import 'package:comunic/models/survey.dart';
|
2022-03-18 18:45:58 +01:00
|
|
|
import 'package:comunic/utils/account_utils.dart' as account;
|
2019-05-10 19:15:11 +02:00
|
|
|
|
|
|
|
/// Single post information
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2019-05-18 16:04:21 +02:00
|
|
|
class Post implements LikeElement {
|
2019-05-10 19:15:11 +02:00
|
|
|
final int id;
|
|
|
|
final int userID;
|
2022-03-10 19:39:57 +01:00
|
|
|
final int? userPageID;
|
|
|
|
final int? groupID;
|
2019-05-10 19:15:11 +02:00
|
|
|
final int timeSent;
|
2020-04-16 14:07:21 +02:00
|
|
|
DisplayedString content;
|
2019-05-23 18:27:43 +02:00
|
|
|
PostVisibilityLevel visibilityLevel;
|
2019-05-10 19:15:11 +02:00
|
|
|
final PostKind kind;
|
2022-03-10 19:39:57 +01:00
|
|
|
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 15:35:07 +02:00
|
|
|
int likes;
|
2019-05-18 16:04:21 +02:00
|
|
|
bool userLike;
|
2019-05-10 19:15:11 +02:00
|
|
|
final UserAccessLevels access;
|
2022-03-10 19:39:57 +01:00
|
|
|
final CommentsList? comments;
|
|
|
|
Survey? survey;
|
2019-05-10 19:15:11 +02:00
|
|
|
|
2019-05-19 14:54:09 +02:00
|
|
|
Post(
|
2022-03-10 19:39:57 +01:00
|
|
|
{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 17:09:37 +01:00
|
|
|
: assert(userPageID != 0 || groupID != 0),
|
2019-05-10 19:15:11 +02:00
|
|
|
assert(kind != PostKind.COUNTDOWN || timeEnd != null),
|
2022-03-11 17:09:37 +01:00
|
|
|
assert(kind != PostKind.SURVEY || survey != null);
|
2019-05-11 09:48:01 +02:00
|
|
|
|
2022-03-10 19:39:57 +01:00
|
|
|
bool get isGroupPost => groupID != null && groupID! > 0;
|
2019-05-23 18:27:43 +02:00
|
|
|
|
2022-03-11 17:09:37 +01:00
|
|
|
bool get hasContent => !content.isNull && !content.isEmpty;
|
2019-05-16 14:52:22 +02:00
|
|
|
|
|
|
|
bool get hasComments => comments != null;
|
2019-05-19 14:54:09 +02:00
|
|
|
|
2019-05-19 17:42:09 +02:00
|
|
|
bool get canUpdate => access == UserAccessLevels.FULL;
|
|
|
|
|
2019-06-24 20:27:20 +02:00
|
|
|
bool get hasLinkImage => linkImage != null;
|
|
|
|
|
2019-05-19 14:54:09 +02:00
|
|
|
bool get canDelete =>
|
|
|
|
access == UserAccessLevels.FULL ||
|
|
|
|
access == UserAccessLevels.INTERMEDIATE;
|
2020-04-15 19:17:29 +02:00
|
|
|
|
2022-03-18 18:45:58 +01:00
|
|
|
bool get isOwner => userID == account.userID();
|
|
|
|
|
2020-04-15 19:17:29 +02:00
|
|
|
@override
|
|
|
|
LikesType get likeType => LikesType.POST;
|
2019-05-10 19:15:11 +02:00
|
|
|
}
|