X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=cbe370a4aa8250d35a899d3b1de59d2e32105adf;hb=456ae169aba480141c43616eca385605aa1911d4;hp=faad2adc78c27c2cc91cfeabfc7e741752517535;hpb=b0d8136b008d17bf9e3579338633c8e3abcfdced;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index faad2adc78..cbe370a4aa 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -653,9 +653,9 @@ class Contact 'nick' => $user['nickname'], 'pubkey' => $user['pubkey'], 'prvkey' => $user['prvkey'], - 'photo' => User::getAvatarUrlForId($user['uid']), - 'thumb' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_THUMB), - 'micro' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_MICRO), + 'photo' => User::getAvatarUrl($user), + 'thumb' => User::getAvatarUrl($user, Proxy::SIZE_THUMB), + 'micro' => User::getAvatarUrl($user, Proxy::SIZE_MICRO), 'blocked' => 0, 'pending' => 0, 'url' => DI::baseUrl() . '/profile/' . $user['nickname'], @@ -709,7 +709,7 @@ class Contact return false; } - $fields = ['nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey']; + $fields = ['uid', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey']; $user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'account_expired' => false]); if (!DBA::isResult($user)) { return false; @@ -768,7 +768,7 @@ class Contact $fields['micro'] = self::getDefaultAvatar($fields, Proxy::SIZE_MICRO); } - $fields['avatar'] = User::getAvatarUrlForId($uid); + $fields['avatar'] = User::getAvatarUrl($user); $fields['forum'] = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY; $fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP; $fields['unsearchable'] = !$profile['net-publish']; @@ -795,8 +795,8 @@ class Contact // Update the profile $fields = [ - 'photo' => User::getAvatarUrlForId($uid), - 'thumb' => User::getAvatarUrlForId($uid, Proxy::SIZE_THUMB) + 'photo' => User::getAvatarUrl($user), + 'thumb' => User::getAvatarUrl($user, Proxy::SIZE_THUMB) ]; DBA::update('profile', $fields, ['uid' => $uid]); @@ -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); @@ -1722,19 +1722,22 @@ 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 */ - public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = ''):string + public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string { // We have to fetch the "updated" variable when it wasn't provided // The parameter can be provided to improve performance - if (empty($updated)) { - $contact = self::getById($cid, ['updated']); - $updated = $contact['updated'] ?? ''; + if (empty($updated) || empty($guid)) { + $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]); + $updated = $account['updated'] ?? ''; + $guid = $account['guid'] ?? ''; } + $guid = urlencode($guid); + $url = DI::baseUrl() . '/photo/contact/'; switch ($size) { case Proxy::SIZE_MICRO: @@ -1753,7 +1756,7 @@ class Contact $url .= Proxy::PIXEL_LARGE . '/'; break; } - return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : ''); + return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : ''); } /** @@ -1761,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 @@ -1776,19 +1779,22 @@ 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 */ - public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = ''):string + public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string { // We have to fetch the "updated" variable when it wasn't provided // The parameter can be provided to improve performance - if (empty($updated)) { - $contact = self::getById($cid, ['updated']); - $updated = $contact['updated'] ?? ''; + if (empty($updated) || empty($guid)) { + $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]); + $updated = $account['updated'] ?? ''; + $guid = $account['guid'] ?? ''; } + $guid = urlencode($guid); + $url = DI::baseUrl() . '/photo/header/'; switch ($size) { case Proxy::SIZE_MICRO: @@ -1808,7 +1814,7 @@ class Contact break; } - return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : ''); + return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : ''); } /** @@ -2184,7 +2190,7 @@ class Contact } $update = false; - $guid = $ret['guid'] ?? ''; + $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST)); // make sure to not overwrite existing values with blank entries except some technical fields $keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl']; @@ -2212,6 +2218,8 @@ class Contact self::updateAvatar($id, $ret['photo'], $update); } + $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]); @@ -2230,12 +2238,7 @@ class Contact return true; } - if (empty($guid)) { - $ret['uri-id'] = ItemURI::getIdByURI($ret['url']); - } else { - $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]); - } - + $ret['uri-id'] = $uriid; $ret['nurl'] = Strings::normaliseLink($ret['url']); $ret['updated'] = $updated; $ret['failed'] = false; @@ -2705,7 +2708,7 @@ class Contact // Ensure to always have the correct network type, independent from the connection request method self::updateFromProbe($contact['id']); - Post\UserNotification::insertNotication($contact['id'], Verb::getID(Activity::FOLLOW), $importer['uid']); + Post\UserNotification::insertNotification($contact['id'], Activity::FOLLOW, $importer['uid']); return true; } else { @@ -2736,7 +2739,7 @@ class Contact self::updateAvatar($contact_id, $photo, true); - Post\UserNotification::insertNotication($contact_id, Verb::getID(Activity::FOLLOW), $importer['uid']); + Post\UserNotification::insertNotification($contact_id, Activity::FOLLOW, $importer['uid']); $contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);