diff options
author | Anna Larch <anna@nextcloud.com> | 2021-07-07 12:45:00 +0300 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2021-07-12 16:03:34 +0300 |
commit | 6d44305d0f1133f15d2b7fabad1a5919d4b43546 (patch) | |
tree | 820954e99f3377e1ec785b8877a7e5214e4a1cff /lib | |
parent | 4ecb5a1f060a5a8f25722d0676f8b67b005cbbd6 (diff) |
Move userId to controller
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 4 | ||||
-rw-r--r-- | lib/Contracts/IUserPreferences.php | 6 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 10 | ||||
-rw-r--r-- | lib/Controller/PreferencesController.php | 12 | ||||
-rw-r--r-- | lib/Listener/AddressCollectionListener.php | 2 | ||||
-rw-r--r-- | lib/Listener/NewMessageClassificationListener.php | 4 | ||||
-rw-r--r-- | lib/Service/AvatarService.php | 6 | ||||
-rw-r--r-- | lib/Service/UserPreferenceService.php (renamed from lib/Service/UserPreferenceSevice.php) | 20 |
8 files changed, 35 insertions, 29 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 43a447537..65c7e68d2 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -61,7 +61,7 @@ use OCA\Mail\Service\MailManager; use OCA\Mail\Service\MailTransmission; use OCA\Mail\Service\Search\MailSearch; use OCA\Mail\Service\TrustedSenderService; -use OCA\Mail\Service\UserPreferenceSevice; +use OCA\Mail\Service\UserPreferenceService; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -96,7 +96,7 @@ class Application extends App implements IBootstrap { $context->registerServiceAlias(IMailSearch::class, MailSearch::class); $context->registerServiceAlias(IMailTransmission::class, MailTransmission::class); $context->registerServiceAlias(ITrustedSenderService::class, TrustedSenderService::class); - $context->registerServiceAlias(IUserPreferences::class, UserPreferenceSevice::class); + $context->registerServiceAlias(IUserPreferences::class, UserPreferenceService::class); $context->registerEventListener(DraftSavedEvent::class, DeleteDraftListener::class); $context->registerEventListener(MailboxesSynchronizedEvent::class, MailboxesSynchronizedSpecialMailboxesUpdater::class); diff --git a/lib/Contracts/IUserPreferences.php b/lib/Contracts/IUserPreferences.php index efaed8e45..765cae347 100644 --- a/lib/Contracts/IUserPreferences.php +++ b/lib/Contracts/IUserPreferences.php @@ -29,15 +29,17 @@ namespace OCA\Mail\Contracts; interface IUserPreferences { /** + * @param string $userId * @param string $key * @param mixed $value * @return mixed new value */ - public function setPreference($key, $value); + public function setPreference(string $userId, $key, $value); /** + * @param string $userId * @param string $key * @param mixed|null $default */ - public function getPreference($key, $default = null); + public function getPreference(string $userId, $key, $default = null); } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 554ab07ef..a337254e4 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -143,7 +143,7 @@ class PageController extends Controller { ); $this->initialStateService->provideInitialState( 'account-settings', - json_decode($this->preferences->getPreference('account-settings', '[]'), true, 512, JSON_THROW_ON_ERROR) ?? [] + json_decode($this->preferences->getPreference($this->currentUserId, 'account-settings', '[]'), true, 512, JSON_THROW_ON_ERROR) ?? [] ); $this->initialStateService->provideInitialState( 'tags', @@ -155,10 +155,10 @@ class PageController extends Controller { [ 'attachment-size-limit' => $this->config->getSystemValue('app.mail.attachment-size-limit', 0), 'app-version' => $this->config->getAppValue('mail', 'installed_version'), - 'external-avatars' => $this->preferences->getPreference('external-avatars', 'true'), - 'reply-mode' => $this->preferences->getPreference('reply-mode', 'top'), - 'collect-data' => $this->preferences->getPreference('collect-data', 'true'), - 'tag-classified-messages' => $this->preferences->getPreference('tag-classified-messages', 'true'), + 'external-avatars' => $this->preferences->getPreference($this->currentUserId, 'external-avatars', 'true'), + 'reply-mode' => $this->preferences->getPreference($this->currentUserId, 'reply-mode', 'top'), + 'collect-data' => $this->preferences->getPreference($this->currentUserId, 'collect-data', 'true'), + 'tag-classified-messages' => $this->preferences->getPreference($this->currentUserId, 'tag-classified-messages', 'true'), ]); $this->initialStateService->provideInitialState( 'prefill_displayName', diff --git a/lib/Controller/PreferencesController.php b/lib/Controller/PreferencesController.php index 201b8be38..2d0e7d3cd 100644 --- a/lib/Controller/PreferencesController.php +++ b/lib/Controller/PreferencesController.php @@ -37,14 +37,19 @@ class PreferencesController extends Controller { /** @var IUserPreferences */ private $userPreference; + /** @var string */ + private $userId; + /** * @param IRequest $request * @param IUserPreferences $userPreference + * @param string $UserId */ - public function __construct(IRequest $request, IUserPreferences $userPreference) { + public function __construct(IRequest $request, IUserPreferences $userPreference, string $UserId) { parent::__construct('mail', $request); $this->userPreference = $userPreference; + $this->userId = $UserId; } /** @@ -56,7 +61,7 @@ class PreferencesController extends Controller { */ public function show(string $id): JSONResponse { return new JSONResponse([ - 'value' => $this->userPreference->getPreference($id) + 'value' => $this->userPreference->getPreference($this->userId, $id) ]); } @@ -74,7 +79,8 @@ class PreferencesController extends Controller { throw new ClientException('key or value missing'); } - $newValue = $this->userPreference->setPreference($key, $value); + + $newValue = $this->userPreference->setPreference($this->userId, $key, $value); return new JSONResponse([ 'value' => $newValue, diff --git a/lib/Listener/AddressCollectionListener.php b/lib/Listener/AddressCollectionListener.php index 9486c8ded..2b430aacd 100644 --- a/lib/Listener/AddressCollectionListener.php +++ b/lib/Listener/AddressCollectionListener.php @@ -56,7 +56,7 @@ class AddressCollectionListener implements IEventListener { if (!($event instanceof MessageSentEvent)) { return; } - if ($this->preferences->getPreference('collect-data', 'true') !== 'true') { + if ($this->preferences->getPreference($event->getAccount()->getUserId(), 'collect-data', 'true') !== 'true') { $this->logger->debug('Not collecting email addresses because the user opted out'); return; } diff --git a/lib/Listener/NewMessageClassificationListener.php b/lib/Listener/NewMessageClassificationListener.php index d370d9b9d..501fb3a6e 100644 --- a/lib/Listener/NewMessageClassificationListener.php +++ b/lib/Listener/NewMessageClassificationListener.php @@ -79,8 +79,8 @@ class NewMessageClassificationListener implements IEventListener { return; } - $allowTagging = $this->preferences->getPreference('tag-classified-messages'); - if ($allowTagging === "false") { + $allowTagging = $this->preferences->getPreference($event->getAccount()->getUserId(), 'tag-classified-messages'); + if ($allowTagging === 'false') { return; } diff --git a/lib/Service/AvatarService.php b/lib/Service/AvatarService.php index 71473ae24..03e9a2c8b 100644 --- a/lib/Service/AvatarService.php +++ b/lib/Service/AvatarService.php @@ -77,8 +77,8 @@ class AvatarService implements IAvatarService { /** * @return bool */ - private function externalAvatarsAllowed(): bool { - return $this->preferences->getPreference('external-avatars', 'true') === 'true'; + private function externalAvatarsAllowed(string $uid): bool { + return $this->preferences->getPreference($uid, 'external-avatars', 'true') === 'true'; } /** @@ -115,7 +115,7 @@ class AvatarService implements IAvatarService { return null; } - $avatar = $this->source->fetch($email, $this->avatarFactory, $this->externalAvatarsAllowed()); + $avatar = $this->source->fetch($email, $this->avatarFactory, $this->externalAvatarsAllowed($uid)); if (is_null($avatar) || !$this->hasAllowedMime($avatar)) { // Cannot locate any avatar -> nothing to do here diff --git a/lib/Service/UserPreferenceSevice.php b/lib/Service/UserPreferenceService.php index aff05ace0..192435546 100644 --- a/lib/Service/UserPreferenceSevice.php +++ b/lib/Service/UserPreferenceService.php @@ -29,38 +29,36 @@ namespace OCA\Mail\Service; use OCA\Mail\Contracts\IUserPreferences; use OCP\IConfig; -class UserPreferenceSevice implements IUserPreferences { +class UserPreferenceService implements IUserPreferences { /** @var IConfig */ private $config; - /** @var string */ - private $UserId; - /** * @param IConfig $config - * @param string $UserId */ - public function __construct(IConfig $config, $UserId) { + public function __construct(IConfig $config) { $this->config = $config; - $this->UserId = $UserId; } /** + * @param string $userId * @param string $key * @param mixed $value * @return mixed new value */ - public function setPreference($key, $value) { - $this->config->setUserValue($this->UserId, 'mail', $key, $value); + public function setPreference(string $userId, $key, $value) { + $this->config->setUserValue($userId, 'mail', $key, $value); return $value; } /** + * @param string $userId * @param string $key * @param mixed|null $default + * @return string */ - public function getPreference($key, $default = null) { - return $this->config->getUserValue($this->UserId, 'mail', $key, $default); + public function getPreference(string $userId, $key, $default = null) { + return $this->config->getUserValue($userId, 'mail', $key, $default); } } |