Skip to content

Commit aae6fb7

Browse files
committed
feat: use full date and time in activity emails
Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent e26cdc4 commit aae6fb7

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

lib/MailQueueHandler.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(
6464
* @param $limit Number of users we want to send an email to
6565
* @param $sendTime The latest send time
6666
* @param $forceSending Ignores latest send and just sends all emails
67-
* @param $restrictEmails null or one of UserSettings::EMAIL_SEND_*
67+
* @param $restrictEmails null or one of UserSettings::EMAIL_SEND_*, will overwrite force send
6868
* @return int Number of users we sent an email to
6969
*/
7070
public function sendEmails(int $limit, int $sendTime, bool $forceSending = false, ?int $restrictEmails = null): int {
@@ -141,12 +141,6 @@ protected function getAffectedUsers(?int $limit, int $latestSend, bool $forceSen
141141
$query->setMaxResults($limit);
142142
}
143143

144-
if ($forceSending) {
145-
$query->where($query->expr()->lt('amq_timestamp', $query->createNamedParameter($latestSend)));
146-
} else {
147-
$query->where($query->expr()->lt('amq_latest_send', $query->createNamedParameter($latestSend)));
148-
}
149-
150144
if ($restrictEmails !== null) {
151145
if ($restrictEmails === UserSettings::EMAIL_SEND_HOURLY) {
152146
$query->where($query->expr()->eq('amq_timestamp', $query->func()->subtract('amq_latest_send', $query->expr()->literal(3600))));
@@ -157,6 +151,22 @@ protected function getAffectedUsers(?int $limit, int $latestSend, bool $forceSen
157151
} elseif ($restrictEmails === UserSettings::EMAIL_SEND_ASAP) {
158152
$query->where($query->expr()->eq('amq_timestamp', 'amq_latest_send'));
159153
}
154+
155+
$result = $query->executeQuery();
156+
157+
$affectedUsers = [];
158+
while ($row = $result->fetch()) {
159+
$affectedUsers[] = $row['amq_affecteduser'];
160+
}
161+
$result->closeCursor();
162+
163+
return $affectedUsers;
164+
}
165+
166+
if ($forceSending) {
167+
$query->where($query->expr()->lt('amq_timestamp', $query->createNamedParameter($latestSend)));
168+
} else {
169+
$query->where($query->expr()->lt('amq_latest_send', $query->createNamedParameter($latestSend)));
160170
}
161171

162172
$result = $query->executeQuery();
@@ -294,7 +304,7 @@ protected function sendEmailToUser(string $userName, string $email, string $lang
294304
function ($event) use ($timezone, $l) {
295305
return [
296306
'event' => $event,
297-
'relativeDateTime' => $this->dateFormatter->formatDateTimeRelativeDay(
307+
'dateTime' => $this->dateFormatter->formatDateTime(
298308
$event->getTimestamp(),
299309
'long', 'short',
300310
new \DateTimeZone($timezone), $l
@@ -322,9 +332,9 @@ function ($event) use ($timezone, $l) {
322332

323333
foreach ($activityEvents as $activity) {
324334
$event = $activity['event'];
325-
$relativeDateTime = $activity['relativeDateTime'];
335+
$activityDateTime = $activity['dateTime'];
326336

327-
$template->addBodyListItem($this->getHTMLSubject($event), $relativeDateTime, $event->getIcon(), $event->getParsedSubject());
337+
$template->addBodyListItem($this->getHTMLSubject($event), $activityDateTime, $event->getIcon(), $event->getParsedSubject());
328338
}
329339

330340
if ($skippedCount) {

0 commit comments

Comments
 (0)