Skip to content

Commit df6e5dd

Browse files
committed
add retentionTime from notifications
1 parent 4821f53 commit df6e5dd

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

core/api/mobile.api.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,25 +669,46 @@ function saveMenuFromAppV2($menu, $mobile)
669669
if ($jsonrpc->getMethod() == 'getNotificationsFromFile') {
670670
log::add('mobile', 'debug', '┌────◀︎ getNotificationsFromFile ──────────');
671671
$Iq = $params['Iq'];
672+
$retentionTime = $params['notifsTime'];
673+
log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
674+
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
675+
$currentTime = time();
676+
672677
$filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json';
673678
$notifications = 'noNotifications';
674679
if (file_exists($filePath)) {
675680
$notifications = file_get_contents($filePath);
676681
if ($notifications) {
677682
$notifications = json_decode($notifications, true);
683+
$notificationsModified = false;
684+
678685
foreach ($notifications as $id => $value) {
679-
$dateNew = substr($value['data']['date'], 0, 10);
680-
$horaire = substr($value['data']['date'], -8);
681-
$horaireFormat = substr($horaire, 0, 5);
682-
$notifications[$id]['data']['newDate'] = $dateNew;
683-
$notifications[$id]['data']['horaireFormat'] = $horaireFormat;
686+
$notificationDate = strtotime($value['data']['date']);
687+
if (($currentTime - $notificationDate) > $retentionSeconds) {
688+
unset($notifications[$id]);
689+
$notificationsModified = true;
690+
} else {
691+
$dateNew = substr($value['data']['date'], 0, 10);
692+
$horaire = substr($value['data']['date'], -8);
693+
$horaireFormat = substr($horaire, 0, 5);
694+
$notifications[$id]['data']['newDate'] = $dateNew;
695+
$notifications[$id]['data']['horaireFormat'] = $horaireFormat;
696+
}
697+
}
698+
if ($notificationsModified) {
699+
file_put_contents($filePath, $notifications);
684700
}
701+
685702
$notifications = json_encode($notifications);
703+
$jsonrpc->makeSuccess($notifications);
704+
log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications);
705+
log::add('mobile', 'debug', '└───────────────────────────────────────────');
686706
}
707+
687708
}
688-
log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications);
689-
log::add('mobile', 'debug', '└───────────────────────────────────────────');
690-
$jsonrpc->makeSuccess($notifications);
709+
710+
//$jsonrpc->makeSuccess($notifications);
711+
691712
}
692713

693714

docs/fr_FR/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
> Pour rappel s'il n'y a pas d'information sur la mise à jour, c'est que celle-ci concerne uniquement de la mise à jour de documentation, de traduction ou de texte
66
77

8+
# 22/07/2024
9+
Prise en compte retention des notifications
10+
Target Sdk 34 pour Android
11+
812
# 28/05/2024
913
Modification Géolocalisation pour prochaine version App
1014
Stockage Notifications dans le plugin

0 commit comments

Comments
 (0)