]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #11959 from annando/notice
[friendica.git] / src / Protocol / DFRN.php
index db3360dd1696f892041b1c53d3b4f096e1033e77..434af898081ea999cf51b0500c43721d6c072c43 100644 (file)
@@ -747,7 +747,7 @@ class DFRN
                $mentioned = [];
 
                if (!$item['parent']) {
-                       Logger::notice('Item without parent found.', ['type' => $type, 'item' => $item]);
+                       Logger::warning('Item without parent found.', ['type' => $type, 'item' => $item]);
                        return null;
                }
 
@@ -998,7 +998,7 @@ class DFRN
                        $path_parts = explode('/', $parts['path']);
                        array_pop($path_parts);
                        $parts['path'] =  implode('/', $path_parts);
-                       $contact['batch'] = Uri::fromParts($parts);
+                       $contact['batch'] = (string)Uri::fromParts($parts);
                }
 
                $dest_url = ($public_batch ? $contact['batch'] : $contact['notify']);
@@ -1466,9 +1466,8 @@ class DFRN
 
                // update contact
                $old = Contact::selectFirst(['photo', 'url'], ['id' => $importer['id'], 'uid' => $importer['importer_uid']]);
-
                if (!DBA::isResult($old)) {
-                       Logger::notice("Query failed to execute, no result returned in " . __FUNCTION__);
+                       Logger::warning('Existing contact had not been fetched', ['id' => $importer['id']]);
                        return false;
                }
 
@@ -1550,24 +1549,9 @@ class DFRN
        private static function getEntryType(array $importer, array $item): int
        {
                if ($item['thr-parent'] != $item['uri']) {
-                       $community = false;
-
-                       if ($importer['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
-                               $sql_extra = '';
-                               $community = true;
-                               Logger::notice("possible community action");
-                       } else {
-                               $sql_extra = " AND `self` AND `wall`";
-                       }
-
                        // was the top-level post for this action written by somebody on this site?
                        // Specifically, the recipient?
-                       $parent = Post::selectFirst(['wall'],
-                               ["`uri` = ? AND `uid` = ?" . $sql_extra, $item['thr-parent'], $importer['importer_uid']]);
-
-                       $is_a_remote_action = DBA::isResult($parent);
-
-                       if ($is_a_remote_action) {
+                       if (Post::exists(['uri' => $item['thr-parent'], 'uid' => $importer['importer_uid'], 'self' => true, 'wall' => true])) {
                                return DFRN::REPLY_RC;
                        } else {
                                return DFRN::REPLY;
@@ -1577,61 +1561,6 @@ class DFRN
                }
        }
 
-       /**
-        * Send a "poke"
-        *
-        * @param array $item      The new item record
-        * @param array $importer  Record of the importer user mixed with contact of the content
-        * @return void
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        * @todo  set proper type-hints (array?)
-        */
-       private static function doPoke(array $item, array $importer)
-       {
-               $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#')+1));
-               if (!$verb) {
-                       return;
-               }
-               $xo = XML::parseString($item['object']);
-
-               if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
-                       // somebody was poked/prodded. Was it me?
-                       $Blink = '';
-                       foreach ($xo->link as $l) {
-                               $atts = $l->attributes();
-                               switch ($atts['rel']) {
-                                       case 'alternate':
-                                               $Blink = $atts['href'];
-                                               break;
-
-                                       default:
-                                               break;
-                               }
-                       }
-
-                       if ($Blink && Strings::compareLink($Blink, DI::baseUrl() . '/profile/' . $importer['nickname'])) {
-                               $author = DBA::selectFirst('contact', ['id', 'name', 'thumb', 'url'], ['id' => $item['author-id']]);
-
-                               $parent = Post::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer['importer_uid']]);
-                               $item['parent'] = $parent['id'];
-
-                               // send a notification
-                               DI::notify()->createFromArray(
-                                       [
-                                       'type'     => Notification\Type::POKE,
-                                       'otype'    => Notification\ObjectType::PERSON,
-                                       'activity' => $verb,
-                                       'verb'     => $item['verb'],
-                                       'uid'      => $importer['importer_uid'],
-                                       'cid'      => $author['id'],
-                                       'item'     => $item,
-                                       'link'     => DI::baseUrl() . '/display/' . urlencode($item['guid']),
-                                       ]
-                               );
-                       }
-               }
-       }
-
        /**
         * Processes several actions, depending on the verb
         *
@@ -1720,9 +1649,8 @@ class DFRN
 
                                if ($xt->type == Activity\ObjectType::NOTE) {
                                        $item_tag = Post::selectFirst(['id', 'uri-id'], ['uri' => $xt->id, 'uid' => $importer['importer_uid']]);
-
                                        if (!DBA::isResult($item_tag)) {
-                                               Logger::notice("Query failed to execute, no result returned in " . __FUNCTION__);
+                                               Logger::warning('Post had not been fetched', ['uri' => $xt->id, 'uid' => $importer['importer_uid']]);
                                                return false;
                                        }
 
@@ -1830,8 +1758,6 @@ class DFRN
 
                $item = $header;
 
-               $item['protocol'] = $protocol;
-
                $item['source'] = $xml;
 
                // Get the uri
@@ -2157,11 +2083,6 @@ class DFRN
                        if ($item['uid'] == 0) {
                                Item::distribute($posted_id);
                        }
-
-                       if (stristr($item['verb'], Activity::POKE)) {
-                               $item['id'] = $posted_id;
-                               self::doPoke($item, $importer);
-                       }
                }
        }
 
@@ -2260,10 +2181,12 @@ class DFRN
                $header = [];
                $header['uid'] = $importer['importer_uid'];
                $header['network'] = Protocol::DFRN;
+               $header['protocol'] = $protocol;
                $header['wall'] = 0;
                $header['origin'] = 0;
                $header['contact-id'] = $importer['id'];
-               $header['direction'] = $direction;
+
+               $header = Diaspora::setDirection($header, $direction);
 
                if ($direction === Conversation::RELAY) {
                        $header['post-reason'] = Item::PR_RELAY;