Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remember the updatedAt time of any notification associated with a WP
Signed-off-by: Artur Neumann <[email protected]>
  • Loading branch information
individual-it committed Nov 8, 2022
commit 3907ea69f2bb33a5ddc7472f499347850b0f7fbc
29 changes: 28 additions & 1 deletion lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,17 @@ private function checkNotificationsForUser(string $userId): void {
'resourceTitle' => $n['_links']['resource']['title'],
'projectTitle' => $n['_links']['project']['title'],
'count' => 1,
'updatedAt' => $n['updatedAt']
];
} else {
$storedUpdatedAt = \Safe\strtotime($aggregatedNotifications[$wpId]['updatedAt']);
if (\Safe\strtotime($n['updatedAt']) > $storedUpdatedAt) {
// currently the code never comes here because the notifications are ordered
// by 'updatedAt' but as backup I would keep it
$aggregatedNotifications[$wpId]['updatedAt'] = $n['updatedAt'];
}
$aggregatedNotifications[$wpId]['count']++;

}
$aggregatedNotifications[$wpId]['reasons'][] = $n['reason'];
$aggregatedNotifications[$wpId]['actors'][] = $n['_links']['actor']['title'];
Expand All @@ -182,7 +190,26 @@ private function checkNotificationsForUser(string $userId): void {
'refresh-notifications-in-progress',
'true'
);
$manager->markProcessed($notificationsFilter);
$currentNotifications = $this->handler->get($notificationsFilter);
foreach ($currentNotifications as $notificationId => $currentNotification) {
$parametersCurrentNotifications = $currentNotification->getSubjectParameters();
$wpId = $parametersCurrentNotifications['wpId'];
if (isset($aggregatedNotifications[$wpId])) {
$currentNotificationUpdateTime = \Safe\strtotime($parametersCurrentNotifications['updatedAt']);
$newNotificationUpdateTime = \Safe\strtotime($aggregatedNotifications[$wpId]['updatedAt']);

if ($newNotificationUpdateTime <= $currentNotificationUpdateTime) {
// nothing changed with any notification associated with that WP
// so get rid of it
unset($aggregatedNotifications[$wpId]);
} else {
$manager->markProcessed($currentNotification);
}
} else { // there are no notifications in OP associated with that WP
$manager->markProcessed($currentNotification);
}

}

foreach ($aggregatedNotifications as $n) {
$n['reasons'] = array_unique($n['reasons']);
Expand Down