Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions lib/MailQueueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']);
Expand All @@ -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']);
Expand Down
30 changes: 19 additions & 11 deletions lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -47,6 +48,9 @@ class Personal implements ISettings {
protected $l10n;

/** @var string */
protected $userId;

/** @var null|IUser */
protected $user;

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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,
];
}
Expand All @@ -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) {
Expand All @@ -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');
}

Expand Down