]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Updated messages.po, keep a translatable string
[friendica.git] / src / Model / Contact.php
index 0c7fd3909e4cc55497de569352979a4516925da5..f095543ebdd725f560d426f0f423191aed7674c8 100644 (file)
@@ -832,11 +832,11 @@ class Contact
         * @param array   $user    User unfriending
         * @param array   $contact Contact (uid != 0) unfriended
         * @param boolean $two_way Revoke eventual inbound follow as well
-        * @return bool|null true if successful, false if not, null if no action was performed
+        * @return bool|null true if successful, false if not, null if no remote action was performed
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function terminateFriendship(array $user, array $contact): bool
+       public static function terminateFriendship(array $user, array $contact): ?bool
        {
                $result = Protocol::terminateFriendship($user, $contact);
 
@@ -857,7 +857,7 @@ class Contact
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function revokeFollow(array $contact): bool
+       public static function revokeFollow(array $contact): ?bool
        {
                if (empty($contact['network'])) {
                        throw new \InvalidArgumentException('Empty network in contact array');
@@ -1722,7 +1722,7 @@ class Contact
         * Get avatar link for given contact id
         *
         * @param integer $cid     contact id
-        * @param string  $size    One of the ProxyUtils::SIZE_* constants
+        * @param string  $size    One of the Proxy::SIZE_* constants
         * @param string  $updated Contact update date
         * @return string avatar link
         */
@@ -1764,7 +1764,7 @@ class Contact
         *
         * @param string  $url  contact url
         * @param integer $uid  user id
-        * @param string  $size One of the ProxyUtils::SIZE_* constants
+        * @param string  $size One of the Proxy::SIZE_* constants
         * @return string avatar link
         */
        public static function getAvatarUrlForUrl(string $url, int $uid, string $size = ''):string
@@ -1779,7 +1779,7 @@ class Contact
         * Get header link for given contact id
         *
         * @param integer $cid     contact id
-        * @param string  $size    One of the ProxyUtils::SIZE_* constants
+        * @param string  $size    One of the Proxy::SIZE_* constants
         * @param string  $updated Contact update date
         * @return string header link
         */
@@ -1933,7 +1933,7 @@ class Contact
 
                        if (!empty($cids)) {
                                // Delete possibly existing cached user contact avatars
-                               Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'album' => Photo::CONTACT_PHOTOS]);
+                               Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'photo-type' => Photo::CONTACT_AVATAR]);
                        }
                }
 
@@ -2218,11 +2218,7 @@ class Contact
                        self::updateAvatar($id, $ret['photo'], $update);
                }
 
-               if (empty($guid)) {
-                       $uriid = ItemURI::getIdByURI($ret['url']);
-               } else {
-                       $uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
-               }
+               $uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
 
                if (!$update) {
                        self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
@@ -3017,37 +3013,33 @@ class Contact
                }
 
                // check supported networks
+               $networks = [Protocol::DFRN, Protocol::ACTIVITYPUB];
                if (DI::config()->get('system', 'diaspora_enabled')) {
-                       $diaspora = Protocol::DIASPORA;
-               } else {
-                       $diaspora = Protocol::DFRN;
+                       $networks[] = Protocol::DIASPORA;
                }
 
                if (!DI::config()->get('system', 'ostatus_disabled')) {
-                       $ostatus = Protocol::OSTATUS;
-               } else {
-                       $ostatus = Protocol::DFRN;
+                       $networks[] = Protocol::OSTATUS;
+               }
+
+               $condition = ['network' => $networks, 'failed' => false, 'deleted' => false, 'uid' => $uid];
+
+               if ($uid == 0) {
+                       $condition['blocked'] = false;
                }
 
                // check if we search only communities or every contact
                if ($mode === 'community') {
-                       $extra_sql = sprintf(' AND `contact-type` = %d', self::TYPE_COMMUNITY);
-               } else {
-                       $extra_sql = '';
+                       $condition['contact-type'] = self::TYPE_COMMUNITY;
                }
 
                $search .= '%';
 
-               $results = DBA::p("SELECT * FROM `contact`
-                       WHERE (NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` where `publish` OR `net-publish`))
-                               AND `network` IN (?, ?, ?, ?) AND
-                               NOT `failed` AND `uid` = ? AND
-                               (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
-                               ORDER BY `nurl` DESC LIMIT 1000",
-                       Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $uid, $search, $search, $search
-               );
+               $condition = DBA::mergeConditions($condition,
+                       ["(NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` WHERE `publish` OR `net-publish`))
+                       AND (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
 
-               $contacts = DBA::toArray($results);
+               $contacts = self::selectToArray([], $condition);
                return $contacts;
        }