From eacfcc69c1e478b454f7b75796f7867fe5937114 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 7 Nov 2021 17:19:29 -0500 Subject: [PATCH] Move contact posts to their own module class - Remove duplicated check for local_user() in Module\Contact - [frio] Fix display issue for search items where the More button and icon would show but be inactive --- src/Module/Contact.php | 38 +------- src/Module/Contact/Posts.php | 102 ++++++++++++++++++++++ static/routes.config.php | 2 +- view/theme/frio/templates/search_item.tpl | 2 +- view/theme/frio/templates/wall_thread.tpl | 2 +- 5 files changed, 107 insertions(+), 39 deletions(-) create mode 100644 src/Module/Contact/Posts.php diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 243ec4be3..fc518d104 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -252,7 +252,7 @@ class Contact extends BaseModule $contact = null; // @TODO: Replace with parameter from router if (DI::args()->getArgc() == 2 && intval(DI::args()->getArgv()[1]) - || DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations']) + || DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['conversations']) ) { $contact_id = intval(DI::args()->getArgv()[1]); @@ -279,7 +279,7 @@ class Contact extends BaseModule if (DBA::isResult($contact)) { if ($contact['self']) { // @TODO: Replace with parameter from router - if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])) { + if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['conversations'])) { DI::baseUrl()->redirect('profile/' . $contact['nick']); } else { DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile'); @@ -324,11 +324,6 @@ class Contact extends BaseModule $o = ''; Nav::setSelected('contact'); - if (!local_user()) { - notice(DI::l10n()->t('Permission denied.')); - return Login::form(); - } - if (DI::args()->getArgc() == 3) { $contact_id = intval(DI::args()->getArgv()[1]); if (!$contact_id) { @@ -343,10 +338,6 @@ class Contact extends BaseModule throw new NotFoundException(DI::l10n()->t('Contact not found')); } - if ($cmd === 'posts') { - return self::getPostsHTML($contact_id); - } - if ($cmd === 'conversations') { return self::getConversationsHMTL($a, $contact_id, $update); } @@ -910,31 +901,6 @@ class Contact extends BaseModule return $o; } - private static function getPostsHTML(int $contact_id) - { - $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]); - - $o = self::getTabsHTML($contact, self::TAB_POSTS); - - if (DBA::isResult($contact)) { - $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user()); - - if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) { - $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']); - } - - DI::page()['aside'] = Widget\VCard::getHTML($profiledata); - - if ($contact['uid'] == 0) { - $o .= Model\Contact::getPostsFromId($contact['id']); - } else { - $o .= Model\Contact::getPostsFromUrl($contact['url']); - } - } - - return $o; - } - /** * Return the fields for the contact template * diff --git a/src/Module/Contact/Posts.php b/src/Module/Contact/Posts.php new file mode 100644 index 000000000..3409d9169 --- /dev/null +++ b/src/Module/Contact/Posts.php @@ -0,0 +1,102 @@ +. + * + */ + +namespace Friendica\Module\Contact; + +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Contact\LocalRelationship\Repository\LocalRelationship; +use Friendica\Content\Nav; +use Friendica\Content\Widget; +use Friendica\Core\L10n; +use Friendica\Core\Protocol; +use Friendica\Database\DBA; +use Friendica\Model; +use Friendica\Module\Contact; +use Friendica\Module\Security\Login; +use Friendica\Network\HTTPException\NotFoundException; + +/** + * Show a contact posts and comments + */ +class Posts extends BaseModule +{ + /** + * @var LocalRelationship + */ + private $localRelationship; + /** + * @var App\BaseURL + */ + private $baseUrl; + /** + * @var App\Page + */ + private $page; + + public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Page $page, array $parameters = []) + { + parent::__construct($l10n, $parameters); + + $this->localRelationship = $localRelationship; + $this->baseUrl = $baseUrl; + $this->page = $page; + } + + public function content(): string + { + if (!local_user()) { + return Login::form($_SERVER['REQUEST_URI']); + } + + // Backward compatibility: Ensure to use the public contact when the user contact is provided + // Remove by version 2022.03 + $data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), local_user()); + if (empty($data)) { + throw new NotFoundException($this->t('Contact not found.')); + } + + $contact = Model\Contact::getById($data['public']); + if (!DBA::isResult($contact)) { + throw new NotFoundException($this->t('Contact not found.')); + } + + // Don't display contacts that are about to be deleted + if (DBA::isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) { + throw new NotFoundException($this->t('Contact not found.')); + } + + $localRelationship = $this->localRelationship->getForUserContact(local_user(), $contact['id']); + if ($localRelationship->rel === Model\Contact::SELF) { + $this->baseUrl->redirect('profile/' . $contact['nick']); + } + + $this->page['aside'] .= Widget\VCard::getHTML($contact); + + Nav::setSelected('contact'); + + $o = Contact::getTabsHTML($contact, Contact::TAB_POSTS); + + $o .= Model\Contact::getPostsFromId($contact['id']); + + return $o; + } +} diff --git a/static/routes.config.php b/static/routes.config.php index e3ab67761..36df142a6 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -338,7 +338,7 @@ return [ '/{id:\d+}/ignore' => [Module\Contact::class, [R::GET]], '/{id:\d+}/media' => [Module\Contact\Media::class, [R::GET]], '/{id:\d+}/poke' => [Module\Contact\Poke::class, [R::GET, R::POST]], - '/{id:\d+}/posts' => [Module\Contact::class, [R::GET]], + '/{id:\d+}/posts' => [Module\Contact\Posts::class, [R::GET]], '/{id:\d+}/revoke' => [Module\Contact\Revoke::class, [R::GET, R::POST]], '/{id:\d+}/update' => [Module\Contact::class, [R::GET]], '/{id:\d+}/updateprofile' => [Module\Contact::class, [R::GET]], diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 344e73f1d..e31537b15 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -174,7 +174,7 @@ {{* Put additional actions in a dropdown menu *}} - {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}} + {{if $item.menu && ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping)}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index e91b1b99f..bbacdfc5b 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -326,7 +326,7 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} {{* Put additional actions in a dropdown menu *}} - {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}} + {{if $item.menu && ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping)}}