Fixed notifications that would not be remembered as hidden + various improvements

This commit is contained in:
Djamil Legato
2020-12-21 15:29:42 -08:00
parent 06719a23dd
commit 72116dcbca
9 changed files with 46 additions and 17 deletions

View File

@@ -1577,10 +1577,14 @@ class Admin
{
$last_checked = null;
$filename = $this->grav['locator']->findResource('user://data/notifications/' . md5($this->grav['user']->username) . YAML_EXT, true, true);
$userStatus = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
$notifications_file = CompiledYamlFile::instance($filename);
$notifications_content = (array)$notifications_file->content();
$userStatus_file = CompiledYamlFile::instance($userStatus);
$userStatus_content = (array)$userStatus_file->content();
$last_checked = $notifications_content['last_checked'] ?? null;
$notifications = $notifications_content['data'] ?? array();
$timeout = $this->grav['config']->get('system.session.timeout', 1800);
@@ -1643,6 +1647,27 @@ class Admin
$notifications_file->save();
}
foreach ($notifications as $location => $list) {
$notifications[$location] = array_filter($list, function ($notification) use ($userStatus_content) {
$element = $userStatus_content[$notification['id']] ?? null;
if (isset($element)) {
if (isset($notification['reappear_after'])) {
$now = new \DateTime();
$hidden_on = new \DateTime($element);
$hidden_on->modify($notification['reappear_after']);
if ($now >= $hidden_on) {
return true;
}
}
return false;
}
return true;
});
}
return $notifications;
}