]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7250 from MrPetovan/bug/6410-normalize-message-button
authorPhilipp <admin+Github@philipp.info>
Wed, 12 Jun 2019 15:56:05 +0000 (17:56 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jun 2019 15:56:05 +0000 (17:56 +0200)
Normalize message button in profile sidebar

1  2 
src/Model/Contact.php

diff --combined src/Model/Contact.php
index 7e1d8c2ba5d9a174534df794fd619ff454dcb4d4,73118be0d04e92807f99e06bb2e1fc09551afbd8..01bbd23a6d415983e3269af3ea9eda3aea092a98
@@@ -124,6 -124,20 +124,20 @@@ class Contact extends BaseObjec
                return DBA::toArray($statement);
        }
  
+       /**
+        * @param array $fields    Array of selected fields, empty for all
+        * @param array $condition Array of fields for condition
+        * @param array $params    Array of several parameters
+        * @return array
+        * @throws \Exception
+        */
+       public static function selectFirst(array $fields = [], array $condition = [], array $params = [])
+       {
+               $contact = DBA::selectFirst('contact', $fields, $condition, $params);
+               return $contact;
+       }
        /**
         * @param integer $id     Contact ID
         * @param array   $fields Array of selected fields, empty for all
                        // If there is more than one entry we filter out the connector networks
                        if (count($r) > 1) {
                                foreach ($r as $id => $result) {
-                                       if ($result["network"] == Protocol::STATUSNET) {
+                                       if (!in_array($result["network"], Protocol::NATIVE_SUPPORT)) {
                                                unset($r[$id]);
                                        }
                                }
                        $profile_link = $profile_link . '?tab=profile';
                }
  
-               if (in_array($contact['network'], [Protocol::DFRN, Protocol::DIASPORA]) && !$contact['self']) {
+               if (self::canReceivePrivateMessages($contact)) {
                        $pm_url = System::baseUrl() . '/message/new/' . $contact['id'];
                }
  
  
                if (!empty($contact)) {
              // Contact is blocked at user-level
 -                  if (self::isBlockedByUser($contact['id'], $importer['id'])) {
 +                  if (!empty($contact['id']) && !empty($importer['id']) &&
 +                      self::isBlockedByUser($contact['id'], $importer['id'])) {
                        return false;
              }
  
                        return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
                }
  
+               // Prevents endless loop in case only a non-public contact exists for the contact URL
+               unset($data['uid']);
                return self::magicLinkByContact($data, $contact_url);
        }
  
                // Is it a forum?
                return ($contact['forum'] || $contact['prv']);
        }
+       /**
+        * Can the remote contact receive private messages?
+        *
+        * @param array $contact
+        * @return bool
+        */
+       public static function canReceivePrivateMessages(array $contact)
+       {
+               $protocol = $contact['network'] ?? $contact['protocol'] ?? Protocol::PHANTOM;
+               $self = $contact['self'] ?? false;
+               return in_array($protocol, [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB]) && !$self;
+       }
  }