]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Issue 8151: Automatic Friend is working again
[friendica.git] / src / Model / Contact.php
index 3d3438955857bc9f549e0f4caba5b7673139ce5e..e4f142e3a2d93d06bfb74ef3d6fad368de333489 100644 (file)
@@ -640,35 +640,6 @@ class Contact
                return $return;
        }
 
-       /**
-        * Returns the count of OStatus contacts in a group
-        *
-        * @param int $gid
-        * @return int
-        * @throws \Exception
-        */
-       public static function getOStatusCountByGroupId($gid)
-       {
-               $return = 0;
-               if (intval($gid)) {
-                       $contacts = DBA::fetchFirst('SELECT COUNT(*) AS `count`
-                               FROM `contact`
-                               INNER JOIN `group_member`
-                                       ON `contact`.`id` = `group_member`.`contact-id`
-                               WHERE `gid` = ?
-                               AND `contact`.`uid` = ?
-                               AND `contact`.`network` = ?
-                               AND `contact`.`notify` != ""',
-                               $gid,
-                               local_user(),
-                               Protocol::OSTATUS
-                       );
-                       $return = $contacts['count'];
-               }
-
-               return $return;
-       }
-
        /**
         * Creates the self-contact for the provided user id
         *
@@ -725,7 +696,7 @@ class Contact
         */
        public static function updateSelfFromUserID($uid, $update_avatar = false)
        {
-               $fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'gender', 'avatar',
+               $fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'avatar',
                        'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
                        'photo', 'thumb', 'micro', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco'];
                $self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
@@ -733,13 +704,13 @@ class Contact
                        return;
                }
 
-               $fields = ['nickname', 'page-flags', 'account-type', 'hidewall'];
+               $fields = ['nickname', 'page-flags', 'account-type'];
                $user = DBA::selectFirst('user', $fields, ['uid' => $uid]);
                if (!DBA::isResult($user)) {
                        return;
                }
 
-               $fields = ['name', 'photo', 'thumb', 'pdesc' => 'about', 'address', 'locality', 'region',
+               $fields = ['name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
                        'country-name', 'pub_keywords', 'xmpp', 'net-publish'];
                $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
                if (!DBA::isResult($profile)) {
@@ -751,7 +722,7 @@ class Contact
                $fields = ['name' => $profile['name'], 'nick' => $user['nickname'],
                        'avatar-date' => $self['avatar-date'], 'location' => Profile::formatLocation($profile),
                        'about' => $profile['about'], 'keywords' => $profile['pub_keywords'],
-                       'gender' => '', 'contact-type' => $user['account-type'],
+                       'contact-type' => $user['account-type'],
                        'xmpp' => $profile['xmpp']];
 
                $avatar = Photo::selectFirst(['resource-id', 'type'], ['uid' => $uid, 'profile' => true]);
@@ -785,7 +756,7 @@ class Contact
                $fields['avatar'] = DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix;
                $fields['forum'] = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
                $fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
-               $fields['unsearchable'] = $user['hidewall'] || !$profile['net-publish'];
+               $fields['unsearchable'] = !$profile['net-publish'];
 
                // it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
                $fields['url'] = DI::baseUrl() . '/profile/' . $user['nickname'];
@@ -1029,14 +1000,14 @@ class Contact
 
                // Fetch contact data from the contact table for the given user
                $s = DBA::p("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                       `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
+                       `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
                FROM `contact` WHERE `nurl` = ? AND `uid` = ?", $nurl, $uid);
                $r = DBA::toArray($s);
 
                // Fetch contact data from the contact table for the given user, checking with the alias
                if (!DBA::isResult($r)) {
                        $s = DBA::p("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                               `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
+                               `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
                        FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = ?", $nurl, $url, $ssl_url, $uid);
                        $r = DBA::toArray($s);
                }
@@ -1044,7 +1015,7 @@ class Contact
                // Fetch the data from the contact table with "uid=0" (which is filled automatically)
                if (!DBA::isResult($r)) {
                        $s = DBA::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                       `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
+                       `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
                        FROM `contact` WHERE `nurl` = ? AND `uid` = 0", $nurl);
                        $r = DBA::toArray($s);
                }
@@ -1052,7 +1023,7 @@ class Contact
                // Fetch the data from the contact table with "uid=0" (which is filled automatically) - checked with the alias
                if (!DBA::isResult($r)) {
                        $s = DBA::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                       `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
+                       `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
                        FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = 0", $nurl, $url, $ssl_url);
                        $r = DBA::toArray($s);
                }
@@ -1060,12 +1031,13 @@ class Contact
                // Fetch the data from the gcontact table
                if (!DBA::isResult($r)) {
                        $s = DBA::p("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
-                       `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, 0 AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`
+                       `keywords`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, 0 AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`
                        FROM `gcontact` WHERE `nurl` = ?", $nurl);
                        $r = DBA::toArray($s);
                }
 
                if (DBA::isResult($r)) {
+                       $authoritativeResult = true;
                        // If there is more than one entry we filter out the connector networks
                        if (count($r) > 1) {
                                foreach ($r as $id => $result) {
@@ -1099,6 +1071,7 @@ class Contact
                                $profile["bd"] = DBA::NULL_DATE;
                        }
                } else {
+                       $authoritativeResult = false;
                        $profile = $default;
                }
 
@@ -1132,11 +1105,14 @@ class Contact
                if (empty($profile["cid"]) && ($profile["network"] ?? "") == Protocol::DIASPORA) {
                        $profile["location"] = "";
                        $profile["about"] = "";
-                       $profile["gender"] = "";
                        $profile["birthday"] = DBA::NULL_DATE;
                }
 
-               $cache[$url][$uid] = $profile;
+               // Only cache the result if it came from the DB since this method is used in widely different contexts
+               // @see display_fetch_author for an example of $default parameter diverging from the DB result
+               if ($authoritativeResult) {
+                       $cache[$url][$uid] = $profile;
+               }
 
                return $profile;
        }
@@ -1165,7 +1141,7 @@ class Contact
 
                // Fetch contact data from the contact table for the given user
                $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                       `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
+                       `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
                        FROM `contact` WHERE `addr` = '%s' AND `uid` = %d AND NOT `deleted`",
                        DBA::escape($addr),
                        intval($uid)
@@ -1173,7 +1149,7 @@ class Contact
                // Fetch the data from the contact table with "uid=0" (which is filled automatically)
                if (!DBA::isResult($r)) {
                        $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                               `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
+                               `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
                                FROM `contact` WHERE `addr` = '%s' AND `uid` = 0 AND NOT `deleted`",
                                DBA::escape($addr)
                        );
@@ -1182,7 +1158,7 @@ class Contact
                // Fetch the data from the gcontact table
                if (!DBA::isResult($r)) {
                        $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
-                               `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`
+                               `keywords`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`
                                FROM `gcontact` WHERE `addr` = '%s'",
                                DBA::escape($addr)
                        );
@@ -1279,6 +1255,10 @@ class Contact
                        }
                }
 
+               if (!empty($follow_link) || !empty($unfollow_link)) {
+                       $contact_drop_link = '';
+               }
+
                /**
                 * Menu array:
                 * "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
@@ -1805,7 +1785,15 @@ class Contact
                                $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
                }
 
-               $pager = new Pager(DI::args()->getQueryString());
+               if (DI::mode()->isMobile()) {
+                       $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+                               DI::config()->get('system', 'itemspage_network_mobile'));
+               } else {
+                       $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+                               DI::config()->get('system', 'itemspage_network'));
+               }
+
+               $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
 
                $params = ['order' => ['received' => true],
                        'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
@@ -1815,13 +1803,13 @@ class Contact
 
                        $items = Item::inArray($r);
 
-                       $o = conversation($a, $items, $pager, 'contacts', $update, false, 'commented', local_user());
+                       $o = conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
                } else {
                        $r = Item::selectForUser(local_user(), [], $condition, $params);
 
                        $items = Item::inArray($r);
 
-                       $o = conversation($a, $items, $pager, 'contact-posts', false);
+                       $o = conversation($a, $items, 'contact-posts', false);
                }
 
                if (!$update) {
@@ -2086,7 +2074,7 @@ class Contact
                // These fields aren't updated by this routine:
                // 'xmpp', 'sensitive'
 
-               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'gender',
+               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about',
                        'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
                        'network', 'alias', 'baseurl', 'forum', 'prv', 'contact-type', 'pubkey'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
@@ -2665,8 +2653,17 @@ class Contact
                                        ]);
                                }
                        } elseif (DBA::isResult($user) && in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
+                               if (($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) && ($network != Protocol::DIASPORA)) {
+                                       self::createFromProbe($importer['uid'], $url, false, $network);
+                               }
+
                                $condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];
-                               DBA::update('contact', ['pending' => false], $condition);
+                               $fields = ['pending' => false];
+                               if ($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) {
+                                       $fields['rel'] = Contact::FRIEND;
+                               }
+
+                               DBA::update('contact', $fields, $condition);
 
                                return true;
                        }