-
-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathActivitySettingsStore.php
More file actions
64 lines (51 loc) · 1.55 KB
/
Copy pathActivitySettingsStore.php
File metadata and controls
64 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Service;
class ActivitySettingsStore {
private const USER_SETTINGS_CLASS = 'OCA\\Activity\\UserSettings';
private bool $resolved = false;
private ?object $activityUserSettings = null;
public function isAvailable(): bool {
return $this->getActivityUserSettings() !== null;
}
public function hasSetting(string $type): bool {
if (!$this->isAvailable()) {
return false;
}
try {
$manager = \OCP\Server::get(\OCP\Activity\IManager::class);
$manager->getSettingById($type);
return true;
} catch (\Throwable) {
return false;
}
}
public function getAdminSetting(string $channel, string $type): mixed {
return $this->getActivityUserSettings()?->getAdminSetting($channel, $type);
}
public function getUserSetting(string $userId, string $channel, string $type): mixed {
return $this->getActivityUserSettings()?->getUserSetting($userId, $channel, $type);
}
private function getActivityUserSettings(): ?object {
if ($this->resolved) {
return $this->activityUserSettings;
}
$this->resolved = true;
if (!class_exists(self::USER_SETTINGS_CLASS)) {
return null;
}
try {
$activityUserSettings = \OCP\Server::get(self::USER_SETTINGS_CLASS);
if (is_object($activityUserSettings)) {
$this->activityUserSettings = $activityUserSettings;
}
} catch (\Throwable) {
$this->activityUserSettings = null;
}
return $this->activityUserSettings;
}
}