]> git.mxchange.org Git - friendica.git/commitdiff
We now handling the contact type
authorMichael <heluecht@pirati.ca>
Thu, 4 Jul 2019 19:31:42 +0000 (19:31 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 4 Jul 2019 19:31:42 +0000 (19:31 +0000)
src/Model/Contact.php
src/Model/GContact.php
src/Network/Probe.php
src/Protocol/ActivityPub.php

index 20dfc4d3526cb4252b10144b04bd68ce232b615c..bb0ba32c39958db2025f52c109dbc664b0d16e5f 100644 (file)
@@ -1821,8 +1821,12 @@ class Contact extends BaseObject
                  This will reliably kill your communication with old Friendica contacts.
                 */
 
+               // These fields aren't updated by this routine:
+               // 'location', 'about', 'keywords', 'gender', 'xmpp', 'unsearchable', 'sensitive'];
+
                $fields = ['avatar', 'uid', 'name', 'nick', 'url', 'addr', 'batch', 'notify',
-                       'poll', 'request', 'confirm', 'poco', 'network', 'alias', 'baseurl'];
+                       'poll', 'request', 'confirm', 'poco', 'network', 'alias', 'baseurl',
+                       'forum', 'prv', 'contact-type'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
                if (!DBA::isResult($contact)) {
                        return false;
@@ -1847,13 +1851,26 @@ class Contact extends BaseObject
                        return false;
                }
 
+               if (isset($ret['account-type'])) {
+                       $ret['forum'] = false;
+                       $ret['prv'] = false;
+                       $ret['contact-type'] = $ret['account-type'];
+                       if ($ret['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
+                               $apcontact = APContact::getByURL($ret['url'], false);
+                               if (isset($apcontact['manually-approve'])) {
+                                       $ret['forum'] = (bool)!$apcontact['manually-approve'];
+                                       $ret['prv'] = (bool)!$ret['forum'];
+                               }
+                       }
+               }
+
                $update = false;
 
                // make sure to not overwrite existing values with blank entries
                foreach ($ret as $key => $val) {
                        if (!array_key_exists($key, $contact)) {
                                unset($ret[$key]);
-                       } elseif (($contact[$key] != '') && ($val == '')) {
+                       } elseif (($contact[$key] != '') && ($val == '') && !is_bool($ret[$key])) {
                                $ret[$key] = $contact[$key];
                        } elseif ($ret[$key] != $contact[$key]) {
                                $update = true;
@@ -1886,6 +1903,17 @@ class Contact extends BaseObject
                return true;
        }
 
+       public static function updateFromProbeByURL($url, $force = false)
+       {
+               $id = self::getIdForURL($url);
+
+               if (empty($id)) {
+                       return;
+               }
+
+               self::updateFromProbe($id, '', $force);
+       }
+
        /**
         * Detects if a given contact array belongs to a legacy DFRN connection
         *
index 7da5f18e94790aec121e610d15732afe06606dbf..0fae0da9d9bc02fa801e6317dd1481aab39407c3 100644 (file)
@@ -913,30 +913,27 @@ class GContact
                        $old_gcontact = [];
                }
 
-               $gcontact = $contact;
+               $gcontact = [];
+
+               // These fields are identical in both contact and gcontact
+               $fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'gender',
+                       'contact-type', 'network', 'addr', 'notify', 'alias', 'created', 'updated'];
+
+               foreach ($fields as $field) {
+                       $gcontact[$field] = $contact[$field];
+               }
 
                // These fields are having different names but the same content
-               $gcontact['server_url'] = $gcontact['baseurl'];
-               unset($gcontact['baseurl']);
-               $gcontact['nsfw'] = $gcontact['sensitive'];
-               unset($gcontact['sensitive']);
-               $gcontact['hide'] = $gcontact['unsearchable'];
-               unset($gcontact['unsearchable']);
-               $gcontact['archived'] = $gcontact['archive'];
-               unset($gcontact['archive']);
-               $gcontact['archive_date'] = $gcontact['term-date'];
-               unset($gcontact['term-date']);
-               $gcontact['birthday'] = $gcontact['bd'];
-               unset($gcontact['bd']);
-               $gcontact['photo'] = $gcontact['avatar'];
-               unset($gcontact['avatar']);
-               $gcontact['last_contact'] = $gcontact['success_update'];
-               unset($gcontact['success_update']);
-               $gcontact['last_failure'] = $gcontact['failure_update'];
-               unset($gcontact['failure_update']);
-               $gcontact['community'] = ($gcontact['forum'] || $gcontact['prv']);
-               unset($gcontact['forum']);
-               unset($gcontact['prv']);
+               $gcontact['server_url'] = $contact['baseurl'];
+               $gcontact['nsfw'] = $contact['sensitive'];
+               $gcontact['hide'] = $contact['unsearchable'];
+               $gcontact['archived'] = $contact['archive'];
+               $gcontact['archive_date'] = $contact['term-date'];
+               $gcontact['birthday'] = $contact['bd'];
+               $gcontact['photo'] = $contact['avatar'];
+               $gcontact['last_contact'] = $contact['success_update'];
+               $gcontact['last_failure'] = $contact['failure_update'];
+               $gcontact['community'] = ($contact['forum'] || $contact['prv']);
 
                foreach (['last_contact', 'last_failure', 'updated'] as $field) {
                        if (!empty($old_gcontact[$field]) && ($old_gcontact[$field] >= $gcontact[$field])) {
index 5c20cc071f5633fda04570d8ec9d83a3e278305c..fae6f8c93e00ec6248977f3dcc6bb27b9ed5e03d 100644 (file)
@@ -45,8 +45,8 @@ class Probe
         */
        private static function rearrangeData($data)
        {
-               $fields = ["name", "nick", "guid", "url", "addr", "alias",
-                               "photo", "community", "keywords", "location", "about",
+               $fields = ["name", "nick", "guid", "url", "addr", "alias", "photo",
+                               "account-type", "community", "keywords", "location", "about",
                                "batch", "notify", "poll", "request", "confirm", "poco",
                                "priority", "network", "pubkey", "baseurl"];
 
@@ -349,6 +349,8 @@ class Probe
 
                        if (!empty($ap_profile) && empty($network) && (defaults($data, 'network', '') != Protocol::DFRN)) {
                                $data = $ap_profile;
+                       } elseif (!empty($ap_profile)) {
+                               $data = array_merge($ap_profile, $data);
                        }
                } else {
                        Logger::notice('Time out detected. AP will not be probed.', ['uri' => $uri]);
index 8caf7ac64c97bb8bd88510d8a93f414a03459030..42b5de9e211cfb6b0ddeddd8ffddba1b24774120 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\Util\JsonLD;
 use Friendica\Util\Network;
 use Friendica\Core\Protocol;
 use Friendica\Model\APContact;
+use Friendica\Model\User;
 use Friendica\Util\HTTPSignature;
 
 /**
@@ -88,6 +89,31 @@ class ActivityPub
                return $content;
        }
 
+       private static function getAccountType($apcontact)
+       {
+               $accounttype = -1;
+
+               switch($apcontact['type']) {
+                       case 'Person':
+                               $accounttype = User::ACCOUNT_TYPE_PERSON;
+                               break;
+                       case 'Organization':
+                               $accounttype = User::ACCOUNT_TYPE_ORGANISATION;
+                               break;
+                       case 'Service':
+                               $accounttype = User::ACCOUNT_TYPE_NEWS;
+                               break;
+                       case 'Group':
+                               $accounttype = User::ACCOUNT_TYPE_COMMUNITY;
+                               break;
+                       case 'Application':
+                               $accounttype = User::ACCOUNT_TYPE_RELAY;
+                               break;
+               }
+
+               return $accounttype;
+       }
+
        /**
         * Fetches a profile from the given url into an array that is compatible to Probe::uri
         *
@@ -112,7 +138,8 @@ class ActivityPub
                $profile['addr'] = $apcontact['addr'];
                $profile['alias'] = $apcontact['alias'];
                $profile['photo'] = $apcontact['photo'];
-               // $profile['community']
+               $profile['account-type'] = self::getAccountType($apcontact);
+               $profile['community'] = ($profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
                // $profile['keywords']
                // $profile['location']
                $profile['about'] = $apcontact['about'];