]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact/Introduction.php
Improve performance on the contact relation queries
[friendica.git] / src / Model / Contact / Introduction.php
index 692ba7befecfdef31e0f75c91121c8bbc0722677..d78673665037ea51c9226e01f9fc2080c057b263 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -37,12 +37,14 @@ class Introduction
         * Confirms a follow request and sends a notice to the remote contact.
         *
         * @param Entity\Introduction $introduction
+        * @param bool                $duplex       Is it a follow back?
+        * @param bool|null           $hidden       Should this contact be hidden? null = no change
         *
         * @throws HTTPException\InternalServerErrorException
         * @throws HTTPException\NotFoundException
         * @throws \ImagickException
         */
-       public static function confirm(Entity\Introduction $introduction): void
+       public static function confirm(Entity\Introduction $introduction, bool $duplex = false, ?bool $hidden = null): void
        {
                DI::logger()->info('Confirming follower', ['cid' => $introduction->cid]);
 
@@ -66,7 +68,7 @@ class Introduction
                }
 
                if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
-                       if ($introduction->duplex) {
+                       if ($duplex) {
                                $newRelation = Contact::FRIEND;
                        } else {
                                $newRelation = Contact::FOLLOWER;
@@ -111,23 +113,6 @@ class Introduction
         */
        public static function discard(Entity\Introduction $introduction): void
        {
-               // If it is a friend suggestion, the contact is not a new friend but an existing friend
-               // that should not be deleted.
-               if (!$introduction->fid) {
-                       // When the contact entry had been created just for that intro, we want to get rid of it now
-                       $condition = [
-                               'id'      => $introduction->cid,
-                               'uid'     => $introduction->uid,
-                               'self'    => false,
-                               'pending' => true,
-                               'rel'     => [0, Contact::FOLLOWER]];
-                       if (DI::dba()->exists('contact', $condition)) {
-                               Contact::remove($introduction->cid);
-                       } else {
-                               Contact::update(['pending' => false], ['id' => $introduction->cid]);
-                       }
-               }
-
                $contact = Contact::selectFirst([], ['id' => $introduction->cid, 'uid' => $introduction->uid]);
                if (!empty($contact)) {
                        if (!empty($contact['protocol'])) {
@@ -137,7 +122,10 @@ class Introduction
                        }
 
                        if ($protocol == Protocol::ACTIVITYPUB) {
-                               ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $contact['uid']);
+                               $owner = User::getOwnerDataById($contact['uid']);
+                               if ($owner) {
+                                       ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $owner);
+                               }
                        }
                }
        }