diff --git a/lib/CurrentUser.php b/lib/CurrentUser.php index aab1ae5a7..7e0512337 100644 --- a/lib/CurrentUser.php +++ b/lib/CurrentUser.php @@ -57,6 +57,10 @@ public function __construct(IUserSession $userSession, IRequest $request, IManag $this->sessionUser = false; } + public function getUser(): ?IUser { + return $this->userSession->getUser(); + } + /** * Get an identifier for the user, session or token * @return string @@ -79,7 +83,7 @@ public function getUserIdentifier() { } /** - * Get the current user from the session + * Get the current user id from the session * @return string|null */ public function getUID() { @@ -96,7 +100,7 @@ public function getUID() { } /** - * Get the current user from the session + * Get the current user cloud id from the session * @return string|null */ public function getCloudId() { diff --git a/lib/MailQueueHandler.php b/lib/MailQueueHandler.php index 5f64a8907..9d6d89a33 100644 --- a/lib/MailQueueHandler.php +++ b/lib/MailQueueHandler.php @@ -134,7 +134,6 @@ public function sendEmails($limit, $sendTime, $forceSending = false, $restrictEm $userLanguages = $this->config->getUserValueForUsers('core', 'lang', $affectedUsers); $userTimezones = $this->config->getUserValueForUsers('core', 'timezone', $affectedUsers); - $userEmails = $this->config->getUserValueForUsers('settings', 'email', $affectedUsers); $userEnabled = $this->config->getUserValueForUsers('core', 'enabled', $affectedUsers); // Send Email @@ -149,7 +148,9 @@ public function sendEmails($limit, $sendTime, $forceSending = false, $restrictEm continue; } - if (empty($userEmails[$user])) { + $userObject = $this->userManager->get($user); + $email = $userObject ? $userObject->getEMailAddress() : ''; + if (empty($email)) { // The user did not setup an email address // So we will not send an email :( $this->logger->debug("Couldn't send notification email to user '{user}' (email address isn't set for that user)", ['user' => $user, 'app' => 'activity']); @@ -160,7 +161,7 @@ public function sendEmails($limit, $sendTime, $forceSending = false, $restrictEm $language = (!empty($userLanguages[$user])) ? $userLanguages[$user] : $default_lang; $timezone = (!empty($userTimezones[$user])) ? $userTimezones[$user] : $defaultTimeZone; try { - if ($this->sendEmailToUser($user, $userEmails[$user], $language, $timezone, $sendTime)) { + if ($this->sendEmailToUser($user, $email, $language, $timezone, $sendTime)) { $deleteItemsForUsers[] = $user; } else { $this->logger->debug("Failed sending activity email to user '{user}'.", ['user' => $user, 'app' => 'activity']); diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 47bc48767..7e87c5d57 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -31,6 +31,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IL10N; +use OCP\IUser; use OCP\Settings\ISettings; class Personal implements ISettings { @@ -47,6 +48,9 @@ class Personal implements ISettings { protected $l10n; /** @var string */ + protected $userId; + + /** @var null|IUser */ protected $user; /** @@ -58,16 +62,19 @@ class Personal implements ISettings { * @param IL10N $l10n * @param CurrentUser $currentUser */ - public function __construct(IConfig $config, - IManager $manager, - UserSettings $userSettings, - IL10N $l10n, - CurrentUser $currentUser) { + public function __construct( + IConfig $config, + IManager $manager, + UserSettings $userSettings, + IL10N $l10n, + CurrentUser $currentUser + ) { $this->config = $config; $this->manager = $manager; $this->userSettings = $userSettings; $this->l10n = $l10n; - $this->user = (string) $currentUser->getUID(); + $this->userId = (string) $currentUser->getUID(); + $this->user = $currentUser->getUser(); } /** @@ -111,8 +118,8 @@ public function getForm() { $activityGroups[$groupIdentifier]['activities'][$identifier] = [ 'desc' => $setting->getName(), - IExtension::METHOD_MAIL => $this->userSettings->getUserSetting($this->user, 'email', $identifier), - IExtension::METHOD_NOTIFICATION => $this->userSettings->getUserSetting($this->user, 'notification', $identifier), + IExtension::METHOD_MAIL => $this->userSettings->getUserSetting($this->userId, 'email', $identifier), + IExtension::METHOD_NOTIFICATION => $this->userSettings->getUserSetting($this->userId, 'notification', $identifier), 'methods' => $methods, ]; } @@ -124,7 +131,7 @@ public function getForm() { } $settingBatchTime = UserSettings::EMAIL_SEND_HOURLY; - $currentSetting = (int) $this->userSettings->getUserSetting($this->user, 'setting', 'batchtime'); + $currentSetting = (int) $this->userSettings->getUserSetting($this->userId, 'setting', 'batchtime'); if ($currentSetting === 3600 * 24 * 7) { $settingBatchTime = UserSettings::EMAIL_SEND_WEEKLY; } elseif ($currentSetting === 3600 * 24) { @@ -146,17 +153,18 @@ public function getForm() { $methods[IExtension::METHOD_NOTIFICATION] = $this->l10n->t('Push'); } + return new TemplateResponse('activity', 'settings/personal', [ 'setting' => 'personal', 'activityGroups' => $activityGroups, - 'is_email_set' => !empty($this->config->getUserValue($this->user, 'settings', 'email', '')), + 'is_email_set' => $this->user instanceof IUser && !empty($this->user->getEMailAddress()), 'email_enabled' => $emailEnabled, 'setting_batchtime' => $settingBatchTime, 'methods' => $methods, - 'activity_digest_enabled' => $this->userSettings->getUserSetting($this->user, 'setting', 'activity_digest') + 'activity_digest_enabled' => $this->userSettings->getUserSetting($this->userId, 'setting', 'activity_digest') ], 'blank'); }