Remove fallback contact query from Model\Contact::photoMenu

- Correct contact is now supplied to the method
This commit is contained in:
Hypolite Petovan 2022-12-17 01:20:59 -05:00
parent 2d9633a595
commit 9da21bf680
3 changed files with 37 additions and 49 deletions

View File

@ -1130,39 +1130,25 @@ class Contact
* Returns the data array for the photo menu of a given contact
*
* @param array $contact contact
* @param int $uid optional, default 0
* @param int $uid Visitor user id
* @return array
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function photoMenu(array $contact, int $uid = 0): array
public static function photoMenu(array $contact, int $uid): array
{
$pm_url = '';
// Anonymous visitor
if (!$uid) {
return ['profile' => [DI::l10n()->t('View Profile'), self::magicLinkByContact($contact), true]];
}
$pm_url = '';
$status_link = '';
$photos_link = '';
if ($uid == 0) {
$uid = DI::userSession()->getLocalUserId();
}
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
if ($uid == 0) {
$profile_link = self::magicLinkByContact($contact);
$menu = ['profile' => [DI::l10n()->t('View Profile'), $profile_link, true]];
return $menu;
}
// Look for our own contact if the uid doesn't match and isn't public
$contact_own = DBA::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
if (DBA::isResult($contact_own)) {
return self::photoMenu($contact_own, $uid);
}
}
$sparkle = false;
if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
$sparkle = true;
$sparkle = true;
$profile_link = 'contact/redir/' . $contact['id'];
} else {
$profile_link = $contact['url'];
@ -1173,8 +1159,8 @@ class Contact
}
if ($sparkle) {
$status_link = $profile_link . '/status';
$photos_link = $profile_link . '/photos';
$status_link = $profile_link . '/status';
$photos_link = $profile_link . '/photos';
$profile_link = $profile_link . '/profile';
}
@ -1183,15 +1169,14 @@ class Contact
}
$contact_url = 'contact/' . $contact['id'];
$posts_link = 'contact/' . $contact['id'] . '/conversations';
$follow_link = '';
$follow_link = '';
$unfollow_link = '';
if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) {
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
$unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1';
} elseif(!$contact['pending']) {
} elseif (!$contact['pending']) {
$follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1';
}
}
@ -1202,27 +1187,27 @@ class Contact
*/
if (empty($contact['uid'])) {
$menu = [
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link, true],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
];
} else {
$menu = [
'status' => [DI::l10n()->t('View Status') , $status_link , true],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true],
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link , true],
'status' => [DI::l10n()->t('View Status') , $status_link , true ],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true ],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
];
if (!empty($contact['pending'])) {
try {
$intro = DI::intro()->selectForContact($contact['id']);
$intro = DI::intro()->selectForContact($contact['id']);
$menu['follow'] = [DI::l10n()->t('Approve'), 'notifications/intros/' . $intro->id, true];
} catch (IntroductionNotFoundException $exception) {
DI::logger()->error('Pending contact doesn\'t have an introduction.', ['exception' => $exception]);

View File

@ -35,6 +35,7 @@ use Friendica\DI;
use Friendica\Model;
use Friendica\Model\User;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\NotFoundException;
/**
@ -494,16 +495,18 @@ class Contact extends BaseModule
*
* @param array $contact Contact array
* @return array Template fields
* @throws InternalServerErrorException
* @throws \ImagickException
*/
public static function getContactTemplateVars(array $contact)
public static function getContactTemplateVars(array $contact): array
{
$alt_text = '';
if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && DI::userSession()->getLocalUserId()) {
$personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], DI::userSession()->getLocalUserId());
if (!empty($personal)) {
$contact['uid'] = $personal['uid'];
$contact['rel'] = $personal['rel'];
$contact['uid'] = $personal['uid'];
$contact['rel'] = $personal['rel'];
$contact['self'] = $personal['self'];
}
}
@ -545,15 +548,15 @@ class Contact extends BaseModule
if ($contact['self']) {
$alt_text = DI::l10n()->t('This is you');
$url = $contact['url'];
$sparkle = '';
$url = $contact['url'];
$sparkle = '';
}
return [
'id' => $contact['id'],
'url' => $url,
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
'photo_menu' => Model\Contact::photoMenu($contact),
'photo_menu' => Model\Contact::photoMenu($contact, DI::userSession()->getLocalUserId()),
'thumb' => Model\Contact::getThumb($contact, true),
'alt_text' => $alt_text,
'name' => $contact['name'],

View File

@ -90,7 +90,7 @@ class Hovercard extends BaseModule
// Get the photo_menu - the menu if possible contact actions
if ($this->userSession->isAuthenticated()) {
$actions = Contact::photoMenu($contact);
$actions = Contact::photoMenu($contact, $this->userSession->getLocalUserId());
} else {
$actions = [];
}