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
This commit is contained in:
Hypolite Petovan 2021-11-07 17:19:29 -05:00
parent 25455eab63
commit eacfcc69c1
5 changed files with 107 additions and 39 deletions

View File

@ -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
*

View File

@ -0,0 +1,102 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -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]],

View File

@ -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)}}
<span role="presentation" class="separator"></span>
<span class="more-links btn-group{{if $item.thread_level> 1}} dropup{{/if}}">
<button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i>&nbsp;{{$item.menu}}</button>

View File

@ -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)}}
<span role="presentation" class="separator"></span>
<span class="more-links btn-group{{if $item.thread_level > 1}} dropup{{/if}}">
<button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i>&nbsp;{{$item.menu}}</button>