X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=73118be0d04e92807f99e06bb2e1fc09551afbd8;hb=3aebb92cf3e9248dc4c6871b1f43cc02bdf28bfe;hp=a0bbdd10499f43abbf6138d976c7a145e6d66402;hpb=5c2cca432fe6b310df4bcf8dd1f002f5096693c0;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index a0bbdd1049..73118be0d0 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -124,6 +124,20 @@ class Contact extends BaseObject 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 @@ -894,7 +908,7 @@ class Contact extends BaseObject // 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]); } } @@ -1078,7 +1092,7 @@ class Contact extends BaseObject $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']; } @@ -2355,6 +2369,9 @@ class Contact extends BaseObject 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); } @@ -2444,4 +2461,18 @@ class Contact extends BaseObject // 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; + } }