]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/OStatus.php
The "thread" table isn't used anymore
[friendica.git] / src / Protocol / OStatus.php
index a6e0df4c33e355644cc6e99344f77a39a13fa43e..a8f4e2429843750c9d0bd57f07caf8c5dd927ea6 100644 (file)
@@ -46,9 +46,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'mod/share.php';
-require_once 'include/api.php';
-
 /**
  * This class contain functions for the OStatus protocol
  */
@@ -315,7 +312,7 @@ class OStatus
         */
        public static function import($xml, array $importer, array &$contact, &$hub)
        {
-               self::process($xml, $importer, $contact, $hub);
+               self::process($xml, $importer, $contact, $hub, false, true, Conversation::PUSH);
        }
 
        /**
@@ -332,7 +329,7 @@ class OStatus
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function process($xml, array $importer, array &$contact = null, &$hub, $stored = false, $initialize = true)
+       private static function process($xml, array $importer, array &$contact = null, &$hub, $stored = false, $initialize = true, $direction = Conversation::UNKNOWN)
        {
                if ($initialize) {
                        self::$itemlist = [];
@@ -400,6 +397,7 @@ class OStatus
 
                        $header["protocol"] = Conversation::PARCEL_SALMON;
                        $header["source"] = $xml2;
+                       $header["direction"] = $direction;
                } elseif (!$initialize) {
                        return false;
                }
@@ -447,7 +445,7 @@ class OStatus
                        }
 
                        // Deletions come with the same uri, so we check for duplicates after processing deletions
-                       if (Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]])) {
+                       if (Post::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]])) {
                                Logger::log('Post with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', Logger::DEBUG);
                                continue;
                        } else {
@@ -535,7 +533,7 @@ class OStatus
                                                }
                                        }
                                        foreach (self::$itemlist as $item) {
-                                               $found = Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]]);
+                                               $found = Post::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]]);
                                                if ($found) {
                                                        Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", Logger::DEBUG);
                                                } elseif ($item['contact-id'] < 0) {
@@ -563,7 +561,7 @@ class OStatus
        private static function deleteNotice(array $item)
        {
                $condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'uri' => $item['uri']];
-               if (!Item::exists($condition)) {
+               if (!Post::exists($condition)) {
                        Logger::log('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it.");
                        return;
                }
@@ -699,7 +697,7 @@ class OStatus
                }
 
                if (isset($item["thr-parent"])) {
-                       if (!Item::exists(['uid' => $importer["uid"], 'uri' => $item['thr-parent']])) {
+                       if (!Post::exists(['uid' => $importer["uid"], 'uri' => $item['thr-parent']])) {
                                if ($related != '') {
                                        self::fetchRelated($related, $item["thr-parent"], $importer);
                                }
@@ -810,6 +808,7 @@ class OStatus
                        $conv_data = [];
 
                        $conv_data['protocol'] = Conversation::PARCEL_SPLIT_CONVERSATION;
+                       $conv_data['direction'] = Conversation::PULL;
                        $conv_data['network'] = Protocol::OSTATUS;
                        $conv_data['uri'] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
 
@@ -850,12 +849,6 @@ class OStatus
 
                        $conv_data['source'] = $doc2->saveXML();
 
-                       $condition = ['item-uri' => $conv_data['uri'],'protocol' => Conversation::PARCEL_FEED];
-                       if (DBA::exists('conversation', $condition)) {
-                               Logger::log('Delete deprecated entry for URI '.$conv_data['uri'], Logger::DEBUG);
-                               DBA::delete('conversation', ['item-uri' => $conv_data['uri']]);
-                       }
-
                        Logger::log('Store conversation data for uri '.$conv_data['uri'], Logger::DEBUG);
                        Conversation::insert($conv_data);
                }
@@ -898,6 +891,7 @@ class OStatus
 
                $item["protocol"] = Conversation::PARCEL_SALMON;
                $item["source"] = $xml;
+               $item["direction"] = Conversation::PULL;
 
                Logger::log('Conversation '.$item['uri'].' is now fetched.', Logger::DEBUG);
        }
@@ -921,7 +915,7 @@ class OStatus
                if (DBA::isResult($conversation)) {
                        $stored = true;
                        $xml = $conversation['source'];
-                       if (self::process($xml, $importer, $contact, $hub, $stored, false)) {
+                       if (self::process($xml, $importer, $contact, $hub, $stored, false, Conversation::PULL)) {
                                Logger::log('Got valid cached XML for URI '.$related_uri, Logger::DEBUG);
                                return;
                        }
@@ -1006,7 +1000,7 @@ class OStatus
                }
 
                if ($xml != '') {
-                       self::process($xml, $importer, $contact, $hub, $stored, false);
+                       self::process($xml, $importer, $contact, $hub, $stored, false, Conversation::PULL);
                } else {
                        Logger::log("XML couldn't be fetched for URI: ".$related_uri." - href: ".$related, Logger::DEBUG);
                }
@@ -1599,7 +1593,7 @@ class OStatus
 
                $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]];
-               $repeated_item = Item::selectFirst([], $condition);
+               $repeated_item = Post::selectFirst([], $condition);
                if (!DBA::isResult($repeated_item)) {
                        return false;
                }
@@ -1665,7 +1659,7 @@ class OStatus
                $verb = ActivityNamespace::ACTIVITY_SCHEMA . "favorite";
                self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
 
-               $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
+               $parent = Post::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
                if (DBA::isResult($parent)) {
                        $as_object = $doc->createElement("activity:object");
 
@@ -1933,9 +1927,9 @@ class OStatus
                $mentioned = [];
 
                if ($item['gravity'] != GRAVITY_PARENT) {
-                       $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
+                       $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
 
-                       $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
+                       $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
 
                        if (DBA::isResult($thrparent)) {
                                $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
@@ -2130,12 +2124,12 @@ class OStatus
                $params = ['order' => ['received' => true], 'limit' => $max_items];
 
                if ($filter === 'posts') {
-                       $ret = Item::selectThread([], $condition, $params);
+                       $ret = Post::selectThread([], $condition, $params);
                } else {
-                       $ret = Item::select([], $condition, $params);
+                       $ret = Post::select([], $condition, $params);
                }
 
-               $items = Item::inArray($ret);
+               $items = Post::toArray($ret);
 
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;