Update mailstream plugin for 2021.04

This commit is contained in:
Matthew Exon 2021-04-27 16:48:37 +02:00
parent 47bc4a97f7
commit 04a0afcc97

View file

@ -228,6 +228,10 @@ function mailstream_subject($item) {
} }
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($item['contact-id']), intval($item['uid'])); intval($item['contact-id']), intval($item['uid']));
if (!DBA::isResult($r)) {
Logger::error('mailstream_subject no contact for item id ' . $item['id'] . ' plink ' . $item['plink'] . ' contact id ' . $item['contact-id'] . ' uid ' . $item['uid']);
return DI::l10n()->t("Friendica post");
}
$contact = $r[0]; $contact = $r[0];
if ($contact['network'] === 'dfrn') { if ($contact['network'] === 'dfrn') {
return DI::l10n()->t("Friendica post"); return DI::l10n()->t("Friendica post");
@ -290,7 +294,7 @@ function mailstream_send(\Friendica\App $a, $message_id, $item, $user) {
$mail->CharSet = 'utf-8'; $mail->CharSet = 'utf-8';
$template = Renderer::getMarkupTemplate('mail.tpl', 'addon/mailstream/'); $template = Renderer::getMarkupTemplate('mail.tpl', 'addon/mailstream/');
$mail->AltBody = BBCode::toPlaintext($item['body']); $mail->AltBody = BBCode::toPlaintext($item['body']);
$item['body'] = BBCode::convert($item['body']); $item['body'] = BBCode::convert($item['body'], false, BBCode::CONNECTORS);
$item['url'] = DI::baseUrl()->get() . '/display/' . $item['guid']; $item['url'] = DI::baseUrl()->get() . '/display/' . $item['guid'];
$mail->Body = Renderer::replaceMacros($template, [ $mail->Body = Renderer::replaceMacros($template, [
'$upstream' => DI::l10n()->t('Upstream'), '$upstream' => DI::l10n()->t('Upstream'),
@ -332,7 +336,30 @@ function mailstream_cron($a, $b) {
// send the email itself before cron jumps in. Only if // send the email itself before cron jumps in. Only if
// mailstream_post_remote_hook fails for some reason will this get // mailstream_post_remote_hook fails for some reason will this get
// used, and in that case it's worth holding off a bit anyway. // used, and in that case it's worth holding off a bit anyway.
$ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `post-view`.`id` FROM `mailstream_item` JOIN `post-view` ON (`mailstream_item`.`uid` = `post-view`.`uid` AND `mailstream_item`.`uri` = `post-view`.`uri` AND `mailstream_item`.`contact-id` = `post-view`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `post-view`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100"); $query = <<< EOT
SELECT
`mailstream_item`.`message-id`,
`mailstream_item`.`uri`,
`post-user-view`.`id`
FROM
`mailstream_item`
JOIN
`post-user-view`
ON (
`mailstream_item`.`uid` = `post-user-view`.`uid` AND
`mailstream_item`.`uri` = `post-user-view`.`uri` AND
`mailstream_item`.`contact-id` = `post-user-view`.`contact-id`
)
WHERE
`mailstream_item`.`completed` IS NULL AND
`mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND
`post-user-view`.`visible` = 1
ORDER BY `mailstream_item`.`created`
LIMIT 100
EOT;
$ms_item_ids = q($query);
if (DBA::isResult($ms_item_ids)) {
Logger::debug('mailstream_cron processing ' . count($ms_item_ids) . ' items'); Logger::debug('mailstream_cron processing ' . count($ms_item_ids) . ' items');
foreach ($ms_item_ids as $ms_item_id) { foreach ($ms_item_ids as $ms_item_id) {
if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) { if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) {
@ -349,6 +376,7 @@ function mailstream_cron($a, $b) {
q("UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = %d", intval($ms_item_id['message-id'])); q("UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = %d", intval($ms_item_id['message-id']));
} }
} }
}
mailstream_tidy(); mailstream_tidy();
} }