Refactoring
This commit is contained in:
@@ -0,0 +1,414 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'notification.g.dart';
|
||||
|
||||
/// Énumération des types de notification
|
||||
enum TypeNotification {
|
||||
// Événements
|
||||
@JsonValue('NOUVEL_EVENEMENT')
|
||||
nouvelEvenement('Nouvel événement', 'evenements', 'info', 'event', '#FF9800'),
|
||||
@JsonValue('RAPPEL_EVENEMENT')
|
||||
rappelEvenement('Rappel d\'événement', 'evenements', 'reminder', 'schedule', '#2196F3'),
|
||||
@JsonValue('EVENEMENT_ANNULE')
|
||||
evenementAnnule('Événement annulé', 'evenements', 'warning', 'event_busy', '#F44336'),
|
||||
@JsonValue('INSCRIPTION_CONFIRMEE')
|
||||
inscriptionConfirmee('Inscription confirmée', 'evenements', 'success', 'check_circle', '#4CAF50'),
|
||||
|
||||
// Cotisations
|
||||
@JsonValue('COTISATION_DUE')
|
||||
cotisationDue('Cotisation due', 'cotisations', 'reminder', 'payment', '#FF5722'),
|
||||
@JsonValue('COTISATION_PAYEE')
|
||||
cotisationPayee('Cotisation payée', 'cotisations', 'success', 'paid', '#4CAF50'),
|
||||
@JsonValue('PAIEMENT_CONFIRME')
|
||||
paiementConfirme('Paiement confirmé', 'cotisations', 'success', 'check_circle', '#4CAF50'),
|
||||
@JsonValue('PAIEMENT_ECHOUE')
|
||||
paiementEchoue('Paiement échoué', 'cotisations', 'error', 'error', '#F44336'),
|
||||
|
||||
// Solidarité
|
||||
@JsonValue('NOUVELLE_DEMANDE_AIDE')
|
||||
nouvelleDemandeAide('Nouvelle demande d\'aide', 'solidarite', 'info', 'help', '#E91E63'),
|
||||
@JsonValue('DEMANDE_AIDE_APPROUVEE')
|
||||
demandeAideApprouvee('Demande d\'aide approuvée', 'solidarite', 'success', 'thumb_up', '#4CAF50'),
|
||||
@JsonValue('AIDE_DISPONIBLE')
|
||||
aideDisponible('Aide disponible', 'solidarite', 'info', 'volunteer_activism', '#E91E63'),
|
||||
|
||||
// Membres
|
||||
@JsonValue('NOUVEAU_MEMBRE')
|
||||
nouveauMembre('Nouveau membre', 'membres', 'info', 'person_add', '#2196F3'),
|
||||
@JsonValue('ANNIVERSAIRE_MEMBRE')
|
||||
anniversaireMembre('Anniversaire de membre', 'membres', 'celebration', 'cake', '#FF9800'),
|
||||
|
||||
// Organisation
|
||||
@JsonValue('ANNONCE_GENERALE')
|
||||
annonceGenerale('Annonce générale', 'organisation', 'info', 'campaign', '#2196F3'),
|
||||
@JsonValue('REUNION_PROGRAMMEE')
|
||||
reunionProgrammee('Réunion programmée', 'organisation', 'info', 'groups', '#2196F3'),
|
||||
|
||||
// Messages
|
||||
@JsonValue('MESSAGE_PRIVE')
|
||||
messagePrive('Message privé', 'messages', 'info', 'mail', '#2196F3'),
|
||||
@JsonValue('MENTION')
|
||||
mention('Mention', 'messages', 'info', 'alternate_email', '#FF9800'),
|
||||
|
||||
// Système
|
||||
@JsonValue('MISE_A_JOUR_APP')
|
||||
miseAJourApp('Mise à jour disponible', 'systeme', 'info', 'system_update', '#2196F3'),
|
||||
@JsonValue('MAINTENANCE_PROGRAMMEE')
|
||||
maintenanceProgrammee('Maintenance programmée', 'systeme', 'warning', 'build', '#FF9800');
|
||||
|
||||
const TypeNotification(this.libelle, this.categorie, this.priorite, this.icone, this.couleur);
|
||||
|
||||
final String libelle;
|
||||
final String categorie;
|
||||
final String priorite;
|
||||
final String icone;
|
||||
final String couleur;
|
||||
|
||||
bool get isCritique => priorite == 'urgent' || priorite == 'error';
|
||||
bool get isRappel => priorite == 'reminder';
|
||||
bool get isPositive => priorite == 'success' || priorite == 'celebration';
|
||||
|
||||
int get niveauPriorite {
|
||||
switch (priorite) {
|
||||
case 'urgent': return 1;
|
||||
case 'error': return 2;
|
||||
case 'warning': return 3;
|
||||
case 'important': return 4;
|
||||
case 'reminder': return 5;
|
||||
case 'info': return 6;
|
||||
case 'success': return 7;
|
||||
case 'celebration': return 8;
|
||||
default: return 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Énumération des statuts de notification
|
||||
enum StatutNotification {
|
||||
@JsonValue('BROUILLON')
|
||||
brouillon('Brouillon', 'draft', '#9E9E9E'),
|
||||
@JsonValue('PROGRAMMEE')
|
||||
programmee('Programmée', 'scheduled', '#FF9800'),
|
||||
@JsonValue('ENVOYEE')
|
||||
envoyee('Envoyée', 'sent', '#4CAF50'),
|
||||
@JsonValue('RECUE')
|
||||
recue('Reçue', 'received', '#4CAF50'),
|
||||
@JsonValue('AFFICHEE')
|
||||
affichee('Affichée', 'displayed', '#2196F3'),
|
||||
@JsonValue('OUVERTE')
|
||||
ouverte('Ouverte', 'opened', '#4CAF50'),
|
||||
@JsonValue('LUE')
|
||||
lue('Lue', 'read', '#4CAF50'),
|
||||
@JsonValue('NON_LUE')
|
||||
nonLue('Non lue', 'unread', '#FF9800'),
|
||||
@JsonValue('MARQUEE_IMPORTANTE')
|
||||
marqueeImportante('Marquée importante', 'starred', '#FF9800'),
|
||||
@JsonValue('SUPPRIMEE')
|
||||
supprimee('Supprimée', 'deleted', '#F44336'),
|
||||
@JsonValue('ARCHIVEE')
|
||||
archivee('Archivée', 'archived', '#9E9E9E'),
|
||||
@JsonValue('ECHEC_ENVOI')
|
||||
echecEnvoi('Échec d\'envoi', 'failed', '#F44336');
|
||||
|
||||
const StatutNotification(this.libelle, this.code, this.couleur);
|
||||
|
||||
final String libelle;
|
||||
final String code;
|
||||
final String couleur;
|
||||
|
||||
bool get isSucces => this == envoyee || this == recue || this == affichee || this == ouverte || this == lue;
|
||||
bool get isErreur => this == echecEnvoi;
|
||||
bool get isFinal => this == supprimee || this == archivee || isErreur;
|
||||
}
|
||||
|
||||
/// Action rapide de notification
|
||||
@JsonSerializable()
|
||||
class ActionNotification extends Equatable {
|
||||
const ActionNotification({
|
||||
required this.id,
|
||||
required this.libelle,
|
||||
required this.typeAction,
|
||||
this.description,
|
||||
this.icone,
|
||||
this.couleur,
|
||||
this.url,
|
||||
this.route,
|
||||
this.parametres,
|
||||
this.fermeNotification = true,
|
||||
this.necessiteConfirmation = false,
|
||||
this.estDestructive = false,
|
||||
this.ordre = 0,
|
||||
this.estActivee = true,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String libelle;
|
||||
final String? description;
|
||||
final String typeAction;
|
||||
final String? icone;
|
||||
final String? couleur;
|
||||
final String? url;
|
||||
final String? route;
|
||||
final Map<String, String>? parametres;
|
||||
final bool fermeNotification;
|
||||
final bool necessiteConfirmation;
|
||||
final bool estDestructive;
|
||||
final int ordre;
|
||||
final bool estActivee;
|
||||
|
||||
factory ActionNotification.fromJson(Map<String, dynamic> json) =>
|
||||
_$ActionNotificationFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ActionNotificationToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id, libelle, description, typeAction, icone, couleur,
|
||||
url, route, parametres, fermeNotification, necessiteConfirmation,
|
||||
estDestructive, ordre, estActivee,
|
||||
];
|
||||
|
||||
ActionNotification copyWith({
|
||||
String? id,
|
||||
String? libelle,
|
||||
String? description,
|
||||
String? typeAction,
|
||||
String? icone,
|
||||
String? couleur,
|
||||
String? url,
|
||||
String? route,
|
||||
Map<String, String>? parametres,
|
||||
bool? fermeNotification,
|
||||
bool? necessiteConfirmation,
|
||||
bool? estDestructive,
|
||||
int? ordre,
|
||||
bool? estActivee,
|
||||
}) {
|
||||
return ActionNotification(
|
||||
id: id ?? this.id,
|
||||
libelle: libelle ?? this.libelle,
|
||||
description: description ?? this.description,
|
||||
typeAction: typeAction ?? this.typeAction,
|
||||
icone: icone ?? this.icone,
|
||||
couleur: couleur ?? this.couleur,
|
||||
url: url ?? this.url,
|
||||
route: route ?? this.route,
|
||||
parametres: parametres ?? this.parametres,
|
||||
fermeNotification: fermeNotification ?? this.fermeNotification,
|
||||
necessiteConfirmation: necessiteConfirmation ?? this.necessiteConfirmation,
|
||||
estDestructive: estDestructive ?? this.estDestructive,
|
||||
ordre: ordre ?? this.ordre,
|
||||
estActivee: estActivee ?? this.estActivee,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Entité principale de notification
|
||||
@JsonSerializable()
|
||||
class NotificationEntity extends Equatable {
|
||||
const NotificationEntity({
|
||||
required this.id,
|
||||
required this.typeNotification,
|
||||
required this.statut,
|
||||
required this.titre,
|
||||
required this.message,
|
||||
this.messageCourt,
|
||||
this.expediteurId,
|
||||
this.expediteurNom,
|
||||
required this.destinatairesIds,
|
||||
this.organisationId,
|
||||
this.donneesPersonnalisees,
|
||||
this.imageUrl,
|
||||
this.iconeUrl,
|
||||
this.actionClic,
|
||||
this.parametresAction,
|
||||
this.actionsRapides,
|
||||
required this.dateCreation,
|
||||
this.dateEnvoiProgramme,
|
||||
this.dateEnvoi,
|
||||
this.dateExpiration,
|
||||
this.dateDerniereLecture,
|
||||
this.priorite = 3,
|
||||
this.estLue = false,
|
||||
this.estImportante = false,
|
||||
this.estArchivee = false,
|
||||
this.nombreAffichages = 0,
|
||||
this.nombreClics = 0,
|
||||
this.tags,
|
||||
this.campagneId,
|
||||
this.plateforme,
|
||||
this.tokenFCM,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final TypeNotification typeNotification;
|
||||
final StatutNotification statut;
|
||||
final String titre;
|
||||
final String message;
|
||||
final String? messageCourt;
|
||||
final String? expediteurId;
|
||||
final String? expediteurNom;
|
||||
final List<String> destinatairesIds;
|
||||
final String? organisationId;
|
||||
final Map<String, dynamic>? donneesPersonnalisees;
|
||||
final String? imageUrl;
|
||||
final String? iconeUrl;
|
||||
final String? actionClic;
|
||||
final Map<String, String>? parametresAction;
|
||||
final List<ActionNotification>? actionsRapides;
|
||||
final DateTime dateCreation;
|
||||
final DateTime? dateEnvoiProgramme;
|
||||
final DateTime? dateEnvoi;
|
||||
final DateTime? dateExpiration;
|
||||
final DateTime? dateDerniereLecture;
|
||||
final int priorite;
|
||||
final bool estLue;
|
||||
final bool estImportante;
|
||||
final bool estArchivee;
|
||||
final int nombreAffichages;
|
||||
final int nombreClics;
|
||||
final List<String>? tags;
|
||||
final String? campagneId;
|
||||
final String? plateforme;
|
||||
final String? tokenFCM;
|
||||
|
||||
factory NotificationEntity.fromJson(Map<String, dynamic> json) =>
|
||||
_$NotificationEntityFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$NotificationEntityToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id, typeNotification, statut, titre, message, messageCourt,
|
||||
expediteurId, expediteurNom, destinatairesIds, organisationId,
|
||||
donneesPersonnalisees, imageUrl, iconeUrl, actionClic, parametresAction,
|
||||
actionsRapides, dateCreation, dateEnvoiProgramme, dateEnvoi,
|
||||
dateExpiration, dateDerniereLecture, priorite, estLue, estImportante,
|
||||
estArchivee, nombreAffichages, nombreClics, tags, campagneId,
|
||||
plateforme, tokenFCM,
|
||||
];
|
||||
|
||||
NotificationEntity copyWith({
|
||||
String? id,
|
||||
TypeNotification? typeNotification,
|
||||
StatutNotification? statut,
|
||||
String? titre,
|
||||
String? message,
|
||||
String? messageCourt,
|
||||
String? expediteurId,
|
||||
String? expediteurNom,
|
||||
List<String>? destinatairesIds,
|
||||
String? organisationId,
|
||||
Map<String, dynamic>? donneesPersonnalisees,
|
||||
String? imageUrl,
|
||||
String? iconeUrl,
|
||||
String? actionClic,
|
||||
Map<String, String>? parametresAction,
|
||||
List<ActionNotification>? actionsRapides,
|
||||
DateTime? dateCreation,
|
||||
DateTime? dateEnvoiProgramme,
|
||||
DateTime? dateEnvoi,
|
||||
DateTime? dateExpiration,
|
||||
DateTime? dateDerniereLecture,
|
||||
int? priorite,
|
||||
bool? estLue,
|
||||
bool? estImportante,
|
||||
bool? estArchivee,
|
||||
int? nombreAffichages,
|
||||
int? nombreClics,
|
||||
List<String>? tags,
|
||||
String? campagneId,
|
||||
String? plateforme,
|
||||
String? tokenFCM,
|
||||
}) {
|
||||
return NotificationEntity(
|
||||
id: id ?? this.id,
|
||||
typeNotification: typeNotification ?? this.typeNotification,
|
||||
statut: statut ?? this.statut,
|
||||
titre: titre ?? this.titre,
|
||||
message: message ?? this.message,
|
||||
messageCourt: messageCourt ?? this.messageCourt,
|
||||
expediteurId: expediteurId ?? this.expediteurId,
|
||||
expediteurNom: expediteurNom ?? this.expediteurNom,
|
||||
destinatairesIds: destinatairesIds ?? this.destinatairesIds,
|
||||
organisationId: organisationId ?? this.organisationId,
|
||||
donneesPersonnalisees: donneesPersonnalisees ?? this.donneesPersonnalisees,
|
||||
imageUrl: imageUrl ?? this.imageUrl,
|
||||
iconeUrl: iconeUrl ?? this.iconeUrl,
|
||||
actionClic: actionClic ?? this.actionClic,
|
||||
parametresAction: parametresAction ?? this.parametresAction,
|
||||
actionsRapides: actionsRapides ?? this.actionsRapides,
|
||||
dateCreation: dateCreation ?? this.dateCreation,
|
||||
dateEnvoiProgramme: dateEnvoiProgramme ?? this.dateEnvoiProgramme,
|
||||
dateEnvoi: dateEnvoi ?? this.dateEnvoi,
|
||||
dateExpiration: dateExpiration ?? this.dateExpiration,
|
||||
dateDerniereLecture: dateDerniereLecture ?? this.dateDerniereLecture,
|
||||
priorite: priorite ?? this.priorite,
|
||||
estLue: estLue ?? this.estLue,
|
||||
estImportante: estImportante ?? this.estImportante,
|
||||
estArchivee: estArchivee ?? this.estArchivee,
|
||||
nombreAffichages: nombreAffichages ?? this.nombreAffichages,
|
||||
nombreClics: nombreClics ?? this.nombreClics,
|
||||
tags: tags ?? this.tags,
|
||||
campagneId: campagneId ?? this.campagneId,
|
||||
plateforme: plateforme ?? this.plateforme,
|
||||
tokenFCM: tokenFCM ?? this.tokenFCM,
|
||||
);
|
||||
}
|
||||
|
||||
/// Vérifie si la notification est expirée
|
||||
bool get isExpiree {
|
||||
if (dateExpiration == null) return false;
|
||||
return DateTime.now().isAfter(dateExpiration!);
|
||||
}
|
||||
|
||||
/// Vérifie si la notification est récente (moins de 24h)
|
||||
bool get isRecente {
|
||||
final maintenant = DateTime.now();
|
||||
final difference = maintenant.difference(dateCreation);
|
||||
return difference.inHours < 24;
|
||||
}
|
||||
|
||||
/// Retourne le temps écoulé depuis la création
|
||||
String get tempsEcoule {
|
||||
final maintenant = DateTime.now();
|
||||
final difference = maintenant.difference(dateCreation);
|
||||
|
||||
if (difference.inMinutes < 1) {
|
||||
return 'À l\'instant';
|
||||
} else if (difference.inMinutes < 60) {
|
||||
return 'Il y a ${difference.inMinutes}min';
|
||||
} else if (difference.inHours < 24) {
|
||||
return 'Il y a ${difference.inHours}h';
|
||||
} else if (difference.inDays < 7) {
|
||||
return 'Il y a ${difference.inDays}j';
|
||||
} else {
|
||||
return 'Il y a ${(difference.inDays / 7).floor()}sem';
|
||||
}
|
||||
}
|
||||
|
||||
/// Retourne le message à afficher (court ou complet)
|
||||
String get messageAffichage => messageCourt ?? message;
|
||||
|
||||
/// Retourne la couleur du type de notification
|
||||
String get couleurType => typeNotification.couleur;
|
||||
|
||||
/// Retourne l'icône du type de notification
|
||||
String get iconeType => typeNotification.icone;
|
||||
|
||||
/// Vérifie si la notification a des actions rapides
|
||||
bool get hasActionsRapides => actionsRapides != null && actionsRapides!.isNotEmpty;
|
||||
|
||||
/// Retourne les actions rapides actives
|
||||
List<ActionNotification> get actionsRapidesActives {
|
||||
if (actionsRapides == null) return [];
|
||||
return actionsRapides!.where((action) => action.estActivee).toList();
|
||||
}
|
||||
|
||||
/// Calcule le taux d'engagement
|
||||
double get tauxEngagement {
|
||||
if (nombreAffichages == 0) return 0.0;
|
||||
return (nombreClics / nombreAffichages) * 100;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'notification.dart';
|
||||
|
||||
part 'preferences_notification.g.dart';
|
||||
|
||||
/// Énumération des canaux de notification
|
||||
enum CanalNotification {
|
||||
@JsonValue('URGENT_CHANNEL')
|
||||
urgent('urgent', 'Notifications urgentes', 5, true, true, '#F44336'),
|
||||
@JsonValue('ERROR_CHANNEL')
|
||||
error('error', 'Erreurs système', 4, true, true, '#F44336'),
|
||||
@JsonValue('WARNING_CHANNEL')
|
||||
warning('warning', 'Avertissements', 4, true, true, '#FF9800'),
|
||||
@JsonValue('IMPORTANT_CHANNEL')
|
||||
important('important', 'Notifications importantes', 4, true, true, '#FF5722'),
|
||||
@JsonValue('REMINDER_CHANNEL')
|
||||
reminder('reminder', 'Rappels', 3, true, true, '#2196F3'),
|
||||
@JsonValue('SUCCESS_CHANNEL')
|
||||
success('success', 'Confirmations', 2, false, false, '#4CAF50'),
|
||||
@JsonValue('DEFAULT_CHANNEL')
|
||||
defaultChannel('default', 'Notifications générales', 2, false, false, '#2196F3'),
|
||||
@JsonValue('EVENTS_CHANNEL')
|
||||
events('events', 'Événements', 3, true, false, '#2196F3'),
|
||||
@JsonValue('PAYMENTS_CHANNEL')
|
||||
payments('payments', 'Paiements', 4, true, true, '#4CAF50'),
|
||||
@JsonValue('SOLIDARITY_CHANNEL')
|
||||
solidarity('solidarity', 'Solidarité', 3, true, false, '#E91E63'),
|
||||
@JsonValue('MEMBERS_CHANNEL')
|
||||
members('members', 'Membres', 2, false, false, '#2196F3'),
|
||||
@JsonValue('ORGANIZATION_CHANNEL')
|
||||
organization('organization', 'Organisation', 3, true, false, '#2196F3'),
|
||||
@JsonValue('SYSTEM_CHANNEL')
|
||||
system('system', 'Système', 2, false, false, '#607D8B'),
|
||||
@JsonValue('MESSAGES_CHANNEL')
|
||||
messages('messages', 'Messages', 3, true, false, '#2196F3');
|
||||
|
||||
const CanalNotification(this.id, this.nom, this.importance, this.sonActive,
|
||||
this.vibrationActive, this.couleur);
|
||||
|
||||
final String id;
|
||||
final String nom;
|
||||
final int importance;
|
||||
final bool sonActive;
|
||||
final bool vibrationActive;
|
||||
final String couleur;
|
||||
|
||||
bool get isCritique => importance >= 4;
|
||||
bool get isSilencieux => !sonActive && !vibrationActive;
|
||||
}
|
||||
|
||||
/// Préférences spécifiques à un type de notification
|
||||
@JsonSerializable()
|
||||
class PreferenceTypeNotification extends Equatable {
|
||||
const PreferenceTypeNotification({
|
||||
this.active = true,
|
||||
this.priorite,
|
||||
this.sonPersonnalise,
|
||||
this.patternVibration,
|
||||
this.couleurLED,
|
||||
this.dureeAffichageSecondes,
|
||||
this.doitVibrer,
|
||||
this.doitEmettreSon,
|
||||
this.doitAllumerLED,
|
||||
this.ignoreModesilencieux = false,
|
||||
});
|
||||
|
||||
final bool active;
|
||||
final int? priorite;
|
||||
final String? sonPersonnalise;
|
||||
final List<int>? patternVibration;
|
||||
final String? couleurLED;
|
||||
final int? dureeAffichageSecondes;
|
||||
final bool? doitVibrer;
|
||||
final bool? doitEmettreSon;
|
||||
final bool? doitAllumerLED;
|
||||
final bool ignoreModesilencieux;
|
||||
|
||||
factory PreferenceTypeNotification.fromJson(Map<String, dynamic> json) =>
|
||||
_$PreferenceTypeNotificationFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$PreferenceTypeNotificationToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
active, priorite, sonPersonnalise, patternVibration, couleurLED,
|
||||
dureeAffichageSecondes, doitVibrer, doitEmettreSon, doitAllumerLED,
|
||||
ignoreModesilencieux,
|
||||
];
|
||||
|
||||
PreferenceTypeNotification copyWith({
|
||||
bool? active,
|
||||
int? priorite,
|
||||
String? sonPersonnalise,
|
||||
List<int>? patternVibration,
|
||||
String? couleurLED,
|
||||
int? dureeAffichageSecondes,
|
||||
bool? doitVibrer,
|
||||
bool? doitEmettreSon,
|
||||
bool? doitAllumerLED,
|
||||
bool? ignoreModesilencieux,
|
||||
}) {
|
||||
return PreferenceTypeNotification(
|
||||
active: active ?? this.active,
|
||||
priorite: priorite ?? this.priorite,
|
||||
sonPersonnalise: sonPersonnalise ?? this.sonPersonnalise,
|
||||
patternVibration: patternVibration ?? this.patternVibration,
|
||||
couleurLED: couleurLED ?? this.couleurLED,
|
||||
dureeAffichageSecondes: dureeAffichageSecondes ?? this.dureeAffichageSecondes,
|
||||
doitVibrer: doitVibrer ?? this.doitVibrer,
|
||||
doitEmettreSon: doitEmettreSon ?? this.doitEmettreSon,
|
||||
doitAllumerLED: doitAllumerLED ?? this.doitAllumerLED,
|
||||
ignoreModesilencieux: ignoreModesilencieux ?? this.ignoreModesilencieux,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Préférences spécifiques à un canal de notification
|
||||
@JsonSerializable()
|
||||
class PreferenceCanalNotification extends Equatable {
|
||||
const PreferenceCanalNotification({
|
||||
this.active = true,
|
||||
this.importance,
|
||||
this.sonPersonnalise,
|
||||
this.patternVibration,
|
||||
this.couleurLED,
|
||||
this.sonActive,
|
||||
this.vibrationActive,
|
||||
this.ledActive,
|
||||
this.peutEtreDesactive = true,
|
||||
});
|
||||
|
||||
final bool active;
|
||||
final int? importance;
|
||||
final String? sonPersonnalise;
|
||||
final List<int>? patternVibration;
|
||||
final String? couleurLED;
|
||||
final bool? sonActive;
|
||||
final bool? vibrationActive;
|
||||
final bool? ledActive;
|
||||
final bool peutEtreDesactive;
|
||||
|
||||
factory PreferenceCanalNotification.fromJson(Map<String, dynamic> json) =>
|
||||
_$PreferenceCanalNotificationFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$PreferenceCanalNotificationToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
active, importance, sonPersonnalise, patternVibration, couleurLED,
|
||||
sonActive, vibrationActive, ledActive, peutEtreDesactive,
|
||||
];
|
||||
|
||||
PreferenceCanalNotification copyWith({
|
||||
bool? active,
|
||||
int? importance,
|
||||
String? sonPersonnalise,
|
||||
List<int>? patternVibration,
|
||||
String? couleurLED,
|
||||
bool? sonActive,
|
||||
bool? vibrationActive,
|
||||
bool? ledActive,
|
||||
bool? peutEtreDesactive,
|
||||
}) {
|
||||
return PreferenceCanalNotification(
|
||||
active: active ?? this.active,
|
||||
importance: importance ?? this.importance,
|
||||
sonPersonnalise: sonPersonnalise ?? this.sonPersonnalise,
|
||||
patternVibration: patternVibration ?? this.patternVibration,
|
||||
couleurLED: couleurLED ?? this.couleurLED,
|
||||
sonActive: sonActive ?? this.sonActive,
|
||||
vibrationActive: vibrationActive ?? this.vibrationActive,
|
||||
ledActive: ledActive ?? this.ledActive,
|
||||
peutEtreDesactive: peutEtreDesactive ?? this.peutEtreDesactive,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Entité principale des préférences de notification
|
||||
@JsonSerializable()
|
||||
class PreferencesNotificationEntity extends Equatable {
|
||||
const PreferencesNotificationEntity({
|
||||
required this.id,
|
||||
required this.utilisateurId,
|
||||
this.organisationId,
|
||||
this.notificationsActivees = true,
|
||||
this.pushActivees = true,
|
||||
this.emailActivees = true,
|
||||
this.smsActivees = false,
|
||||
this.inAppActivees = true,
|
||||
this.typesActives,
|
||||
this.typesDesactivees,
|
||||
this.canauxActifs,
|
||||
this.canauxDesactives,
|
||||
this.modeSilencieux = false,
|
||||
this.heureDebutSilencieux,
|
||||
this.heureFinSilencieux,
|
||||
this.joursSilencieux,
|
||||
this.urgentesIgnorentSilencieux = true,
|
||||
this.frequenceRegroupementMinutes = 5,
|
||||
this.maxNotificationsSimultanees = 10,
|
||||
this.dureeAffichageSecondes = 10,
|
||||
this.vibrationActivee = true,
|
||||
this.sonActive = true,
|
||||
this.ledActivee = true,
|
||||
this.sonPersonnalise,
|
||||
this.patternVibrationPersonnalise,
|
||||
this.couleurLEDPersonnalisee,
|
||||
this.apercuEcranVerrouillage = true,
|
||||
this.affichageHistorique = true,
|
||||
this.dureeConservationJours = 30,
|
||||
this.marquageLectureAutomatique = false,
|
||||
this.delaiMarquageLectureSecondes,
|
||||
this.archivageAutomatique = true,
|
||||
this.delaiArchivageHeures = 168,
|
||||
this.preferencesParType,
|
||||
this.preferencesParCanal,
|
||||
this.motsClesFiltre,
|
||||
this.expediteursBloques,
|
||||
this.expediteursPrioritaires,
|
||||
this.notificationsTestActivees = false,
|
||||
this.niveauLog = 'INFO',
|
||||
this.tokenFCM,
|
||||
this.plateforme,
|
||||
this.versionApp,
|
||||
this.langue = 'fr',
|
||||
this.fuseauHoraire,
|
||||
this.metadonnees,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String utilisateurId;
|
||||
final String? organisationId;
|
||||
final bool notificationsActivees;
|
||||
final bool pushActivees;
|
||||
final bool emailActivees;
|
||||
final bool smsActivees;
|
||||
final bool inAppActivees;
|
||||
final Set<TypeNotification>? typesActives;
|
||||
final Set<TypeNotification>? typesDesactivees;
|
||||
final Set<CanalNotification>? canauxActifs;
|
||||
final Set<CanalNotification>? canauxDesactives;
|
||||
final bool modeSilencieux;
|
||||
final String? heureDebutSilencieux; // Format HH:mm
|
||||
final String? heureFinSilencieux; // Format HH:mm
|
||||
final Set<int>? joursSilencieux; // 1=Lundi, 7=Dimanche
|
||||
final bool urgentesIgnorentSilencieux;
|
||||
final int frequenceRegroupementMinutes;
|
||||
final int maxNotificationsSimultanees;
|
||||
final int dureeAffichageSecondes;
|
||||
final bool vibrationActivee;
|
||||
final bool sonActive;
|
||||
final bool ledActivee;
|
||||
final String? sonPersonnalise;
|
||||
final List<int>? patternVibrationPersonnalise;
|
||||
final String? couleurLEDPersonnalisee;
|
||||
final bool apercuEcranVerrouillage;
|
||||
final bool affichageHistorique;
|
||||
final int dureeConservationJours;
|
||||
final bool marquageLectureAutomatique;
|
||||
final int? delaiMarquageLectureSecondes;
|
||||
final bool archivageAutomatique;
|
||||
final int delaiArchivageHeures;
|
||||
final Map<TypeNotification, PreferenceTypeNotification>? preferencesParType;
|
||||
final Map<CanalNotification, PreferenceCanalNotification>? preferencesParCanal;
|
||||
final Set<String>? motsClesFiltre;
|
||||
final Set<String>? expediteursBloques;
|
||||
final Set<String>? expediteursPrioritaires;
|
||||
final bool notificationsTestActivees;
|
||||
final String niveauLog;
|
||||
final String? tokenFCM;
|
||||
final String? plateforme;
|
||||
final String? versionApp;
|
||||
final String langue;
|
||||
final String? fuseauHoraire;
|
||||
final Map<String, dynamic>? metadonnees;
|
||||
|
||||
factory PreferencesNotificationEntity.fromJson(Map<String, dynamic> json) =>
|
||||
_$PreferencesNotificationEntityFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$PreferencesNotificationEntityToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id, utilisateurId, organisationId, notificationsActivees, pushActivees,
|
||||
emailActivees, smsActivees, inAppActivees, typesActives, typesDesactivees,
|
||||
canauxActifs, canauxDesactives, modeSilencieux, heureDebutSilencieux,
|
||||
heureFinSilencieux, joursSilencieux, urgentesIgnorentSilencieux,
|
||||
frequenceRegroupementMinutes, maxNotificationsSimultanees,
|
||||
dureeAffichageSecondes, vibrationActivee, sonActive, ledActivee,
|
||||
sonPersonnalise, patternVibrationPersonnalise, couleurLEDPersonnalisee,
|
||||
apercuEcranVerrouillage, affichageHistorique, dureeConservationJours,
|
||||
marquageLectureAutomatique, delaiMarquageLectureSecondes,
|
||||
archivageAutomatique, delaiArchivageHeures, preferencesParType,
|
||||
preferencesParCanal, motsClesFiltre, expediteursBloques,
|
||||
expediteursPrioritaires, notificationsTestActivees, niveauLog,
|
||||
tokenFCM, plateforme, versionApp, langue, fuseauHoraire, metadonnees,
|
||||
];
|
||||
|
||||
PreferencesNotificationEntity copyWith({
|
||||
String? id,
|
||||
String? utilisateurId,
|
||||
String? organisationId,
|
||||
bool? notificationsActivees,
|
||||
bool? pushActivees,
|
||||
bool? emailActivees,
|
||||
bool? smsActivees,
|
||||
bool? inAppActivees,
|
||||
Set<TypeNotification>? typesActives,
|
||||
Set<TypeNotification>? typesDesactivees,
|
||||
Set<CanalNotification>? canauxActifs,
|
||||
Set<CanalNotification>? canauxDesactives,
|
||||
bool? modeSilencieux,
|
||||
String? heureDebutSilencieux,
|
||||
String? heureFinSilencieux,
|
||||
Set<int>? joursSilencieux,
|
||||
bool? urgentesIgnorentSilencieux,
|
||||
int? frequenceRegroupementMinutes,
|
||||
int? maxNotificationsSimultanees,
|
||||
int? dureeAffichageSecondes,
|
||||
bool? vibrationActivee,
|
||||
bool? sonActive,
|
||||
bool? ledActivee,
|
||||
String? sonPersonnalise,
|
||||
List<int>? patternVibrationPersonnalise,
|
||||
String? couleurLEDPersonnalisee,
|
||||
bool? apercuEcranVerrouillage,
|
||||
bool? affichageHistorique,
|
||||
int? dureeConservationJours,
|
||||
bool? marquageLectureAutomatique,
|
||||
int? delaiMarquageLectureSecondes,
|
||||
bool? archivageAutomatique,
|
||||
int? delaiArchivageHeures,
|
||||
Map<TypeNotification, PreferenceTypeNotification>? preferencesParType,
|
||||
Map<CanalNotification, PreferenceCanalNotification>? preferencesParCanal,
|
||||
Set<String>? motsClesFiltre,
|
||||
Set<String>? expediteursBloques,
|
||||
Set<String>? expediteursPrioritaires,
|
||||
bool? notificationsTestActivees,
|
||||
String? niveauLog,
|
||||
String? tokenFCM,
|
||||
String? plateforme,
|
||||
String? versionApp,
|
||||
String? langue,
|
||||
String? fuseauHoraire,
|
||||
Map<String, dynamic>? metadonnees,
|
||||
}) {
|
||||
return PreferencesNotificationEntity(
|
||||
id: id ?? this.id,
|
||||
utilisateurId: utilisateurId ?? this.utilisateurId,
|
||||
organisationId: organisationId ?? this.organisationId,
|
||||
notificationsActivees: notificationsActivees ?? this.notificationsActivees,
|
||||
pushActivees: pushActivees ?? this.pushActivees,
|
||||
emailActivees: emailActivees ?? this.emailActivees,
|
||||
smsActivees: smsActivees ?? this.smsActivees,
|
||||
inAppActivees: inAppActivees ?? this.inAppActivees,
|
||||
typesActives: typesActives ?? this.typesActives,
|
||||
typesDesactivees: typesDesactivees ?? this.typesDesactivees,
|
||||
canauxActifs: canauxActifs ?? this.canauxActifs,
|
||||
canauxDesactives: canauxDesactives ?? this.canauxDesactives,
|
||||
modeSilencieux: modeSilencieux ?? this.modeSilencieux,
|
||||
heureDebutSilencieux: heureDebutSilencieux ?? this.heureDebutSilencieux,
|
||||
heureFinSilencieux: heureFinSilencieux ?? this.heureFinSilencieux,
|
||||
joursSilencieux: joursSilencieux ?? this.joursSilencieux,
|
||||
urgentesIgnorentSilencieux: urgentesIgnorentSilencieux ?? this.urgentesIgnorentSilencieux,
|
||||
frequenceRegroupementMinutes: frequenceRegroupementMinutes ?? this.frequenceRegroupementMinutes,
|
||||
maxNotificationsSimultanees: maxNotificationsSimultanees ?? this.maxNotificationsSimultanees,
|
||||
dureeAffichageSecondes: dureeAffichageSecondes ?? this.dureeAffichageSecondes,
|
||||
vibrationActivee: vibrationActivee ?? this.vibrationActivee,
|
||||
sonActive: sonActive ?? this.sonActive,
|
||||
ledActivee: ledActivee ?? this.ledActivee,
|
||||
sonPersonnalise: sonPersonnalise ?? this.sonPersonnalise,
|
||||
patternVibrationPersonnalise: patternVibrationPersonnalise ?? this.patternVibrationPersonnalise,
|
||||
couleurLEDPersonnalisee: couleurLEDPersonnalisee ?? this.couleurLEDPersonnalisee,
|
||||
apercuEcranVerrouillage: apercuEcranVerrouillage ?? this.apercuEcranVerrouillage,
|
||||
affichageHistorique: affichageHistorique ?? this.affichageHistorique,
|
||||
dureeConservationJours: dureeConservationJours ?? this.dureeConservationJours,
|
||||
marquageLectureAutomatique: marquageLectureAutomatique ?? this.marquageLectureAutomatique,
|
||||
delaiMarquageLectureSecondes: delaiMarquageLectureSecondes ?? this.delaiMarquageLectureSecondes,
|
||||
archivageAutomatique: archivageAutomatique ?? this.archivageAutomatique,
|
||||
delaiArchivageHeures: delaiArchivageHeures ?? this.delaiArchivageHeures,
|
||||
preferencesParType: preferencesParType ?? this.preferencesParType,
|
||||
preferencesParCanal: preferencesParCanal ?? this.preferencesParCanal,
|
||||
motsClesFiltre: motsClesFiltre ?? this.motsClesFiltre,
|
||||
expediteursBloques: expediteursBloques ?? this.expediteursBloques,
|
||||
expediteursPrioritaires: expediteursPrioritaires ?? this.expediteursPrioritaires,
|
||||
notificationsTestActivees: notificationsTestActivees ?? this.notificationsTestActivees,
|
||||
niveauLog: niveauLog ?? this.niveauLog,
|
||||
tokenFCM: tokenFCM ?? this.tokenFCM,
|
||||
plateforme: plateforme ?? this.plateforme,
|
||||
versionApp: versionApp ?? this.versionApp,
|
||||
langue: langue ?? this.langue,
|
||||
fuseauHoraire: fuseauHoraire ?? this.fuseauHoraire,
|
||||
metadonnees: metadonnees ?? this.metadonnees,
|
||||
);
|
||||
}
|
||||
|
||||
/// Vérifie si un type de notification est activé
|
||||
bool isTypeActive(TypeNotification type) {
|
||||
if (!notificationsActivees) return false;
|
||||
if (typesDesactivees?.contains(type) == true) return false;
|
||||
if (typesActives != null) return typesActives!.contains(type);
|
||||
return true; // Activé par défaut
|
||||
}
|
||||
|
||||
/// Vérifie si un canal de notification est activé
|
||||
bool isCanalActif(CanalNotification canal) {
|
||||
if (!notificationsActivees) return false;
|
||||
if (canauxDesactives?.contains(canal) == true) return false;
|
||||
if (canauxActifs != null) return canauxActifs!.contains(canal);
|
||||
return true; // Activé par défaut
|
||||
}
|
||||
|
||||
/// Vérifie si on est en mode silencieux actuellement
|
||||
bool get isEnModeSilencieux {
|
||||
if (!modeSilencieux) return false;
|
||||
if (heureDebutSilencieux == null || heureFinSilencieux == null) return false;
|
||||
|
||||
final maintenant = DateTime.now();
|
||||
final heureActuelle = '${maintenant.hour.toString().padLeft(2, '0')}:${maintenant.minute.toString().padLeft(2, '0')}';
|
||||
|
||||
// Gestion du cas où la période traverse minuit
|
||||
if (heureDebutSilencieux!.compareTo(heureFinSilencieux!) > 0) {
|
||||
return heureActuelle.compareTo(heureDebutSilencieux!) >= 0 ||
|
||||
heureActuelle.compareTo(heureFinSilencieux!) <= 0;
|
||||
} else {
|
||||
return heureActuelle.compareTo(heureDebutSilencieux!) >= 0 &&
|
||||
heureActuelle.compareTo(heureFinSilencieux!) <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Vérifie si un expéditeur est bloqué
|
||||
bool isExpediteurBloque(String? expediteurId) {
|
||||
if (expediteurId == null) return false;
|
||||
return expediteursBloques?.contains(expediteurId) == true;
|
||||
}
|
||||
|
||||
/// Vérifie si un expéditeur est prioritaire
|
||||
bool isExpediteurPrioritaire(String? expediteurId) {
|
||||
if (expediteurId == null) return false;
|
||||
return expediteursPrioritaires?.contains(expediteurId) == true;
|
||||
}
|
||||
|
||||
/// Crée des préférences par défaut pour un utilisateur
|
||||
static PreferencesNotificationEntity creerDefaut(String utilisateurId) {
|
||||
return PreferencesNotificationEntity(
|
||||
id: 'pref_$utilisateurId',
|
||||
utilisateurId: utilisateurId,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user