forked from friendica/friendica-addons
Mailstream: respect blocked/ignored/collapsed contact settings
This commit is contained in:
parent
ca1de575c6
commit
6b6f536c95
|
@ -129,21 +129,35 @@ function mailstream_send_hook(array $data)
|
|||
return;
|
||||
}
|
||||
|
||||
$contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
Logger::error('mailstream_send_hook could not find contact', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
|
||||
$author = DBA::selectFirst('contact', ['nick', 'blocked', 'uri-id'], ['id' => $data['author-id'], 'self' => false]);
|
||||
if (!DBA::isResult($author)) {
|
||||
Logger::error('mailstream_send_hook could not find author', ['guid' => $item['guid'], 'author-id' => $data['author-id']]);
|
||||
return;
|
||||
}
|
||||
if ($contact['blocked']) {
|
||||
Logger::error('mailstream_send_hook contact is blocked', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
|
||||
if ($author['blocked']) {
|
||||
Logger::info('mailstream_send_hook author is blocked', ['guid' => $item['guid'], 'author-id' => $data['author-id']]);
|
||||
return;
|
||||
}
|
||||
if (array_key_exists('ignored', $contact) && $contact['ignored']) {
|
||||
Logger::error('mailstream_send_hook contact is ignored', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
|
||||
return;
|
||||
$collapsed = false;
|
||||
$user_contact = DBA::selectFirst('user-contact', ['cid', 'blocked', 'ignored', 'collapsed'], ['uid' => $item['uid'], 'uri-id' => $item['author-uri-id']]);
|
||||
if (!DBA::isResult($user_contact)) {
|
||||
$user_contact = DBA::selectFirst('user-contact', ['cid', 'blocked', 'ignored', 'collapsed'], ['uid' => $item['uid'], 'cid' => $item['author-id']]);
|
||||
}
|
||||
if (DBA::isResult($user_contact)) {
|
||||
if ($user_contact['blocked']) {
|
||||
Logger::info('mailstream_send_hook author is blocked', ['guid' => $item['guid'], 'cid' => $user_contact['cid']]);
|
||||
return;
|
||||
}
|
||||
if ($user_contact['ignored']) {
|
||||
Logger::info('mailstream_send_hook author is ignored', ['guid' => $item['guid'], 'cid' => $user_contact['cid']]);
|
||||
return;
|
||||
}
|
||||
if ($user_contact['collapsed']) {
|
||||
$collapsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mailstream_send($data['message_id'], $item, $user)) {
|
||||
if (!mailstream_send($data['message_id'], $item, $user, $collapsed)) {
|
||||
Logger::debug('mailstream_send_hook send failed, will retry', $data);
|
||||
if (!Worker::defer()) {
|
||||
Logger::error('mailstream_send_hook failed and could not defer', $data);
|
||||
|
@ -199,6 +213,7 @@ function mailstream_post_hook(array &$item)
|
|||
$send_hook_data = [
|
||||
'uid' => $item['uid'],
|
||||
'contact-id' => $item['contact-id'],
|
||||
'author-id' => $item['author-id'],
|
||||
'uri' => $item['uri'],
|
||||
'message_id' => $message_id,
|
||||
'tries' => 0,
|
||||
|
@ -383,10 +398,11 @@ function mailstream_subject(array $item): string
|
|||
* @param string $message_id ID of the message (RFC 1036)
|
||||
* @param array $item content of the item
|
||||
* @param array $user results from the user table
|
||||
* @param bool $collapsed true if the content should be hidden
|
||||
*
|
||||
* @return bool True if this message has been completed. False if it should be retried.
|
||||
*/
|
||||
function mailstream_send(string $message_id, array $item, array $user): bool
|
||||
function mailstream_send(string $message_id, array $item, array $user, bool $collapsed): bool
|
||||
{
|
||||
if (!is_array($item)) {
|
||||
Logger::error('mailstream_send item is empty', ['message_id' => $message_id]);
|
||||
|
@ -405,10 +421,16 @@ function mailstream_send(string $message_id, array $item, array $user): bool
|
|||
|
||||
require_once (dirname(__file__) . '/phpmailer/class.phpmailer.php');
|
||||
|
||||
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||
if ($collapsed) {
|
||||
$item['body'] = DI::l10n()->t('Content from %s is collapsed', $item['author-name']);
|
||||
} else {
|
||||
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||
}
|
||||
|
||||
$attachments = [];
|
||||
mailstream_do_images($item, $attachments);
|
||||
if (!$collapsed) {
|
||||
mailstream_do_images($item, $attachments);
|
||||
}
|
||||
$frommail = DI::config()->get('mailstream', 'frommail');
|
||||
if ($frommail == '') {
|
||||
$frommail = 'friendica@localhost.local';
|
||||
|
|
Loading…
Reference in a new issue