]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #9655 from MrPetovan/bug/fatal-errors
[friendica.git] / src / Protocol / DFRN.php
index 7189588a8ece74964cda832898e9193c68c6958c..71ae052eb649dc0289c534296e2410ff2dc1b88a 100644 (file)
@@ -37,6 +37,7 @@ use Friendica\Model\FContact;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
 use Friendica\Model\Mail;
+use Friendica\Model\Notify;
 use Friendica\Model\Notify\Type;
 use Friendica\Model\PermissionSet;
 use Friendica\Model\Post;
@@ -1767,7 +1768,7 @@ class DFRN
                $msg["from-photo"] = XML::getFirstValue($xpath, "dfrn:sender/dfrn:avatar/text()", $mail);
                $msg["contact-id"] = $importer["id"];
                $msg["uri"] = XML::getFirstValue($xpath, "dfrn:id/text()", $mail);
-               $msg["thr-parent"] = XML::getFirstValue($xpath, "dfrn:in-reply-to/text()", $mail);
+               $msg["parent-uri"] = XML::getFirstValue($xpath, "dfrn:in-reply-to/text()", $mail);
                $msg["created"] = DateTimeFormat::utc(XML::getFirstValue($xpath, "dfrn:sentdate/text()", $mail));
                $msg["title"] = XML::getFirstValue($xpath, "dfrn:subject/text()", $mail);
                $msg["body"] = XML::getFirstValue($xpath, "dfrn:content/text()", $mail);
@@ -2005,7 +2006,7 @@ class DFRN
                        }
 
                        if ($Blink && Strings::compareLink($Blink, DI::baseUrl() . "/profile/" . $importer["nickname"])) {
-                               $author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]);
+                               $author = DBA::selectFirst('contact', ['id', 'name', 'thumb', 'url'], ['id' => $item['author-id']]);
 
                                $parent = Item::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer["importer_uid"]]);
                                $item['parent'] = $parent['id'];
@@ -2013,21 +2014,15 @@ class DFRN
                                // send a notification
                                notification(
                                        [
-                                       "type"         => Type::POKE,
-                                       "notify_flags" => $importer["notify-flags"],
-                                       "language"     => $importer["language"],
-                                       "to_name"      => $importer["username"],
-                                       "to_email"     => $importer["email"],
-                                       "uid"          => $importer["importer_uid"],
-                                       "item"         => $item,
-                                       "link"         => DI::baseUrl()."/display/".urlencode($item['guid']),
-                                       "source_name"  => $author["name"],
-                                       "source_link"  => $author["url"],
-                                       "source_photo" => $author["thumb"],
-                                       "verb"         => $item["verb"],
-                                       "otype"        => "person",
-                                       "activity"     => $verb,
-                                       "parent"       => $item['parent']]
+                                       "type"     => Type::POKE,
+                                       "otype"    => Notify\ObjectType::PERSON,
+                                       "activity" => $verb,
+                                       "verb"     => $item["verb"],
+                                       "uid"      => $importer["importer_uid"],
+                                       "cid"      => $author["id"],
+                                       "item"     => $item,
+                                       "link"     => DI::baseUrl() . "/display/" . urlencode($item['guid']),
+                                       ]
                                );
                        }
                }
@@ -2204,13 +2199,13 @@ class DFRN
         * @throws \ImagickException
         * @todo  Add type-hints
         */
-       private static function processEntry($header, $xpath, $entry, $importer, $xml)
+       private static function processEntry($header, $xpath, $entry, $importer, $xml, $protocol)
        {
                Logger::log("Processing entries");
 
                $item = $header;
 
-               $item["protocol"] = Conversation::PARCEL_DFRN;
+               $item["protocol"] = $protocol;
 
                $item["source"] = $xml;
 
@@ -2606,7 +2601,7 @@ class DFRN
         * @throws \ImagickException
         * @todo  set proper type-hints
         */
-       public static function import($xml, $importer, $sort_by_date = false)
+       public static function import($xml, $importer, $sort_by_date = false, $protocol = Conversation::PARCEL_DFRN)
        {
                if ($xml == "") {
                        return 400;
@@ -2710,14 +2705,20 @@ class DFRN
                }
 
                $deletions = $xpath->query("/atom:feed/at:deleted-entry");
-               foreach ($deletions as $deletion) {
-                       self::processDeletion($xpath, $deletion, $importer);
+               if (!empty($deletions)) {
+                       foreach ($deletions as $deletion) {
+                               self::processDeletion($xpath, $deletion, $importer);
+                       }
+                       if (count($deletions) > 0) {
+                               Logger::notice('Deletions had been processed');
+                               return 200;
+                       }
                }
 
                if (!$sort_by_date) {
                        $entries = $xpath->query("/atom:feed/atom:entry");
                        foreach ($entries as $entry) {
-                               self::processEntry($header, $xpath, $entry, $importer, $xml);
+                               self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
                        }
                } else {
                        $newentries = [];
@@ -2731,7 +2732,7 @@ class DFRN
                        ksort($newentries);
 
                        foreach ($newentries as $entry) {
-                               self::processEntry($header, $xpath, $entry, $importer, $xml);
+                               self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
                        }
                }
                Logger::log("Import done for user " . $importer["importer_uid"] . " from contact " . $importer["id"], Logger::DEBUG);