Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
7 / 21 |
|
33.33% |
2 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ActivitySettingsStore | |
33.33% |
7 / 21 |
|
33.33% |
2 / 6 |
54.67 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isAvailable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasSetting | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getAdminSetting | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserSetting | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getActivityUserSettings | |
45.45% |
5 / 11 |
|
0.00% |
0 / 1 |
9.06 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service; |
| 10 | |
| 11 | use OCP\Activity\IManager; |
| 12 | |
| 13 | class ActivitySettingsStore { |
| 14 | private const USER_SETTINGS_CLASS = 'OCA\\Activity\\UserSettings'; |
| 15 | |
| 16 | private bool $resolved = false; |
| 17 | private ?object $activityUserSettings = null; |
| 18 | |
| 19 | public function __construct( |
| 20 | private IManager $activityManager, |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public function isAvailable(): bool { |
| 25 | return $this->getActivityUserSettings() !== null; |
| 26 | } |
| 27 | |
| 28 | public function hasSetting(string $type): bool { |
| 29 | if (!$this->isAvailable()) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | try { |
| 34 | $this->activityManager->getSettingById($type); |
| 35 | return true; |
| 36 | } catch (\Throwable) { |
| 37 | return false; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public function getAdminSetting(string $channel, string $type): mixed { |
| 42 | return $this->getActivityUserSettings()?->getAdminSetting($channel, $type); |
| 43 | } |
| 44 | |
| 45 | public function getUserSetting(string $userId, string $channel, string $type): mixed { |
| 46 | return $this->getActivityUserSettings()?->getUserSetting($userId, $channel, $type); |
| 47 | } |
| 48 | |
| 49 | private function getActivityUserSettings(): ?object { |
| 50 | if ($this->resolved) { |
| 51 | return $this->activityUserSettings; |
| 52 | } |
| 53 | |
| 54 | $this->resolved = true; |
| 55 | if (!class_exists(self::USER_SETTINGS_CLASS)) { |
| 56 | return null; |
| 57 | } |
| 58 | |
| 59 | try { |
| 60 | $activityUserSettings = \OCP\Server::get(self::USER_SETTINGS_CLASS); |
| 61 | if (is_object($activityUserSettings)) { |
| 62 | $this->activityUserSettings = $activityUserSettings; |
| 63 | } |
| 64 | } catch (\Throwable) { |
| 65 | $this->activityUserSettings = null; |
| 66 | } |
| 67 | |
| 68 | return $this->activityUserSettings; |
| 69 | } |
| 70 | } |