/opt/canhelp/apps/mobile/lib/models
Edit: /opt/canhelp/apps/mobile/lib/models/app_notification.dart (2423B)
enum NotificationType {
message,
offerAccepted,
offerDeclined,
taskUpdated,
newOffer,
taskInvite,
review,
specialistCardSubmitted,
specialistCardApproved,
specialistCardRejected,
referralReward,
supportReply,
system,
}
NotificationType _parseType(String? v) {
switch (v) {
case 'message':
case 'new_message':
return NotificationType.message;
case 'offer_accepted':
return NotificationType.offerAccepted;
case 'offer_declined':
return NotificationType.offerDeclined;
case 'task_updated':
case 'task_completed':
case 'task_cancelled':
return NotificationType.taskUpdated;
case 'new_offer':
return NotificationType.newOffer;
case 'task_invite':
return NotificationType.taskInvite;
case 'review':
case 'new_review':
return NotificationType.review;
case 'specialist_card_submitted':
return NotificationType.specialistCardSubmitted;
case 'specialist_card_approved':
return NotificationType.specialistCardApproved;
case 'specialist_card_rejected':
return NotificationType.specialistCardRejected;
case 'referral_reward':
return NotificationType.referralReward;
case 'support_ticket_reply':
return NotificationType.supportReply;
default:
return NotificationType.system;
}
}
class AppNotification {
final String id;
final NotificationType type;
final String title;
final String body;
final bool read;
final String? referenceId;
final String? userId;
final DateTime createdAt;
AppNotification({
required this.id,
required this.type,
required this.title,
required this.body,
this.read = false,
this.referenceId,
this.userId,
required this.createdAt,
});
factory AppNotification.fromJson(Map
json) =>
AppNotification(
id: json['id'] as String,
type: _parseType(json['type'] as String?),
title: json['title'] as String? ?? '',
body: json['body'] as String? ?? json['message'] as String? ?? '',
read: json['isRead'] as bool? ?? json['read'] as bool? ?? false,
referenceId:
json['referenceId'] as String? ?? json['taskId'] as String?,
userId: json['userId'] as String?,
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'] as String)
: DateTime.now(),
);
}