Remove fallback contact query from Model\Contact::photoMenu
- Correct contact is now supplied to the method
This commit is contained in:
parent
2d9633a595
commit
9da21bf680
3 changed files with 37 additions and 49 deletions
|
@ -1130,39 +1130,25 @@ class Contact
|
||||||
* Returns the data array for the photo menu of a given contact
|
* Returns the data array for the photo menu of a given contact
|
||||||
*
|
*
|
||||||
* @param array $contact contact
|
* @param array $contact contact
|
||||||
* @param int $uid optional, default 0
|
* @param int $uid Visitor user id
|
||||||
* @return array
|
* @return array
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @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 = '';
|
$status_link = '';
|
||||||
$photos_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;
|
$sparkle = false;
|
||||||
if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
|
if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
|
||||||
$sparkle = true;
|
$sparkle = true;
|
||||||
$profile_link = 'contact/redir/' . $contact['id'];
|
$profile_link = 'contact/redir/' . $contact['id'];
|
||||||
} else {
|
} else {
|
||||||
$profile_link = $contact['url'];
|
$profile_link = $contact['url'];
|
||||||
|
@ -1173,8 +1159,8 @@ class Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sparkle) {
|
if ($sparkle) {
|
||||||
$status_link = $profile_link . '/status';
|
$status_link = $profile_link . '/status';
|
||||||
$photos_link = $profile_link . '/photos';
|
$photos_link = $profile_link . '/photos';
|
||||||
$profile_link = $profile_link . '/profile';
|
$profile_link = $profile_link . '/profile';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1183,15 +1169,14 @@ class Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact_url = 'contact/' . $contact['id'];
|
$contact_url = 'contact/' . $contact['id'];
|
||||||
|
|
||||||
$posts_link = 'contact/' . $contact['id'] . '/conversations';
|
$posts_link = 'contact/' . $contact['id'] . '/conversations';
|
||||||
|
|
||||||
$follow_link = '';
|
$follow_link = '';
|
||||||
$unfollow_link = '';
|
$unfollow_link = '';
|
||||||
if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) {
|
if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) {
|
||||||
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
|
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
|
||||||
$unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1';
|
$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';
|
$follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1202,27 +1187,27 @@ class Contact
|
||||||
*/
|
*/
|
||||||
if (empty($contact['uid'])) {
|
if (empty($contact['uid'])) {
|
||||||
$menu = [
|
$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],
|
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
|
||||||
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
|
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
|
||||||
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
|
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
|
||||||
'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link, true],
|
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$menu = [
|
$menu = [
|
||||||
'status' => [DI::l10n()->t('View Status') , $status_link , true],
|
'status' => [DI::l10n()->t('View Status') , $status_link , true ],
|
||||||
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true],
|
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
|
||||||
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true],
|
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true ],
|
||||||
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
|
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
|
||||||
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
|
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
|
||||||
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
|
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
|
||||||
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
|
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
|
||||||
'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link , true],
|
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($contact['pending'])) {
|
if (!empty($contact['pending'])) {
|
||||||
try {
|
try {
|
||||||
$intro = DI::intro()->selectForContact($contact['id']);
|
$intro = DI::intro()->selectForContact($contact['id']);
|
||||||
$menu['follow'] = [DI::l10n()->t('Approve'), 'notifications/intros/' . $intro->id, true];
|
$menu['follow'] = [DI::l10n()->t('Approve'), 'notifications/intros/' . $intro->id, true];
|
||||||
} catch (IntroductionNotFoundException $exception) {
|
} catch (IntroductionNotFoundException $exception) {
|
||||||
DI::logger()->error('Pending contact doesn\'t have an introduction.', ['exception' => $exception]);
|
DI::logger()->error('Pending contact doesn\'t have an introduction.', ['exception' => $exception]);
|
||||||
|
|
|
@ -35,6 +35,7 @@ use Friendica\DI;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Module\Security\Login;
|
use Friendica\Module\Security\Login;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -494,16 +495,18 @@ class Contact extends BaseModule
|
||||||
*
|
*
|
||||||
* @param array $contact Contact array
|
* @param array $contact Contact array
|
||||||
* @return array Template fields
|
* @return array Template fields
|
||||||
|
* @throws InternalServerErrorException
|
||||||
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function getContactTemplateVars(array $contact)
|
public static function getContactTemplateVars(array $contact): array
|
||||||
{
|
{
|
||||||
$alt_text = '';
|
$alt_text = '';
|
||||||
|
|
||||||
if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && DI::userSession()->getLocalUserId()) {
|
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());
|
$personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], DI::userSession()->getLocalUserId());
|
||||||
if (!empty($personal)) {
|
if (!empty($personal)) {
|
||||||
$contact['uid'] = $personal['uid'];
|
$contact['uid'] = $personal['uid'];
|
||||||
$contact['rel'] = $personal['rel'];
|
$contact['rel'] = $personal['rel'];
|
||||||
$contact['self'] = $personal['self'];
|
$contact['self'] = $personal['self'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,15 +548,15 @@ class Contact extends BaseModule
|
||||||
|
|
||||||
if ($contact['self']) {
|
if ($contact['self']) {
|
||||||
$alt_text = DI::l10n()->t('This is you');
|
$alt_text = DI::l10n()->t('This is you');
|
||||||
$url = $contact['url'];
|
$url = $contact['url'];
|
||||||
$sparkle = '';
|
$sparkle = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $contact['id'],
|
'id' => $contact['id'],
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['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),
|
'thumb' => Model\Contact::getThumb($contact, true),
|
||||||
'alt_text' => $alt_text,
|
'alt_text' => $alt_text,
|
||||||
'name' => $contact['name'],
|
'name' => $contact['name'],
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Hovercard extends BaseModule
|
||||||
|
|
||||||
// Get the photo_menu - the menu if possible contact actions
|
// Get the photo_menu - the menu if possible contact actions
|
||||||
if ($this->userSession->isAuthenticated()) {
|
if ($this->userSession->isAuthenticated()) {
|
||||||
$actions = Contact::photoMenu($contact);
|
$actions = Contact::photoMenu($contact, $this->userSession->getLocalUserId());
|
||||||
} else {
|
} else {
|
||||||
$actions = [];
|
$actions = [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue