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 = '';
@ -1191,7 +1176,7 @@ class Contact
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,22 +1187,22 @@ class Contact
*/
if (empty($contact['uid'])) {
$menu = [
'profile' => [DI::l10n()->t('View Profile') , $profile_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],
'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],
'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],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
];
if (!empty($contact['pending'])) {

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 = [];
}