Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not send daily digest email to user who is disabled #1803

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
25 changes: 21 additions & 4 deletions lib/DigestSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
Expand Down Expand Up @@ -68,6 +69,12 @@ public function sendDigests(int $now): void {
// User got todays digest already
continue;
}
$user = $this->userManager->get($user);
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
if (!$user->isEnabled()) {
// User is disabled so do not send the email but update last sent since after enabling avoid flooding
$this->updateLastSentForUser($user, $now);
continue;
}

try {
$this->sendDigestForUser($user, $now, $timezone, $language);
Expand All @@ -78,7 +85,7 @@ public function sendDigests(int $now): void {
}
// We still update the digest time after an failed email,
// so it hopefully works tomorrow
$this->config->setUserValue($user, 'activity', 'digest', $timezoneDigestDay[$timezone]);
$this->config->setUserValue($user->getUID(), 'activity', 'digest', $timezoneDigestDay[$timezone]);
}

$this->activityManager->setRequirePNG(false);
Expand All @@ -103,11 +110,21 @@ private function getLastSendActivity(string $user, int $now): int {
return $this->data->getFirstActivitySince($user, $now - (24 * 60 * 60));
}

public function sendDigestForUser(string $uid, int $now, string $timezone, string $language) {
public function updateLastSentForUser(IUser $user, int $now): void {
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
$uid = $user->getUID();
$lastSend = $this->getLastSendActivity($uid, $now);

['count' => $count, 'max' => $lastActivityId] = $this->data->getActivitySince($uid, $lastSend, true);
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
$lastActivityId = (int)$lastActivityId;

$this->config->setUserValue($uid, 'activity', 'activity_digest_last_send', (string)$lastActivityId);
}

public function sendDigestForUser(IUser $user, int $now, string $timezone, string $language) {
$uid = $user->getUID();
$l10n = $this->l10nFactory->get('activity', $language);
$this->groupHelper->setL10n($l10n);
$lastSend = $this->getLastSendActivity($uid, $now);
$user = $this->userManager->get($uid);
if ($lastSend === 0) {
return;
}
Expand Down Expand Up @@ -181,7 +198,7 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin
$this->activityManager->setCurrentUserId(null);
try {
$this->mailer->send($message);
$this->config->setUserValue($user->getUID(), 'activity', 'activity_digest_last_send', (string)$lastActivityId);
$this->config->setUserValue($uid, 'activity', 'activity_digest_last_send', (string)$lastActivityId);
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
return;
Expand Down
Loading