]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Update FAQ.md
[friendica.git] / src / Protocol / Diaspora.php
index 5f28e092d5798ab751c701a1c412eeca50ae5cfa..269d62386887bd1580043de2d6e519f894d6c068 100644 (file)
@@ -537,7 +537,7 @@ class Diaspora
                                return self::receiveConversation($importer, $msg, $fields);
 
                        case "like":
-                               return self::receiveLike($importer, $sender, $fields);
+                               return self::receiveLike($importer, $sender, $fields, $fetched);
 
                        case "message":
                                if (!$private) {
@@ -551,7 +551,7 @@ class Diaspora
                                        Logger::log('Message with type ' . $type . ' is not private, quitting.');
                                        return false;
                                }
-                               return self::receiveParticipation($importer, $fields);
+                               return self::receiveParticipation($importer, $fields, $fetched);
 
                        case "photo": // Not implemented
                                return self::receivePhoto($importer, $fields);
@@ -567,7 +567,7 @@ class Diaspora
                                return self::receiveProfile($importer, $fields);
 
                        case "reshare":
-                               return self::receiveReshare($importer, $fields, $msg["message"]);
+                               return self::receiveReshare($importer, $fields, $msg["message"], $fetched);
 
                        case "retraction":
                                return self::receiveRetraction($importer, $sender, $fields);
@@ -1265,7 +1265,7 @@ class Diaspora
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function plink($addr, $guid, $parent_guid = '')
+       private static function plink(string $addr, string $guid, string $parent_guid = '')
        {
                $contact = Contact::getByURL($addr);
                if (empty($contact)) {
@@ -1570,6 +1570,7 @@ class Diaspora
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
                $datarray["source"] = $xml;
+               $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
 
                $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
 
@@ -1589,6 +1590,11 @@ class Diaspora
                        $datarray['diaspora_signed_text'] = json_encode($data);
                }
 
+               if (Item::isTooOld($datarray)) {
+                       Logger::info('Comment is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+                       return false;
+               }
+
                $message_id = Item::insert($datarray);
 
                if ($message_id <= 0) {
@@ -1735,7 +1741,7 @@ class Diaspora
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function receiveLike(array $importer, $sender, $data)
+       private static function receiveLike(array $importer, $sender, $data, bool $fetched)
        {
                $author = Strings::escapeTags(XML::unescape($data->author));
                $guid = Strings::escapeTags(XML::unescape($data->guid));
@@ -1784,6 +1790,7 @@ class Diaspora
                $datarray = [];
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
+               $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
 
                $datarray["uid"] = $importer["uid"];
                $datarray["contact-id"] = $author_contact["cid"];
@@ -1820,6 +1827,11 @@ class Diaspora
                        $datarray['diaspora_signed_text'] = json_encode($data);
                }
 
+               if (Item::isTooOld($datarray)) {
+                       Logger::info('Like is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+                       return false;
+               }
+
                $message_id = Item::insert($datarray);
 
                if ($message_id <= 0) {
@@ -1907,7 +1919,7 @@ class Diaspora
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function receiveParticipation(array $importer, $data)
+       private static function receiveParticipation(array $importer, $data, bool $fetched)
        {
                $author = strtolower(Strings::escapeTags(XML::unescape($data->author)));
                $guid = Strings::escapeTags(XML::unescape($data->guid));
@@ -1948,6 +1960,7 @@ class Diaspora
                $datarray = [];
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
+               $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
 
                $datarray["uid"] = $importer["uid"];
                $datarray["contact-id"] = $author_contact["cid"];
@@ -1970,6 +1983,11 @@ class Diaspora
                // Diaspora doesn't provide a date for a participation
                $datarray["changed"] = $datarray["created"] = $datarray["edited"] = DateTimeFormat::utcNow();
 
+               if (Item::isTooOld($datarray)) {
+                       Logger::info('Participation is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+                       return false;
+               }
+
                $message_id = Item::insert($datarray);
 
                Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
@@ -2360,11 +2378,18 @@ class Diaspora
                $datarray['object-type'] = Activity\ObjectType::NOTE;
 
                $datarray['protocol'] = $item['protocol'];
+               $datarray['source'] = $item['source'];
+               $datarray['direction'] = $item['direction'];
 
                $datarray['plink'] = self::plink($author, $datarray['guid']);
                $datarray['private'] = $item['private'];
                $datarray['changed'] = $datarray['created'] = $datarray['edited'] = $item['created'];
 
+               if (Item::isTooOld($datarray)) {
+                       Logger::info('Reshare activity is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+                       return false;
+               }
+
                $message_id = Item::insert($datarray);
 
                if ($message_id) {
@@ -2386,7 +2411,7 @@ class Diaspora
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function receiveReshare(array $importer, $data, $xml)
+       private static function receiveReshare(array $importer, $data, $xml, bool $fetched)
        {
                $author = Strings::escapeTags(XML::unescape($data->author));
                $guid = Strings::escapeTags(XML::unescape($data->guid));
@@ -2411,6 +2436,10 @@ class Diaspora
                        return false;
                }
 
+               if (empty($original_item['plink'])) {
+                       $original_item['plink'] = self::plink($root_author, $root_guid);
+               }
+
                $datarray = [];
 
                $datarray["uid"] = $importer["uid"];
@@ -2432,6 +2461,7 @@ class Diaspora
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
                $datarray["source"] = $xml;
+               $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
 
                /// @todo Copy tag data from original post
 
@@ -2462,6 +2492,12 @@ class Diaspora
                $datarray["object-type"] = $original_item["object-type"];
 
                self::fetchGuid($datarray);
+
+               if (Item::isTooOld($datarray)) {
+                       Logger::info('Reshare is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+                       return false;
+               }
+
                $message_id = Item::insert($datarray);
 
                self::sendParticipation($contact, $datarray);
@@ -2723,6 +2759,7 @@ class Diaspora
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
                $datarray["source"] = $xml;
+               $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
 
                if ($fetched) {
                        $datarray["post-type"] = Item::PT_FETCHED;
@@ -2758,6 +2795,12 @@ class Diaspora
                }
 
                self::fetchGuid($datarray);
+
+               if (Item::isTooOld($datarray)) {
+                       Logger::info('Status is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+                       return false;
+               }
+
                $message_id = Item::insert($datarray);
 
                self::sendParticipation($contact, $datarray);