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,36 +1130,22 @@ 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
{
// 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;
@ -1183,7 +1169,6 @@ class Contact
}
$contact_url = 'contact/' . $contact['id'];
$posts_link = 'contact/' . $contact['id'] . '/conversations';
$follow_link = '';

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,8 +495,10 @@ 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 = '';
@ -553,7 +556,7 @@ class Contact extends BaseModule
'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 = [];
}