X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FWorker%2FNotifier.php;h=fcf36bd55ab41a589a6b49fdddfb0b30e88c92e3;hb=1e9bff88bc05fce154edee9f047e7d8922184140;hp=f7b7aeae14c44d5b1681bbebbcd12c1f3ab92b07;hpb=61824119e41c514951106dd525714e264d1435de;p=friendica.git diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index f7b7aeae14..fcf36bd55a 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -10,6 +10,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Group; +use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Model\PushSubscriber; use Friendica\Network\Probe; @@ -104,27 +105,27 @@ class Notifier { intval($uid), NETWORK_DFRN, NETWORK_DIASPORA); } else { // find ancestors - $target_item = dba::fetch_first("SELECT `item`.*, `contact`.`uid` AS `cuid` FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`id` = ? AND `visible` AND NOT `moderated`", $item_id); + $condition = ['id' => $item_id, 'visible' => true, 'moderated' => false]; + $target_item = Item::selectFirst([], $condition); if (!DBM::is_result($target_item) || !intval($target_item['parent'])) { return; } $parent_id = intval($target_item['parent']); - $uid = $target_item['cuid']; + $uid = $target_item['contact-uid']; $updated = $target_item['edited']; - $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` - FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible AND NOT moderated ORDER BY `id` ASC", - intval($parent_id) - ); + $condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false]; + $params = ['order' => ['id']]; + $ret = Item::select([], $condition, $params); - if (!count($items)) { + if (!DBM::is_result($ret)) { return; } + $items = Item::inArray($ret); + // avoid race condition with deleting entries if ($items[0]['deleted']) { foreach ($items as $item) { @@ -164,10 +165,11 @@ class Notifier { if (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::RELOCATION])) { $parent = $items[0]; - $thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", - dbesc($target_item["thr-parent"]), intval($target_item["uid"])); + $fields = ['network', 'author-id', 'owner-id']; + $condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]]; + $thr_parent = dba::selectFirst('item', $fields, $condition); - logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG); + logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent['network'], LOGGER_DEBUG); // This is IMPORTANT!!!! @@ -213,7 +215,7 @@ class Notifier { } // Special treatment for forum posts - if (($target_item['author-link'] != $target_item['owner-link']) && + if (($target_item['author-id'] != $target_item['owner-id']) && ($owner['id'] != $target_item['contact-id']) && ($target_item['uri'] === $target_item['parent-uri'])) { @@ -247,7 +249,7 @@ class Notifier { $target_item['deny_cid'].$target_item['deny_gid']) == 0)) $push_notify = true; - if (($thr_parent && ($thr_parent[0]['network'] == NETWORK_OSTATUS)) || ($parent['network'] == NETWORK_OSTATUS)) { + if (($thr_parent && ($thr_parent['network'] == NETWORK_OSTATUS)) || ($parent['network'] == NETWORK_OSTATUS)) { $push_notify = true; if ($parent["network"] == NETWORK_OSTATUS) { @@ -333,37 +335,21 @@ class Notifier { // If the thread parent is OStatus then do some magic to distribute the messages. // We have not only to look at the parent, since it could be a Friendica thread. - if (($thr_parent && ($thr_parent[0]['network'] == NETWORK_OSTATUS)) || ($parent['network'] == NETWORK_OSTATUS)) { + if (($thr_parent && ($thr_parent['network'] == NETWORK_OSTATUS)) || ($parent['network'] == NETWORK_OSTATUS)) { $diaspora_delivery = false; - logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent[0]['author-link']." - Owner: ".$thr_parent[0]['owner-link'], LOGGER_DEBUG); + logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent['author-id']." - Owner: ".$thr_parent['owner-id'], LOGGER_DEBUG); // Send a salmon to the parent author - $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", - dbesc(normalise_link($thr_parent[0]['author-link'])), - intval($uid)); - if (DBM::is_result($r)) { - $probed_contact = $r[0]; - } else { - $probed_contact = Probe::uri($thr_parent[0]['author-link']); - } - - if ($probed_contact["notify"] != "") { + $probed_contact = dba::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]); + if (DBM::is_result($probed_contact) && !empty($probed_contact["notify"])) { logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]); $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; } // Send a salmon to the parent owner - $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", - dbesc(normalise_link($thr_parent[0]['owner-link'])), - intval($uid)); - if (DBM::is_result($r)) { - $probed_contact = $r[0]; - } else { - $probed_contact = Probe::uri($thr_parent[0]['owner-link']); - } - - if ($probed_contact["notify"] != "") { + $probed_contact = dba::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]); + if (DBM::is_result($probed_contact) && !empty($probed_contact["notify"])) { logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]); $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; } @@ -499,15 +485,10 @@ class Notifier { // Notify PuSH subscribers (Used for OStatus distribution of regular posts) if ($push_notify) { - // Set push flag for PuSH subscribers to this topic, - // they will be notified in queue.php - $condition = ['push' => false, 'nickname' => $owner['nickname']]; - dba::update('push_subscriber', ['push' => true, 'next_try' => NULL_DATE], $condition); - logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG); // Handling the pubsubhubbub requests - PushSubscriber::publishFeed($a->queue['priority']); + PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']); } logger('notifier: calling hooks for ' . $cmd . ' ' . $item_id, LOGGER_DEBUG);