Issue 9366: filter account types on the network page

This commit is contained in:
Michael 2020-10-05 16:48:28 +00:00
parent cc42c0ba27
commit 6c3ffb75a6
7 changed files with 84 additions and 33 deletions

View File

@ -36,6 +36,7 @@ use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Post\Category;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\Contact as ModuleContact;
use Friendica\Module\Security\Login;
use Friendica\Util\DateTimeFormat;
@ -131,6 +132,13 @@ function network_init(App $a)
DI::page()['aside'] = '';
}
if (in_array($a->argv[1], ['person', 'organisation', 'news', 'community'])) {
$accounttype = $a->argv[1];
} else {
$accounttype = '';
}
DI::page()['aside'] .= Widget::accounts('network', $accounttype);
DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
DI::page()['aside'] .= ForumManager::widget(local_user(), $cid);
DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false);
@ -292,10 +300,28 @@ function network_content(App $a, $update = 0, $parent = 0)
$o = '';
}
switch ($a->argv[1] ?? '') {
case 'person':
$account = User::ACCOUNT_TYPE_PERSON;
break;
case 'organisation':
$account = User::ACCOUNT_TYPE_ORGANISATION;
break;
case 'news':
$account = User::ACCOUNT_TYPE_NEWS;
break;
case 'community':
$account = User::ACCOUNT_TYPE_COMMUNITY;
break;
default:
$account = null;
break;
}
if (!empty($_GET['file'])) {
$o .= networkFlatView($a, $update);
$o .= networkFlatView($a, $update, $account);
} else {
$o .= networkThreadedView($a, $update, $parent);
$o .= networkThreadedView($a, $update, $parent, $account);
}
if (!$update && ($o === '')) {
@ -315,7 +341,7 @@ function network_content(App $a, $update = 0, $parent = 0)
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @global Pager $pager
*/
function networkFlatView(App $a, $update = 0)
function networkFlatView(App $a, $update, $account)
{
global $pager;
// Rawmode is used for fetching new content at the end of the page
@ -383,6 +409,10 @@ function networkFlatView(App $a, $update = 0)
networkSetSeen(['unseen' => true, 'uid' => local_user()]);
}
if (!empty($account)) {
$item_condition['contact-type'] = $account;
}
$result = Item::selectForUser(local_user(), [], $item_condition, $item_params);
$items = Item::inArray($result);
$o .= networkConversation($a, $items, $pager, 'network-new', $update);
@ -401,7 +431,7 @@ function networkFlatView(App $a, $update = 0)
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @global Pager $pager
*/
function networkThreadedView(App $a, $update, $parent)
function networkThreadedView(App $a, $update, $parent, $account)
{
/// @TODO this will have to be converted to a static property of the converted Module\Network class
global $pager;
@ -507,6 +537,10 @@ function networkThreadedView(App $a, $update, $parent)
$conditionFields = ['uid' => local_user()];
$conditionStrings = [];
if (!empty($account)) {
$conditionFields['contact-type'] = $account;
}
if ($star) {
$conditionFields['starred'] = true;
}

View File

@ -525,4 +525,25 @@ class Widget
return $o;
}
/**
* Display the accounts sidebar
*
* @param string $base Basepath
* @param string $accounttype Acount type (person, organisation, news, community)
* @return string
*/
public static function accounts(string $base, string $accounttype)
{
return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/accounts.tpl'), [
'$title' => DI::l10n()->t('Accounts'),
'$content' => $base,
'$accounttype' => ($accounttype ?? ''),
'$all' => DI::l10n()->t('All'),
'$person' => DI::l10n()->t('Persons'),
'$organisation' => DI::l10n()->t('Organisations'),
'$news' => DI::l10n()->t('News'),
'$community' => DI::l10n()->t('Forums'),
]);
}
}

View File

@ -27,6 +27,7 @@ use Friendica\Content\BoundariesPager;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Content\Widget\TrendingTags;
use Friendica\Core\ACL;
use Friendica\Core\Renderer;
@ -87,16 +88,7 @@ class Community extends BaseModule
Nav::setSelected('community');
DI::page()['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_accounts.tpl'), [
'$title' => DI::l10n()->t('Accounts'),
'$content' => self::$content,
'$accounttype' => ($parameters['accounttype'] ?? ''),
'$all' => DI::l10n()->t('All'),
'$person' => DI::l10n()->t('Persons'),
'$organisation' => DI::l10n()->t('Organisations'),
'$news' => DI::l10n()->t('News'),
'$community' => DI::l10n()->t('Forums'),
]);
DI::page()['aside'] .= Widget::accounts('community/' . self::$content, $parameters['accounttype'] ?? '');
if (local_user() && DI::config()->get('system', 'community_no_sharer')) {
$path = self::$content;

View File

@ -54,7 +54,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1369);
define('DB_UPDATE_VERSION', 1370);
}
return [

View File

@ -83,6 +83,7 @@ return [
"unseen" => ["item", "unseen"],
"gravity" => ["item", "gravity"],
"contact-id" => ["item", "contact-id"],
"contact-type" => ["ownercontact", "contact-type"],
],
"query" => "FROM `item`
INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
@ -90,6 +91,7 @@ return [
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id`
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
@ -110,6 +112,7 @@ return [
"mention" => ["thread", "mention"],
"network" => ["thread", "network"],
"contact-id" => ["thread", "contact-id"],
"contact-type" => ["ownercontact", "contact-type"],
],
"query" => "FROM `thread`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
@ -117,6 +120,7 @@ return [
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id`
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)

View File

@ -0,0 +1,18 @@
<span id="sidebar-accounts-inflated" class="widget fakelink" onclick="openCloseWidget('sidebar-accounts', 'sidebar-accounts-inflated');">
<h3>{{$title}}</h3>
</span>
<div id="sidebar-accounts" class="widget">
<span class="fakelink" onclick="openCloseWidget('sidebar-accounts', 'sidebar-accounts-inflated');">
<h3>{{$title}}</h3>
</span>
<ul class="sidebar-accounts-ul">
<li role="menuitem" class="sidebar-accounts-li{{if !$accounttype}} selected{{/if}}"><a href="{{$content}}">{{$all}}</a></li>
<li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'person'}} selected{{/if}}"><a href="{{$content}}/person">{{$person}}</a></li>
<li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'organisation'}} selected{{/if}}"><a href="{{$content}}/organisation">{{$organisation}}</a></li>
<li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'news'}} selected{{/if}}"><a href="{{$content}}/news">{{$news}}</a></li>
<li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'community'}} selected{{/if}}"><a href="{{$content}}/community">{{$community}}</a></li>
</ul>
</div>
<script>
initWidget('sidebar-accounts', 'sidebar-accounts-inflated');
</script>

View File

@ -1,18 +0,0 @@
<span id="sidebar-community-accounts-inflated" class="widget fakelink" onclick="openCloseWidget('sidebar-community-accounts', 'sidebar-community-accounts-inflated');">
<h3>{{$title}}</h3>
</span>
<div id="sidebar-community-accounts" class="widget">
<span class="fakelink" onclick="openCloseWidget('sidebar-community-accounts', 'sidebar-community-accounts-inflated');">
<h3>{{$title}}</h3>
</span>
<ul class="sidebar-community-accounts-ul">
<li role="menuitem" class="sidebar-community-accounts-li{{if !$accounttype}} selected{{/if}}"><a href="community/{{$content}}">{{$all}}</a></li>
<li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'person'}} selected{{/if}}"><a href="community/{{$content}}/person">{{$person}}</a></li>
<li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'organisation'}} selected{{/if}}"><a href="community/{{$content}}/organisation">{{$organisation}}</a></li>
<li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'news'}} selected{{/if}}"><a href="community/{{$content}}/news">{{$news}}</a></li>
<li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'community'}} selected{{/if}}"><a href="community/{{$content}}/community">{{$community}}</a></li>
</ul>
</div>
<script>
initWidget('sidebar-community-accounts', 'sidebar-community-accounts-inflated');
</script>