]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
Merge pull request #5294 from annando/use-gravity
[friendica.git] / src / Worker / Notifier.php
index e22e8a1cd1b9521609f118bb79e93521ad31718d..fcf36bd55ab41a589a6b49fdddfb0b30e88c92e3 100644 (file)
@@ -10,7 +10,9 @@ 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;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
@@ -103,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) {
@@ -163,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!!!!
 
@@ -212,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'])) {
 
@@ -246,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) {
@@ -332,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"];
                                }
@@ -498,16 +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], $condition);
-
                        logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG);
 
                        // Handling the pubsubhubbub requests
-                       Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true],
-                                       'PubSubPublish');
+                       PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']);
                }
 
                logger('notifier: calling hooks for ' . $cmd . ' ' . $item_id, LOGGER_DEBUG);