forked from eatvio/eatvio_app
feat(notifications): added push notifications navigation handling and fixed ws notification parsing
This commit is contained in:
@@ -166,13 +166,7 @@ class DiaryReminderNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
DiaryReminderNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
this.diaryId,
|
||||
this.message,
|
||||
required this.createdAt,
|
||||
});
|
||||
DiaryReminderNotification({required this.type, required this.isRead, this.diaryId, this.message, required this.createdAt});
|
||||
|
||||
factory DiaryReminderNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return DiaryReminderNotification(
|
||||
@@ -581,6 +575,22 @@ class ComplaintToModerationForUser implements BaseNotificationModel {
|
||||
}
|
||||
}
|
||||
|
||||
enum CommentedEntityType {
|
||||
diet,
|
||||
blogPost,
|
||||
unknown;
|
||||
|
||||
factory CommentedEntityType.fromJson(String type) {
|
||||
return switch (type) {
|
||||
'diet' => CommentedEntityType.diet,
|
||||
'Modules\\UserGeneratedPublicContent\\Models\\Diet' => CommentedEntityType.diet,
|
||||
'blog-post' => CommentedEntityType.blogPost,
|
||||
'Modules\\UserGeneratedPublicContent\\Models\\BlogPost' => CommentedEntityType.blogPost,
|
||||
_ => CommentedEntityType.unknown,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class CommentReplied implements BaseNotificationModel {
|
||||
@override
|
||||
final NotificationType type;
|
||||
@@ -588,7 +598,7 @@ class CommentReplied implements BaseNotificationModel {
|
||||
final bool isRead;
|
||||
final String entityName;
|
||||
final int commentedEntityId;
|
||||
final String commentedEntityType;
|
||||
final CommentedEntityType commentedEntityType;
|
||||
final String author;
|
||||
final int authorId;
|
||||
final int parentCommentId;
|
||||
@@ -614,7 +624,7 @@ class CommentReplied implements BaseNotificationModel {
|
||||
type: type,
|
||||
entityName: json['entity_name'],
|
||||
commentedEntityId: json['commented_entity_id'],
|
||||
commentedEntityType: json['commented_entity_type'],
|
||||
commentedEntityType: CommentedEntityType.fromJson(json['commented_entity_type']),
|
||||
author: json['author'],
|
||||
authorId: json['author_id'],
|
||||
parentCommentId: json['parrent_comment_id'],
|
||||
@@ -673,7 +683,7 @@ class EntityCommented implements BaseNotificationModel {
|
||||
final bool isRead;
|
||||
final String entityName;
|
||||
final int entityId;
|
||||
final String entityType;
|
||||
final CommentedEntityType entityType;
|
||||
final String entityTranslatedType;
|
||||
final String entityUrl;
|
||||
final String authorName;
|
||||
@@ -703,7 +713,7 @@ class EntityCommented implements BaseNotificationModel {
|
||||
type: type,
|
||||
entityName: json['entity_name'],
|
||||
entityId: json['entity_id'],
|
||||
entityType: json['entity_type'],
|
||||
entityType: CommentedEntityType.fromJson(json['entity_type']),
|
||||
entityTranslatedType: json['entity_traslated_type'],
|
||||
entityUrl: json['entity_url'],
|
||||
authorName: json['author_name'],
|
||||
@@ -1012,11 +1022,7 @@ class UnknownNotification implements BaseNotificationModel {
|
||||
UnknownNotification({required this.type, this.isRead = true, required this.createdAt});
|
||||
|
||||
factory UnknownNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return UnknownNotification(
|
||||
type: type,
|
||||
isRead: isRead ?? false,
|
||||
createdAt: parseDate(createdAt ?? json['created_at'] ?? DateTime.now().toIso8601String()),
|
||||
);
|
||||
return UnknownNotification(type: type, isRead: isRead ?? false, createdAt: parseDate(createdAt ?? json['created_at'] ?? DateTime.now().toIso8601String()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1889,12 +1895,7 @@ class ClientCloseComplaintSuccessNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
ClientCloseComplaintSuccessNotification({
|
||||
required this.type,
|
||||
required this.planName,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
});
|
||||
ClientCloseComplaintSuccessNotification({required this.type, required this.planName, required this.isRead, required this.createdAt});
|
||||
|
||||
factory ClientCloseComplaintSuccessNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return ClientCloseComplaintSuccessNotification(
|
||||
@@ -2001,13 +2002,7 @@ class ConsultantRejectSuccessNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
ConsultantRejectSuccessNotification({
|
||||
required this.type,
|
||||
required this.planName,
|
||||
required this.clientName,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
});
|
||||
ConsultantRejectSuccessNotification({required this.type, required this.planName, required this.clientName, required this.isRead, required this.createdAt});
|
||||
|
||||
factory ConsultantRejectSuccessNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return ConsultantRejectSuccessNotification(
|
||||
@@ -2115,13 +2110,7 @@ class DiaryReminderForUsersNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
DiaryReminderForUsersNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
this.diaryId,
|
||||
this.message,
|
||||
required this.createdAt,
|
||||
});
|
||||
DiaryReminderForUsersNotification({required this.type, required this.isRead, this.diaryId, this.message, required this.createdAt});
|
||||
|
||||
factory DiaryReminderForUsersNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
final data = json['data'] is Map<String, dynamic> ? json['data'] as Map<String, dynamic> : json;
|
||||
@@ -2196,12 +2185,7 @@ class ConsultantEducationUpdatedNotification implements BaseNotificationModel {
|
||||
final DateTime createdAt;
|
||||
final String consultantName;
|
||||
|
||||
ConsultantEducationUpdatedNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.consultantName,
|
||||
});
|
||||
ConsultantEducationUpdatedNotification({required this.type, required this.isRead, required this.createdAt, required this.consultantName});
|
||||
|
||||
factory ConsultantEducationUpdatedNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return ConsultantEducationUpdatedNotification(
|
||||
@@ -2258,13 +2242,7 @@ class ContentUnpublishedNotification implements BaseNotificationModel {
|
||||
final String reason;
|
||||
final String entityName;
|
||||
|
||||
ContentUnpublishedNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.reason,
|
||||
required this.entityName,
|
||||
});
|
||||
ContentUnpublishedNotification({required this.type, required this.isRead, required this.createdAt, required this.reason, required this.entityName});
|
||||
|
||||
factory ContentUnpublishedNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return ContentUnpublishedNotification(
|
||||
@@ -2286,12 +2264,7 @@ class FinanceQuestionCreatedNotification implements BaseNotificationModel {
|
||||
final DateTime createdAt;
|
||||
final String questionText;
|
||||
|
||||
FinanceQuestionCreatedNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.questionText,
|
||||
});
|
||||
FinanceQuestionCreatedNotification({required this.type, required this.isRead, required this.createdAt, required this.questionText});
|
||||
|
||||
factory FinanceQuestionCreatedNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return FinanceQuestionCreatedNotification(
|
||||
@@ -2343,11 +2316,7 @@ class CompleteRegistrationNotification implements BaseNotificationModel {
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
CompleteRegistrationNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
});
|
||||
CompleteRegistrationNotification({required this.type, required this.isRead, required this.createdAt});
|
||||
|
||||
factory CompleteRegistrationNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return CompleteRegistrationNotification(
|
||||
@@ -2368,13 +2337,7 @@ class ChosenDietExpiredNotification implements BaseNotificationModel {
|
||||
final String dietName;
|
||||
final int dietId;
|
||||
|
||||
ChosenDietExpiredNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.dietName,
|
||||
required this.dietId,
|
||||
});
|
||||
ChosenDietExpiredNotification({required this.type, required this.isRead, required this.createdAt, required this.dietName, required this.dietId});
|
||||
|
||||
factory ChosenDietExpiredNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return ChosenDietExpiredNotification(
|
||||
@@ -2396,12 +2359,7 @@ class MotivateUserNotification implements BaseNotificationModel {
|
||||
final DateTime createdAt;
|
||||
final String message;
|
||||
|
||||
MotivateUserNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.message,
|
||||
});
|
||||
MotivateUserNotification({required this.type, required this.isRead, required this.createdAt, required this.message});
|
||||
|
||||
factory MotivateUserNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return MotivateUserNotification(
|
||||
@@ -2423,13 +2381,7 @@ class CommentComplaintNotification implements BaseNotificationModel {
|
||||
final String commentPreview;
|
||||
final String reason;
|
||||
|
||||
CommentComplaintNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.commentPreview,
|
||||
required this.reason,
|
||||
});
|
||||
CommentComplaintNotification({required this.type, required this.isRead, required this.createdAt, required this.commentPreview, required this.reason});
|
||||
|
||||
factory CommentComplaintNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return CommentComplaintNotification(
|
||||
@@ -2451,12 +2403,7 @@ class CommentDeletedNotification implements BaseNotificationModel {
|
||||
final DateTime createdAt;
|
||||
final String commentPreview;
|
||||
|
||||
CommentDeletedNotification({
|
||||
required this.type,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
required this.commentPreview,
|
||||
});
|
||||
CommentDeletedNotification({required this.type, required this.isRead, required this.createdAt, required this.commentPreview});
|
||||
|
||||
factory CommentDeletedNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead, String? createdAt}) {
|
||||
return CommentDeletedNotification(
|
||||
@@ -2655,7 +2602,7 @@ enum NotificationType {
|
||||
'stay-on-track-to-customer' => NotificationType.stayOnTrackToCustomer,
|
||||
'diary-reminder-for-users' => NotificationType.diaryReminderForUsers,
|
||||
'personal-diet-is-defined-to-customer' => NotificationType.personalDietIsDefinedToCustomer,
|
||||
|
||||
|
||||
// New additions
|
||||
'consultant-education-updated' => NotificationType.consultantEducationUpdated,
|
||||
'complaint-registered' => NotificationType.complaintRegistered,
|
||||
@@ -2671,7 +2618,6 @@ enum NotificationType {
|
||||
'user-subscribed' => NotificationType.userSubscribed,
|
||||
// 'diary-reminder' => NotificationType.diaryReminder, // Already legacy? Check if it maps to diaryReminderNotification
|
||||
'meal-reminder' => NotificationType.mealReminder, // Maps to legacy if string matches? No, legacy was App\\...
|
||||
|
||||
// Legacy mapping
|
||||
'App\\Notifications\\Plan\\PlanSubscriptionStartedToAuthor' => NotificationType.planSubscriptionStartedToAuthor,
|
||||
'App\\Notifications\\Plan\\PlanSubscriptionCanceledToAuthor' => NotificationType.planSubscriptionCanceledToAuthor,
|
||||
|
||||
Reference in New Issue
Block a user