]> git.mxchange.org Git - friendica.git/commitdiff
Add return value to Model\Contact::addRelationship to remove protocol-specific code...
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 19 May 2019 22:46:29 +0000 (18:46 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 20 May 2019 19:29:20 +0000 (15:29 -0400)
src/Model/Contact.php
src/Protocol/ActivityPub/Processor.php

index e75ac0394a69e1e84e4e3b63ea5d2d9238470c24..18b60d2121090b09e7fd09229eef637b4660e70b 100644 (file)
@@ -2126,6 +2126,7 @@ class Contact extends BaseObject
         * @param array  $datarray An item-like array with at least the 'author-id' and 'author-url' keys for the contact. Mandatory.
         * @param bool   $sharing  True: Contact is now sharing with Owner; False: Contact is now following Owner (default)
         * @param string $note     Introduction additional message
+        * @return bool|null True: follow request is accepted; False: relationship is rejected; Null: relationship is pending
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
@@ -2133,14 +2134,14 @@ class Contact extends BaseObject
        {
                // Should always be set
                if (empty($datarray['author-id'])) {
-                       return;
+                       return false;
                }
 
                $fields = ['url', 'name', 'nick', 'photo', 'network'];
                $pub_contact = DBA::selectFirst('contact', $fields, ['id' => $datarray['author-id']]);
                if (!DBA::isResult($pub_contact)) {
                        // Should never happen
-                       return;
+                       return false;
                }
 
                $url = defaults($datarray, 'author-link', $pub_contact['url']);
@@ -2153,26 +2154,20 @@ class Contact extends BaseObject
                        // Make sure that the existing contact isn't archived
                        self::unmarkForArchival($contact);
 
-                       $protocol = self::getProtocol($url, $contact['network']);
-
                        if (($contact['rel'] == self::SHARING)
                                || ($sharing && $contact['rel'] == self::FOLLOWER)) {
                                DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
                                                ['id' => $contact['id'], 'uid' => $importer['uid']]);
                        }
 
-                       if ($protocol == Protocol::ACTIVITYPUB) {
-                               ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']);
-                       }
-
+                       return true;
                } else {
-                       $protocol = self::getProtocol($url, $network);
-
                        // send email notification to owner?
                        if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($url), 'uid' => $importer['uid'], 'pending' => true])) {
                                Logger::log('ignoring duplicated connection request from pending contact ' . $url);
-                               return;
+                               return null;
                        }
+
                        // create contact record
                        DBA::insert('contact', [
                                'uid'      => $importer['uid'],
@@ -2237,14 +2232,11 @@ class Contact extends BaseObject
                                $condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];
                                DBA::update('contact', ['pending' => false], $condition);
 
-                               $contact = DBA::selectFirst('contact', ['url', 'network', 'hub-verify'], ['id' => $contact_record['id']]);
-                               $protocol = self::getProtocol($contact['url'], $contact['network']);
-
-                               if ($protocol == Protocol::ACTIVITYPUB) {
-                                       ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']);
-                               }
+                               return true;
                        }
                }
+
+               return null;
        }
 
        public static function removeFollower($importer, $contact, array $datarray = [], $item = "")
index c63300e84b4c30acd95ef2d700229b1dadec960e..8280ccfb78513d67372e2c53a024016b50a6eb42 100644 (file)
@@ -542,6 +542,13 @@ class Processor
                self::switchContact($item['author-id']);
 
                $result = Contact::addRelationship($owner, $contact, $item, false, $note);
+               if ($result === false) {
+                       ActivityPub\Transmitter::sendContactReject($item['author-link'], $item['author-id'], $owner['uid']);
+                       return;
+               }elseif ($result === true) {
+                       ActivityPub\Transmitter::sendContactAccept($item['author-link'], $item['author-id'], $owner['uid']);
+               }
+
                $cid = Contact::getIdForURL($activity['actor'], $uid);
                if (empty($cid)) {
                        return;