]> git.mxchange.org Git - friendica.git/commitdiff
Revert "Reworked contact-id generation"
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 2 Aug 2019 00:39:42 +0000 (20:39 -0400)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2019 00:39:42 +0000 (20:39 -0400)
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php

index 2db3d1d890c1ca854172c1f9c5b43ae34def73fb..8cca6f693ff12c5c59ef35a98a4c8854540e62fa 100644 (file)
@@ -1234,18 +1234,35 @@ class Item extends BaseObject
 
        private static function contactId($item)
        {
-               if (!empty($item['uid']) && !Contact::isSharing($item['author-id'], $item['uid'])) {
-                       return $item['author-id'];
-               } elseif (!empty($item['contact-id'])) {
-                       return $item['contact-id'];
-               } else {
+               $contact_id = (int)$item["contact-id"];
+
+               if (!empty($contact_id)) {
+                       return $contact_id;
+               }
+               Logger::log('Missing contact-id. Called by: '.System::callstack(), Logger::DEBUG);
+               /*
+                * First we are looking for a suitable contact that matches with the author of the post
+                * This is done only for comments
+                */
+               if ($item['parent-uri'] != $item['uri']) {
                        $contact_id = Contact::getIdForURL($item['author-link'], $item['uid']);
-                       if (!empty($contact_id)) {
-                               return $contact_id;
+               }
+
+               // If not present then maybe the owner was found
+               if ($contact_id == 0) {
+                       $contact_id = Contact::getIdForURL($item['owner-link'], $item['uid']);
+               }
+
+               // Still missing? Then use the "self" contact of the current user
+               if ($contact_id == 0) {
+                       $self = DBA::selectFirst('contact', ['id'], ['self' => true, 'uid' => $item['uid']]);
+                       if (DBA::isResult($self)) {
+                               $contact_id = $self["id"];
                        }
                }
+               Logger::log("Contact-id was missing for post ".$item['guid']." from user id ".$item['uid']." - now set to ".$contact_id, Logger::DEBUG);
 
-               return $item['author-id'];
+               return $contact_id;
        }
 
        // This function will finally cover most of the preparation functionality in mod/item.php
@@ -1470,6 +1487,9 @@ class Item extends BaseObject
 
                $item['plink'] = defaults($item, 'plink', System::baseUrl() . '/display/' . urlencode($item['guid']));
 
+               // The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes
+               $item["contact-id"] = self::contactId($item);
+
                $default = ['url' => $item['author-link'], 'name' => $item['author-name'],
                        'photo' => $item['author-avatar'], 'network' => $item['network']];
 
@@ -1525,9 +1545,6 @@ class Item extends BaseObject
                unset($item['causer-id']);
                unset($item['causer-link']);
 
-               // The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes
-               $item['contact-id'] = self::contactId($item);
-
                if ($item['network'] == Protocol::PHANTOM) {
                        $item['network'] = Protocol::DFRN;
                        Logger::notice('Missing network, setting to {network}.', [
index 65dd6d3e627e98d32978651a650c3f4c98d02681..7639d0f2a325d97ee6dc3ea6a9f2fb48a4f0d6b4 100644 (file)
@@ -419,8 +419,8 @@ class Processor
                                $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true);
                        }
 
-                       if (empty($item['contact-id'])) {
-                               $item['contact-id'] = $item['author-id'];
+                       if (($receiver != 0) && empty($item['contact-id'])) {
+                               $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true);
                        }
 
                        if (!empty($activity['directmessage'])) {