From c4790c13c7cbc89c28bcf4e1407794c7f01d8390 Mon Sep 17 00:00:00 2001 From: yemkareems Date: Tue, 24 Sep 2024 17:13:15 +0530 Subject: [PATCH 1/5] fix: do not send daily digest email to user who is disabled --- lib/DigestSender.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DigestSender.php b/lib/DigestSender.php index 75adc28cb..d2f44caa3 100644 --- a/lib/DigestSender.php +++ b/lib/DigestSender.php @@ -108,7 +108,7 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin $this->groupHelper->setL10n($l10n); $lastSend = $this->getLastSendActivity($uid, $now); $user = $this->userManager->get($uid); - if ($lastSend === 0) { + if ($lastSend === 0 || !$user->isEnabled()) { return; } $this->activityManager->setCurrentUserId($uid); From 1583c3d75c423251550ba29ddf7f05bcfea10a56 Mon Sep 17 00:00:00 2001 From: yemkareems Date: Wed, 9 Oct 2024 10:24:22 +0530 Subject: [PATCH 2/5] fix: do not send digest email for disabled user --- lib/DigestSender.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/DigestSender.php b/lib/DigestSender.php index d2f44caa3..03c44bcf2 100644 --- a/lib/DigestSender.php +++ b/lib/DigestSender.php @@ -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; @@ -68,6 +69,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); @@ -103,12 +110,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); @@ -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; From 7222b5ff41370722671749b53ad1016472170b35 Mon Sep 17 00:00:00 2001 From: yemkareems Date: Tue, 15 Oct 2024 10:18:29 +0530 Subject: [PATCH 3/5] fix: cs fix and psalm error fix --- lib/DigestSender.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DigestSender.php b/lib/DigestSender.php index 03c44bcf2..b7d59d1d6 100644 --- a/lib/DigestSender.php +++ b/lib/DigestSender.php @@ -70,7 +70,7 @@ public function sendDigests(int $now): void { continue; } $user = $this->userManager->get($user); - if(!$user->isEnabled()) { + 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; @@ -85,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); From 4bd553020b5f71fe48f0f6ea24e9319a02a40fb5 Mon Sep 17 00:00:00 2001 From: yemkareems Date: Fri, 18 Oct 2024 10:10:34 +0530 Subject: [PATCH 4/5] fix: updateLastSentForUser changed to private and removed count as it is not used Signed-off-by: yemkareems --- lib/DigestSender.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DigestSender.php b/lib/DigestSender.php index b7d59d1d6..f5b50dfd1 100644 --- a/lib/DigestSender.php +++ b/lib/DigestSender.php @@ -110,11 +110,11 @@ private function getLastSendActivity(string $user, int $now): int { return $this->data->getFirstActivitySince($user, $now - (24 * 60 * 60)); } - public function updateLastSentForUser(IUser $user, int $now): void { + private 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); + ['max' => $lastActivityId] = $this->data->getActivitySince($uid, $lastSend, true); $lastActivityId = (int)$lastActivityId; $this->config->setUserValue($uid, 'activity', 'activity_digest_last_send', (string)$lastActivityId); From b8038f48f08f97b34776455f44755a0b9886701f Mon Sep 17 00:00:00 2001 From: yemkareems Date: Mon, 28 Oct 2024 10:08:45 +0530 Subject: [PATCH 5/5] fix: user renamed to userObject Signed-off-by: yemkareems --- lib/DigestSender.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/DigestSender.php b/lib/DigestSender.php index f5b50dfd1..ec99ef99d 100644 --- a/lib/DigestSender.php +++ b/lib/DigestSender.php @@ -69,15 +69,15 @@ public function sendDigests(int $now): void { // User got todays digest already continue; } - $user = $this->userManager->get($user); - if (!$user->isEnabled()) { + $userObject = $this->userManager->get($user); + if (!$userObject->isEnabled()) { // User is disabled so do not send the email but update last sent since after enabling avoid flooding - $this->updateLastSentForUser($user, $now); + $this->updateLastSentForUser($userObject, $now); continue; } try { - $this->sendDigestForUser($user, $now, $timezone, $language); + $this->sendDigestForUser($userObject, $now, $timezone, $language); } catch (\Throwable $e) { $this->logger->error('Exception occurred while sending user digest email', [ 'exception' => $e, @@ -85,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->getUID(), 'activity', 'digest', $timezoneDigestDay[$timezone]); + $this->config->setUserValue($userObject->getUID(), 'activity', 'digest', $timezoneDigestDay[$timezone]); } $this->activityManager->setRequirePNG(false);