Merge pull request #9367 from annando/issue-9366

Issue 9366: filter account types on the network page
This commit is contained in:
Tobias Diekershoff 2020-10-05 20:03:04 +02:00 committed by GitHub
commit 53155f7357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 36 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2020.12-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1369
-- DB_UPDATE_VERSION 1370
-- ------------------------------------------
@ -1449,13 +1449,15 @@ CREATE VIEW `network-item-view` AS SELECT
`item`.`network` AS `network`,
`item`.`unseen` AS `unseen`,
`item`.`gravity` AS `gravity`,
`item`.`contact-id` AS `contact-id`
`item`.`contact-id` AS `contact-id`,
`ownercontact`.`contact-type` AS `contact-type`
FROM `item`
INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
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`)
@ -1478,13 +1480,15 @@ CREATE VIEW `network-thread-view` AS SELECT
`thread`.`starred` AS `starred`,
`thread`.`mention` AS `mention`,
`thread`.`network` AS `network`,
`thread`.`contact-id` AS `contact-id`
`thread`.`contact-id` AS `contact-id`,
`ownercontact`.`contact-type` AS `contact-type`
FROM `thread`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
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

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