112 lines
3.5 KiB
Dart
112 lines
3.5 KiB
Dart
import '../utils/app_time.dart';
|
|
|
|
class Announcement {
|
|
Announcement({
|
|
required this.id,
|
|
required this.authorId,
|
|
required this.title,
|
|
required this.body,
|
|
required this.visibleRoles,
|
|
required this.isTemplate,
|
|
this.templateId,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
required this.bannerEnabled,
|
|
this.bannerShowAt,
|
|
this.bannerHideAt,
|
|
this.pushIntervalMinutes,
|
|
});
|
|
|
|
final String id;
|
|
final String authorId;
|
|
final String title;
|
|
final String body;
|
|
final List<String> visibleRoles;
|
|
final bool isTemplate;
|
|
final String? templateId;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
|
|
/// Whether a persistent banner is shown at the top of the announcements screen.
|
|
final bool bannerEnabled;
|
|
|
|
/// When the banner should start showing. [null] means immediately.
|
|
final DateTime? bannerShowAt;
|
|
|
|
/// When the banner should stop showing. [null] means it requires a manual
|
|
/// turn-off by the poster or an admin.
|
|
final DateTime? bannerHideAt;
|
|
|
|
/// How often (in minutes) a scheduled push notification is sent while the
|
|
/// banner is active. [null] means no scheduled push. Max is 1440 (daily).
|
|
final int? pushIntervalMinutes;
|
|
|
|
/// Whether the banner is currently active (visible) based on the current time.
|
|
bool get isBannerActive {
|
|
if (!bannerEnabled) return false;
|
|
final now = AppTime.now();
|
|
if (bannerShowAt != null && now.isBefore(bannerShowAt!)) return false;
|
|
if (bannerHideAt != null && now.isAfter(bannerHideAt!)) return false;
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Announcement &&
|
|
runtimeType == other.runtimeType &&
|
|
id == other.id &&
|
|
authorId == other.authorId &&
|
|
title == other.title &&
|
|
body == other.body &&
|
|
isTemplate == other.isTemplate &&
|
|
templateId == other.templateId &&
|
|
bannerEnabled == other.bannerEnabled &&
|
|
bannerShowAt == other.bannerShowAt &&
|
|
bannerHideAt == other.bannerHideAt &&
|
|
pushIntervalMinutes == other.pushIntervalMinutes &&
|
|
createdAt == other.createdAt &&
|
|
updatedAt == other.updatedAt;
|
|
|
|
@override
|
|
int get hashCode => Object.hash(
|
|
id,
|
|
authorId,
|
|
title,
|
|
body,
|
|
isTemplate,
|
|
templateId,
|
|
bannerEnabled,
|
|
bannerShowAt,
|
|
bannerHideAt,
|
|
pushIntervalMinutes,
|
|
createdAt,
|
|
updatedAt,
|
|
);
|
|
|
|
factory Announcement.fromMap(Map<String, dynamic> map) {
|
|
final rolesRaw = map['visible_roles'];
|
|
final roles = rolesRaw is List ? rolesRaw.cast<String>() : <String>[];
|
|
|
|
return Announcement(
|
|
id: map['id'] as String,
|
|
authorId: map['author_id'] as String,
|
|
title: map['title'] as String? ?? '',
|
|
body: map['body'] as String? ?? '',
|
|
visibleRoles: roles,
|
|
isTemplate: map['is_template'] as bool? ?? false,
|
|
templateId: map['template_id'] as String?,
|
|
createdAt: AppTime.parse(map['created_at'] as String),
|
|
updatedAt: AppTime.parse(map['updated_at'] as String),
|
|
bannerEnabled: map['banner_enabled'] as bool? ?? false,
|
|
bannerShowAt: map['banner_show_at'] != null
|
|
? AppTime.parse(map['banner_show_at'] as String)
|
|
: null,
|
|
bannerHideAt: map['banner_hide_at'] != null
|
|
? AppTime.parse(map['banner_hide_at'] as String)
|
|
: null,
|
|
pushIntervalMinutes: map['push_interval_minutes'] as int?,
|
|
);
|
|
}
|
|
}
|