Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: do not send digest email for disabled user
  • Loading branch information
yemkareems authored and backportbot[bot] committed Oct 28, 2024
commit 459d5df7e8199482103aac0ce189c79a3d57d34d
23 changes: 20 additions & 3 deletions lib/DigestSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -83,6 +84,12 @@ public function sendDigests(int $now): void {
// User got todays digest already
continue;
}
$user = $this->userManager->get($user);
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 Down Expand Up @@ -118,12 +125,22 @@ 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 {
$uid = $user->getUID();
$lastSend = $this->getLastSendActivity($uid, $now);

['count' => $count, 'max' => $lastActivityId] = $this->data->getActivitySince($uid, $lastSend, true);
$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 || !$user->isEnabled()) {
if ($lastSend === 0) {
return;
}
$this->activityManager->setCurrentUserId($uid);
Expand Down