Refactor Worker/Notifier part 3
- Replace deprecated q() calls
This commit is contained in:
parent
d0228b9b97
commit
774609dd38
1 changed files with 64 additions and 59 deletions
|
@ -23,6 +23,8 @@ use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
use Friendica\Protocol\Salmon;
|
use Friendica\Protocol\Salmon;
|
||||||
|
|
||||||
|
require_once 'include/items.php';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The notifier is typically called with:
|
* The notifier is typically called with:
|
||||||
*
|
*
|
||||||
|
@ -61,7 +63,7 @@ class Notifier
|
||||||
$url_recipients = [];
|
$url_recipients = [];
|
||||||
|
|
||||||
$normal_mode = true;
|
$normal_mode = true;
|
||||||
$recipients_relocate = [];
|
$delivery_contacts_stmt = null;
|
||||||
$target_item = [];
|
$target_item = [];
|
||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
|
@ -87,8 +89,8 @@ class Notifier
|
||||||
$normal_mode = false;
|
$normal_mode = false;
|
||||||
$uid = $target_id;
|
$uid = $target_id;
|
||||||
|
|
||||||
$recipients_relocate = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND `network` IN ('%s', '%s')",
|
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
||||||
intval($uid), Protocol::DFRN, Protocol::DIASPORA);
|
$delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
|
||||||
} else {
|
} else {
|
||||||
// find ancestors
|
// find ancestors
|
||||||
$condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
|
$condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
|
||||||
|
@ -235,15 +237,12 @@ class Notifier
|
||||||
if ($parent["network"] == Protocol::OSTATUS) {
|
if ($parent["network"] == Protocol::OSTATUS) {
|
||||||
// Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
|
// Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
|
||||||
// Currently it is work at progress
|
// Currently it is work at progress
|
||||||
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
|
$condition = ['uid' => $uid, 'network' => Protocol::DFRN, 'blocked' => false, 'pending' => false, 'archive' => false];
|
||||||
intval($uid),
|
$followup_contacts_stmt = DBA::select('contact', ['id'], $condition);
|
||||||
DBA::escape(Protocol::DFRN)
|
while($followup_contact = DBA::fetch($followup_contacts_stmt)) {
|
||||||
);
|
$recipients_followup[] = $followup_contact['id'];
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
foreach ($r as $rr) {
|
|
||||||
$recipients_followup[] = $rr['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
DBA::close($followup_contacts_stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,21 +355,15 @@ class Notifier
|
||||||
if (!strlen($target_item['allow_cid']) && !strlen($target_item['allow_gid'])
|
if (!strlen($target_item['allow_cid']) && !strlen($target_item['allow_gid'])
|
||||||
&& !strlen($target_item['deny_cid']) && !strlen($target_item['deny_gid'])
|
&& !strlen($target_item['deny_cid']) && !strlen($target_item['deny_gid'])
|
||||||
&& intval($target_item['pubmail'])) {
|
&& intval($target_item['pubmail'])) {
|
||||||
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
|
$mail_contacts_stmt = DBA::select('contact', ['id'], ['uid' => $uid, 'network' => Protocol::MAIL]);
|
||||||
intval($uid),
|
while ($mail_contact = DBA::fetch($mail_contacts_stmt)) {
|
||||||
DBA::escape(Protocol::MAIL)
|
$recipients[] = $mail_contact['id'];
|
||||||
);
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
foreach ($r as $rr) {
|
|
||||||
$recipients[] = $rr['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
DBA::close($mail_contacts_stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cmd == Delivery::RELOCATION) {
|
if (empty($delivery_contacts_stmt)) {
|
||||||
$contacts = $recipients_relocate;
|
|
||||||
} else {
|
|
||||||
if ($followup) {
|
if ($followup) {
|
||||||
$recipients = $recipients_followup;
|
$recipients = $recipients_followup;
|
||||||
}
|
}
|
||||||
|
@ -379,35 +372,47 @@ class Notifier
|
||||||
if (!empty($networks)) {
|
if (!empty($networks)) {
|
||||||
$condition['network'] = $networks;
|
$condition['network'] = $networks;
|
||||||
}
|
}
|
||||||
$result = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
|
$delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
|
||||||
$contacts = DBA::toArray($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$conversants = [];
|
$conversants = [];
|
||||||
$batch_delivery = false;
|
$batch_delivery = false;
|
||||||
|
|
||||||
if ($public_message && !in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION]) && !$followup) {
|
if ($public_message && !in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION]) && !$followup) {
|
||||||
$r1 = [];
|
$relay_list = [];
|
||||||
|
|
||||||
if ($diaspora_delivery) {
|
if ($diaspora_delivery) {
|
||||||
$batch_delivery = true;
|
$batch_delivery = true;
|
||||||
|
|
||||||
$r1 = q("SELECT `batch`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`name`) AS `name`, ANY_VALUE(`network`) AS `network`
|
$relay_list_stmt = DBA::p(
|
||||||
FROM `contact` WHERE `network` = '%s' AND `batch` != ''
|
"SELECT
|
||||||
AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`",
|
`batch`,
|
||||||
DBA::escape(Protocol::DIASPORA),
|
ANY_VALUE(`id`) AS `id`,
|
||||||
intval($owner['uid']),
|
ANY_VALUE(`name`) AS `name`,
|
||||||
intval(Contact::SHARING)
|
ANY_VALUE(`network`) AS `network`
|
||||||
|
FROM `contact`
|
||||||
|
WHERE `network` = ?
|
||||||
|
AND `batch` != ''
|
||||||
|
AND `uid` = ?
|
||||||
|
AND `rel` != ?
|
||||||
|
AND NOT `blocked`
|
||||||
|
AND NOT `pending`
|
||||||
|
AND NOT `archive`
|
||||||
|
GROUP BY `batch`",
|
||||||
|
Protocol::DIASPORA,
|
||||||
|
$owner['uid'],
|
||||||
|
Contact::SHARING
|
||||||
);
|
);
|
||||||
|
$relay_list = DBA::toArray($relay_list_stmt);
|
||||||
|
|
||||||
// Fetch the participation list
|
// Fetch the participation list
|
||||||
// The function will ensure that there are no duplicates
|
// The function will ensure that there are no duplicates
|
||||||
$r1 = Diaspora::participantsForThread($target_id, $r1);
|
$relay_list = Diaspora::participantsForThread($target_id, $relay_list);
|
||||||
|
|
||||||
// Add the relay to the list, avoid duplicates.
|
// Add the relay to the list, avoid duplicates.
|
||||||
// Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
|
// Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
|
||||||
if (!$followup && !self::isForumPost($target_item, $owner)) {
|
if (!$followup && !self::isForumPost($target_item, $owner)) {
|
||||||
$r1 = Diaspora::relayList($target_id, $r1);
|
$relay_list = Diaspora::relayList($target_id, $relay_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +421,7 @@ class Notifier
|
||||||
|
|
||||||
$r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition));
|
$r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition));
|
||||||
|
|
||||||
$r = array_merge($r2, $r1);
|
$r = array_merge($r2, $relay_list);
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
if (DBA::isResult($r)) {
|
||||||
foreach ($r as $rr) {
|
foreach ($r as $rr) {
|
||||||
|
@ -439,8 +444,7 @@ class Notifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// delivery loop
|
// delivery loop
|
||||||
if (DBA::isResult($contacts)) {
|
while ($contact = DBA::fetch($delivery_contacts_stmt)) {
|
||||||
foreach ($contacts as $contact) {
|
|
||||||
// Don't deliver to Diaspora if it already had been done as batch delivery
|
// Don't deliver to Diaspora if it already had been done as batch delivery
|
||||||
if (($contact['network'] == Protocol::DIASPORA) && $batch_delivery) {
|
if (($contact['network'] == Protocol::DIASPORA) && $batch_delivery) {
|
||||||
Logger::log('Already delivered id ' . $target_id . ' via batch to ' . json_encode($contact), Logger::DEBUG);
|
Logger::log('Already delivered id ' . $target_id . ' via batch to ' . json_encode($contact), Logger::DEBUG);
|
||||||
|
@ -465,7 +469,7 @@ class Notifier
|
||||||
}
|
}
|
||||||
Worker::add($deliver_options, 'Delivery', $cmd, $target_id, (int)$contact['id']);
|
Worker::add($deliver_options, 'Delivery', $cmd, $target_id, (int)$contact['id']);
|
||||||
}
|
}
|
||||||
}
|
DBA::close($delivery_contacts_stmt);
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -520,6 +524,7 @@ class Notifier
|
||||||
while($contact = DBA::fetch($contacts_stmt)) {
|
while($contact = DBA::fetch($contacts_stmt)) {
|
||||||
Contact::terminateFriendship($owner, $contact, true);
|
Contact::terminateFriendship($owner, $contact, true);
|
||||||
}
|
}
|
||||||
|
DBA::close($contacts_stmt);
|
||||||
|
|
||||||
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
|
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
|
||||||
foreach ($inboxes as $inbox) {
|
foreach ($inboxes as $inbox) {
|
||||||
|
|
Loading…
Reference in a new issue