Refactor Worker/Notifier part 4
- Remove redundant $normal_mode flag - Moved public message email recipient loop - Simplify OStatus delivery
This commit is contained in:
parent
774609dd38
commit
1e6193a14e
|
@ -62,13 +62,11 @@ class Notifier
|
||||||
$recipients = [];
|
$recipients = [];
|
||||||
$url_recipients = [];
|
$url_recipients = [];
|
||||||
|
|
||||||
$normal_mode = true;
|
|
||||||
$delivery_contacts_stmt = null;
|
$delivery_contacts_stmt = null;
|
||||||
$target_item = [];
|
$target_item = [];
|
||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
if ($cmd == Delivery::MAIL) {
|
if ($cmd == Delivery::MAIL) {
|
||||||
$normal_mode = false;
|
|
||||||
$message = DBA::selectFirst('mail', ['uid', 'contact-id'], ['id' => $target_id]);
|
$message = DBA::selectFirst('mail', ['uid', 'contact-id'], ['id' => $target_id]);
|
||||||
if (!DBA::isResult($message)) {
|
if (!DBA::isResult($message)) {
|
||||||
return;
|
return;
|
||||||
|
@ -76,7 +74,6 @@ class Notifier
|
||||||
$uid = $message['uid'];
|
$uid = $message['uid'];
|
||||||
$recipients[] = $message['contact-id'];
|
$recipients[] = $message['contact-id'];
|
||||||
} elseif ($cmd == Delivery::SUGGESTION) {
|
} elseif ($cmd == Delivery::SUGGESTION) {
|
||||||
$normal_mode = false;
|
|
||||||
$suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $target_id]);
|
$suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $target_id]);
|
||||||
if (!DBA::isResult($suggest)) {
|
if (!DBA::isResult($suggest)) {
|
||||||
return;
|
return;
|
||||||
|
@ -86,7 +83,6 @@ class Notifier
|
||||||
} elseif ($cmd == Delivery::REMOVAL) {
|
} elseif ($cmd == Delivery::REMOVAL) {
|
||||||
return self::notifySelfRemoval($target_id, $a->queue['priority'], $a->queue['created']);
|
return self::notifySelfRemoval($target_id, $a->queue['priority'], $a->queue['created']);
|
||||||
} elseif ($cmd == Delivery::RELOCATION) {
|
} elseif ($cmd == Delivery::RELOCATION) {
|
||||||
$normal_mode = false;
|
|
||||||
$uid = $target_id;
|
$uid = $target_id;
|
||||||
|
|
||||||
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
||||||
|
@ -304,6 +300,20 @@ class Notifier
|
||||||
$recipients = array_unique(array_merge($recipients, $allow_people, $allow_groups));
|
$recipients = array_unique(array_merge($recipients, $allow_people, $allow_groups));
|
||||||
$deny = array_unique(array_merge($deny_people, $deny_groups));
|
$deny = array_unique(array_merge($deny_people, $deny_groups));
|
||||||
$recipients = array_diff($recipients, $deny);
|
$recipients = array_diff($recipients, $deny);
|
||||||
|
|
||||||
|
// If this is a public message and pubmail is set on the parent, include all your email contacts
|
||||||
|
if (
|
||||||
|
function_exists('imap_open')
|
||||||
|
&& !Config::get('system','imap_disabled')
|
||||||
|
&& $public_message
|
||||||
|
&& intval($target_item['pubmail'])
|
||||||
|
) {
|
||||||
|
$mail_contacts_stmt = DBA::select('contact', ['id'], ['uid' => $uid, 'network' => Protocol::MAIL]);
|
||||||
|
while ($mail_contact = DBA::fetch($mail_contacts_stmt)) {
|
||||||
|
$recipients[] = $mail_contact['id'];
|
||||||
|
}
|
||||||
|
DBA::close($mail_contacts_stmt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the thread parent is OStatus then do some magic to distribute the messages.
|
// If the thread parent is OStatus then do some magic to distribute the messages.
|
||||||
|
@ -350,19 +360,6 @@ class Notifier
|
||||||
$public_message = false;
|
$public_message = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a public message and pubmail is set on the parent, include all your email contacts
|
|
||||||
if (!empty($target_item) && function_exists('imap_open') && !Config::get('system','imap_disabled')) {
|
|
||||||
if (!strlen($target_item['allow_cid']) && !strlen($target_item['allow_gid'])
|
|
||||||
&& !strlen($target_item['deny_cid']) && !strlen($target_item['deny_gid'])
|
|
||||||
&& intval($target_item['pubmail'])) {
|
|
||||||
$mail_contacts_stmt = DBA::select('contact', ['id'], ['uid' => $uid, 'network' => Protocol::MAIL]);
|
|
||||||
while ($mail_contact = DBA::fetch($mail_contacts_stmt)) {
|
|
||||||
$recipients[] = $mail_contact['id'];
|
|
||||||
}
|
|
||||||
DBA::close($mail_contacts_stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($delivery_contacts_stmt)) {
|
if (empty($delivery_contacts_stmt)) {
|
||||||
if ($followup) {
|
if ($followup) {
|
||||||
$recipients = $recipients_followup;
|
$recipients = $recipients_followup;
|
||||||
|
@ -471,16 +468,16 @@ class Notifier
|
||||||
}
|
}
|
||||||
DBA::close($delivery_contacts_stmt);
|
DBA::close($delivery_contacts_stmt);
|
||||||
|
|
||||||
|
|
||||||
|
$url_recipients = array_filter($url_recipients);
|
||||||
// send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
|
// send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
|
||||||
// They are especially used for notifications to OStatus users that don't follow us.
|
// They are especially used for notifications to OStatus users that don't follow us.
|
||||||
if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) {
|
if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && !empty($target_item)) {
|
||||||
$slap = OStatus::salmon($target_item, $owner);
|
$slap = OStatus::salmon($target_item, $owner);
|
||||||
foreach ($url_recipients as $url) {
|
foreach ($url_recipients as $url) {
|
||||||
if ($url) {
|
Logger::log('Salmon delivery of item ' . $target_id . ' to ' . $url);
|
||||||
Logger::log('Salmon delivery of item ' . $target_id . ' to ' . $url);
|
/// @TODO Redeliver/queue these items on failure, though there is no contact record
|
||||||
/// @TODO Redeliver/queue these items on failure, though there is no contact record
|
Salmon::slapper($owner, $url, $slap);
|
||||||
Salmon::slapper($owner, $url, $slap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,13 +489,13 @@ class Notifier
|
||||||
PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']);
|
PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::log('Calling hooks for ' . $cmd . ' ' . $target_id, Logger::DEBUG);
|
if (!empty($target_item)) {
|
||||||
|
Logger::log('Calling hooks for ' . $cmd . ' ' . $target_id, Logger::DEBUG);
|
||||||
|
|
||||||
if ($normal_mode) {
|
|
||||||
Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
|
Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
|
||||||
}
|
|
||||||
|
|
||||||
Hook::callAll('notifier_end',$target_item);
|
Hook::callAll('notifier_end', $target_item);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue