From 12fa3424a4ad6207695fc0f2806252959055875a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 15 Aug 2020 01:13:31 +0200 Subject: [PATCH] only send activity by others in digest mail Signed-off-by: Robin Appelman --- lib/Data.php | 10 ++++++++-- lib/DigestSender.php | 14 +++----------- templates/settings/personal.php | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/Data.php b/lib/Data.php index 6b2de5f23..2eac93cb9 100755 --- a/lib/Data.php +++ b/lib/Data.php @@ -450,15 +450,21 @@ public function getFirstActivitySince(string $user, int $timestamp): int { * * @param string $user * @param int $since + * @param bool $byOthers * @return array */ - public function getActivitySince(string $user, int $since) { + public function getActivitySince(string $user, int $since, bool $byOthers) { $query = $this->connection->getQueryBuilder(); + $nameParam = $query->createNamedParameter($user); $query->select($query->func()->count('activity_id'), $query->func()->max('activity_id')) ->from('activity') - ->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user))) + ->where($query->expr()->eq('affecteduser', $nameParam)) ->andWhere($query->expr()->gt('activity_id', $query->createNamedParameter($since, IQueryBuilder::PARAM_INT))); + if ($byOthers) { + $query->andWhere($query->expr()->neq('user', $nameParam)); + } + return $query->execute()->fetch(); } } diff --git a/lib/DigestSender.php b/lib/DigestSender.php index df7025e15..f70944a56 100644 --- a/lib/DigestSender.php +++ b/lib/DigestSender.php @@ -115,7 +115,7 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin return; } - ['count' => $count, 'max' => $lastActivityId] = $this->data->getActivitySince($uid, $lastSend); + ['count' => $count, 'max' => $lastActivityId] = $this->data->getActivitySince($uid, $lastSend, true); if ($count == 0) { return; } @@ -128,7 +128,7 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin $lastSend, self::ACTIVITY_LIMIT, 'asc', - 'all', + 'by', '', 0, true @@ -141,15 +141,8 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin 'activityEvents' => $activities, 'skippedCount' => $skippedCount, ]); - $template->setSubject($l10n->t('Daily activity digest for ' . $this->defaults->getName())); + $template->setSubject($l10n->t('Daily activity summary for ' . $this->defaults->getName())); $template->addHeader(); - $template->addHeading($l10n->t('Hello %s', [$user->getDisplayName()]), $l10n->t('Hello %s,', [$user->getDisplayName()])); - - $homeLink = '' . htmlspecialchars($this->defaults->getName()) . ''; - $template->addBodyText( - $l10n->t('There was some activity at %s', [$homeLink]), - $l10n->t('There was some activity at %s', [$this->urlGenerator->getAbsoluteURL('/')]) - ); foreach ($activities as $event) { $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay( @@ -176,7 +169,6 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin try { $this->mailer->send($message); - var_dump($lastActivityId); $this->config->setUserValue($user->getUID(), 'activity', 'activity_digest_last_send', $lastActivityId); } catch (\Exception $e) { var_dump($e->getMessage()); diff --git a/templates/settings/personal.php b/templates/settings/personal.php index 190de2900..3d4f900b1 100644 --- a/templates/settings/personal.php +++ b/templates/settings/personal.php @@ -41,5 +41,5 @@ /> - +