forked from eatvio/eatvio_app
feat(notifications): support payment-required and start-date-set types (#3054)
This commit is contained in:
@@ -1011,6 +1011,125 @@ class MealReminderNotification implements BaseNotificationModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// Данные уведомления: в API-ленте лежат во вложенном `data`, а в realtime-событии могут быть в корне.
|
||||
Map<String, dynamic> _notificationData(Map<String, dynamic> json) {
|
||||
final data = json['data'];
|
||||
return data is Map<String, dynamic> ? data : json;
|
||||
}
|
||||
|
||||
DateTime? parseOptionalDate(dynamic value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
final raw = value.toString();
|
||||
if (raw.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return DateTime.tryParse(raw)?.toLocal();
|
||||
}
|
||||
|
||||
class ClientPlanPaymentRequiredNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final NotificationType type;
|
||||
@override
|
||||
final bool isRead;
|
||||
final String planName;
|
||||
final int planId;
|
||||
final String authorName;
|
||||
final int authorId;
|
||||
final String authorPhotoPath;
|
||||
final String chatId;
|
||||
final String chatUrl;
|
||||
final DateTime? startDate;
|
||||
final DateTime? paymentDeadlineAt;
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
ClientPlanPaymentRequiredNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.planName,
|
||||
required this.planId,
|
||||
required this.authorName,
|
||||
required this.authorId,
|
||||
required this.authorPhotoPath,
|
||||
required this.chatId,
|
||||
required this.chatUrl,
|
||||
required this.startDate,
|
||||
required this.paymentDeadlineAt,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory ClientPlanPaymentRequiredNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
final data = _notificationData(json);
|
||||
return ClientPlanPaymentRequiredNotification(
|
||||
type: type,
|
||||
isRead: isRead ?? false,
|
||||
planName: data['plan_name'] ?? '',
|
||||
planId: data['plan_id'] ?? 0,
|
||||
authorName: data['author_name'] ?? '',
|
||||
authorId: data['author_id'] ?? 0,
|
||||
authorPhotoPath: data['author_photo_path'] ?? '',
|
||||
chatId: data['chat_id'] ?? '',
|
||||
chatUrl: data['chat_url'] ?? '',
|
||||
startDate: parseOptionalDate(data['start_date']),
|
||||
paymentDeadlineAt: parseOptionalDate(data['payment_deadline_at']),
|
||||
createdAt: parseDate(createdAt ?? json['created_at'] ?? data['created_at'] ?? DateTime.now().toIso8601String()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ConsultantPlanStartDateSetNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final NotificationType type;
|
||||
@override
|
||||
final bool isRead;
|
||||
final String planName;
|
||||
final int planId;
|
||||
final String clientName;
|
||||
final int userId;
|
||||
final String userPhotoPath;
|
||||
final String chatId;
|
||||
final String chatUrl;
|
||||
final DateTime? startDate;
|
||||
final DateTime? paymentDeadlineAt;
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
ConsultantPlanStartDateSetNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.planName,
|
||||
required this.planId,
|
||||
required this.clientName,
|
||||
required this.userId,
|
||||
required this.userPhotoPath,
|
||||
required this.chatId,
|
||||
required this.chatUrl,
|
||||
required this.startDate,
|
||||
required this.paymentDeadlineAt,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory ConsultantPlanStartDateSetNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
final data = _notificationData(json);
|
||||
return ConsultantPlanStartDateSetNotification(
|
||||
type: type,
|
||||
isRead: isRead ?? false,
|
||||
planName: data['plan_name'] ?? '',
|
||||
planId: data['plan_id'] ?? 0,
|
||||
clientName: data['user_name'] ?? '',
|
||||
userId: data['user_id'] ?? 0,
|
||||
userPhotoPath: data['user_photo_path'] ?? '',
|
||||
chatId: data['chat_id'] ?? '',
|
||||
chatUrl: data['chat_url'] ?? '',
|
||||
startDate: parseOptionalDate(data['start_date']),
|
||||
paymentDeadlineAt: parseOptionalDate(data['payment_deadline_at']),
|
||||
createdAt: parseDate(createdAt ?? json['created_at'] ?? data['created_at'] ?? DateTime.now().toIso8601String()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UnknownNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final NotificationType type;
|
||||
@@ -2476,6 +2595,8 @@ enum NotificationType {
|
||||
clientStartPlanSubscriptionToAuthor,
|
||||
clientCancelPlanSubscriptionToAuthor,
|
||||
clientCancelPlanSubscriptionToSubscriber,
|
||||
clientPlanPaymentRequired,
|
||||
consultantPlanStartDateSet,
|
||||
userDailyReportCompleted,
|
||||
chosenPlanFinishedToConsultant,
|
||||
stayOnTrackToCustomer,
|
||||
@@ -2597,6 +2718,8 @@ enum NotificationType {
|
||||
'client-start-plan-subscription-to-author' => NotificationType.clientStartPlanSubscriptionToAuthor,
|
||||
'client-cancel-plan-subscription-to-author' => NotificationType.clientCancelPlanSubscriptionToAuthor,
|
||||
'client-cancel-plan-subscription-to-subscriber' => NotificationType.clientCancelPlanSubscriptionToSubscriber,
|
||||
'client-plan-payment-required' => NotificationType.clientPlanPaymentRequired,
|
||||
'consultant-plan-start-date-set' => NotificationType.consultantPlanStartDateSet,
|
||||
'user-daily-report-completed' => NotificationType.userDailyReportCompleted,
|
||||
'chosen-plan-finished-to-consultant' => NotificationType.chosenPlanFinishedToConsultant,
|
||||
'stay-on-track-to-customer' => NotificationType.stayOnTrackToCustomer,
|
||||
|
||||
Reference in New Issue
Block a user