Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
NotificationHistoryService
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFirst
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 recordAccepted
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Service\Notification;
10
11use OCA\Libresign\Db\SignRequest;
12use OCA\Libresign\Db\SignRequestMapper;
13
14/**
15 * Backward-compatible projection for reminders.
16 * Only an accepted channel submission counts as a delivered notification.
17 */
18final class NotificationHistoryService {
19    public function __construct(
20        private SignRequestMapper $signRequestMapper,
21    ) {
22    }
23
24    public function isFirst(SignRequest $request, string $method): bool {
25        $metadata = $this->signRequestMapper->getByIdUncached($request->getId())->getMetadata() ?? [];
26        foreach ($metadata['notify'] ?? [] as $item) {
27            if (($item['method'] ?? null) === $method) {
28                return false;
29            }
30        }
31        return true;
32    }
33
34    public function recordAccepted(NotificationMessage $message): void {
35        if ($message->eventType === 'sign_request' && $message->historyMethod !== null) {
36            $this->signRequestMapper->incrementNotificationCounter($message->signRequest, $message->historyMethod);
37        }
38    }
39}