-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathSetUserDefaults.php
64 lines (52 loc) · 1.42 KB
/
SetUserDefaults.php
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: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Activity\Listener;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IUser;
use OCP\User\Events\PostLoginEvent;
/**
* @template-implements IEventListener<Event>
*/
class SetUserDefaults implements IEventListener {
/** @var IConfig */
private $config;
public function __construct(IConfig $config) {
$this->config = $config;
}
public function handle(Event $event): void {
if (!($event instanceof PostLoginEvent)) {
return;
}
$user = $event->getUser();
$this->setDefaultsForUser($user);
}
private function setDefaultsForUser(IUser $user): void {
if ($this->config->getUserValue($user->getUID(), 'activity', 'configured', 'no') === 'yes') {
// Already has settings
return;
}
foreach ($this->config->getAppKeys('activity') as $key) {
if (strpos($key, 'notify_') !== 0) {
continue;
}
if ($this->config->getUserValue($user->getUID(), 'activity', $key, null) !== null) {
// Already has this setting
continue;
}
$this->config->setUserValue(
$user->getUID(),
'activity',
$key,
$this->config->getAppValue('activity', $key)
);
}
// Mark settings as configured
$this->config->setUserValue($user->getUID(), 'activity', 'configured', 'yes');
}
}