Skip to content

Commit

Permalink
only send activity by others in digest mail
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Aug 15, 2020
1 parent 7336403 commit 12fa342
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
10 changes: 8 additions & 2 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
14 changes: 3 additions & 11 deletions lib/DigestSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -128,7 +128,7 @@ public function sendDigestForUser(string $uid, int $now, string $timezone, strin
$lastSend,
self::ACTIVITY_LIMIT,
'asc',
'all',
'by',
'',
0,
true
Expand All @@ -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 = '<a href="' . $this->urlGenerator->getAbsoluteURL('/') . '">' . htmlspecialchars($this->defaults->getName()) . '</a>';
$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(
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion templates/settings/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@

<input id="activity_email_enabled" name="activity_digest" type="checkbox" class="checkbox"
value="1" <?php if ($_['activity_digest_enabled']) { print_unescaped('checked="checked"'); } ?> />
<label for="activity_email_enabled"><?php p($l->t('Send daily activity digest')); ?></label>
<label for="activity_email_enabled"><?php p($l->t('Send daily activity summary')); ?></label>
</form>

0 comments on commit 12fa342

Please sign in to comment.