There is now a single way to display group postings

This commit is contained in:
Michael 2024-01-02 20:45:02 +00:00
parent 9592292dba
commit 16d0d17169
5 changed files with 15 additions and 53 deletions

View file

@ -106,14 +106,12 @@ class GroupManager
* Sidebar widget to show subscribed Friendica groups. If activated * Sidebar widget to show subscribed Friendica groups. If activated
* in the settings, it appears in the network page sidebar * in the settings, it appears in the network page sidebar
* *
* @param string $baseurl Base module path * @param int $uid The ID of the User
* @param int $uid The ID of the User
* @param int $cid The contact id which is used to mark a group as "selected"
* @return string * @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function widget(string $baseurl, int $uid, int $cid = 0) public static function widget(int $uid)
{ {
$o = ''; $o = '';
@ -130,14 +128,11 @@ class GroupManager
$entries = []; $entries = [];
foreach ($contacts as $contact) { foreach ($contacts as $contact) {
$selected = (($cid == $contact['id']) ? ' group-selected' : '');
$entry = [ $entry = [
'url' => $baseurl . '/' . $contact['id'], 'url' => 'contact/' . $contact['id'] . '/conversations',
'external_url' => Contact::magicLinkByContact($contact), 'external_url' => Contact::magicLinkByContact($contact),
'name' => $contact['name'], 'name' => $contact['name'],
'cid' => $contact['id'], 'cid' => $contact['id'],
'selected' => $selected,
'micro' => DI::baseUrl()->remove(Contact::getMicro($contact)), 'micro' => DI::baseUrl()->remove(Contact::getMicro($contact)),
'id' => ++$id, 'id' => ++$id,
]; ];

View file

@ -50,25 +50,19 @@ use Friendica\Database\DBA;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Circle; use Friendica\Model\Circle;
use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\Verb;
use Friendica\Module\Contact as ModuleContact;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Navigation\SystemMessages; use Friendica\Navigation\SystemMessages;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Friendica\Protocol\Activity;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class Network extends Timeline class Network extends Timeline
{ {
/** @var int */ /** @var int */
protected $circleId; protected $circleId;
/** @var int */
protected $groupContactId;
/** @var string */ /** @var string */
protected $network; protected $network;
/** @var string */ /** @var string */
@ -140,9 +134,9 @@ class Network extends Timeline
$o = ''; $o = '';
$this->page['aside'] .= Circle::sidebarWidget($module, $module . '/circle', 'standard', $this->circleId); $this->page['aside'] .= Circle::sidebarWidget($module, $module . '/circle', 'standard', $this->circleId);
$this->page['aside'] .= GroupManager::widget($module . '/group', $this->session->getLocalUserId(), $this->groupContactId); $this->page['aside'] .= GroupManager::widget($this->session->getLocalUserId());
$this->page['aside'] .= Widget::postedByYear($module . '/archive', $this->session->getLocalUserId(), false); $this->page['aside'] .= Widget::postedByYear($module . '/archive', $this->session->getLocalUserId(), false);
$this->page['aside'] .= Widget::networks($module, !$this->groupContactId ? $this->network : ''); $this->page['aside'] .= Widget::networks($module, $this->network);
$this->page['aside'] .= Widget::accountTypes($module, $this->accountTypeString); $this->page['aside'] .= Widget::accountTypes($module, $this->accountTypeString);
$this->page['aside'] .= Widget::channels($module, $this->selectedTab, $this->session->getLocalUserId()); $this->page['aside'] .= Widget::channels($module, $this->selectedTab, $this->session->getLocalUserId());
$this->page['aside'] .= Widget\SavedSearches::getHTML($this->args->getQueryString()); $this->page['aside'] .= Widget\SavedSearches::getHTML($this->args->getQueryString());
@ -164,24 +158,13 @@ class Network extends Timeline
$content = ''; $content = '';
if ($this->groupContactId) {
// If $this->groupContactId belongs to a community group or a private group, add a mention to the status editor
$condition = ["`id` = ? AND `contact-type` = ?", $this->groupContactId, Contact::TYPE_COMMUNITY];
$contact = $this->database->selectFirst('contact', ['addr'], $condition);
if (!empty($contact['addr'])) {
$content = '!' . $contact['addr'];
}
}
$default_permissions = []; $default_permissions = [];
if ($this->circleId) { if ($this->circleId) {
$default_permissions['allow_gid'] = [$this->circleId]; $default_permissions['allow_gid'] = [$this->circleId];
} }
$allowedCids = []; $allowedCids = [];
if ($this->groupContactId) { if ($this->network) {
$allowedCids[] = (int) $this->groupContactId;
} elseif ($this->network) {
$condition = [ $condition = [
'uid' => $this->session->getLocalUserId(), 'uid' => $this->session->getLocalUserId(),
'network' => $this->network, 'network' => $this->network,
@ -203,9 +186,9 @@ class Network extends Timeline
} }
$x = [ $x = [
'lockstate' => $this->circleId || $this->groupContactId || $this->network || ACL::getLockstateForUserId($this->session->getLocalUserId()) ? 'lock' : 'unlock', 'lockstate' => $this->circleId || $this->network || ACL::getLockstateForUserId($this->session->getLocalUserId()) ? 'lock' : 'unlock',
'acl' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), true, $default_permissions), 'acl' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), true, $default_permissions),
'bang' => (($this->circleId || $this->groupContactId || $this->network) ? '!' : ''), 'bang' => (($this->circleId || $this->network) ? '!' : ''),
'content' => $content, 'content' => $content,
]; ];
@ -220,16 +203,6 @@ class Network extends Timeline
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [ $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
'$title' => $this->l10n->t('Circle: %s', $circle['name']) '$title' => $this->l10n->t('Circle: %s', $circle['name'])
]) . $o; ]) . $o;
} elseif ($this->groupContactId) {
$contact = Contact::getById($this->groupContactId);
if ($this->database->isResult($contact)) {
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('contact/list.tpl'), [
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
'id' => $this->args->get(0),
]) . $o;
} else {
$this->systemMessages->addNotice($this->l10n->t('Invalid contact.'));
}
} elseif (Profile::shouldDisplayEventList($this->session->getLocalUserId(), $this->mode)) { } elseif (Profile::shouldDisplayEventList($this->session->getLocalUserId(), $this->mode)) {
$o .= Profile::getBirthdays($this->session->getLocalUserId()); $o .= Profile::getBirthdays($this->session->getLocalUserId());
$o .= Profile::getEventsReminderHTML($this->session->getLocalUserId(), $this->session->getPublicContactId()); $o .= Profile::getEventsReminderHTML($this->session->getLocalUserId(), $this->session->getPublicContactId());
@ -321,15 +294,13 @@ class Network extends Timeline
$this->circleId = (int)($this->parameters['circle_id'] ?? 0); $this->circleId = (int)($this->parameters['circle_id'] ?? 0);
$this->groupContactId = (int)($this->parameters['contact_id'] ?? 0);
if (!$this->selectedTab) { if (!$this->selectedTab) {
$this->selectedTab = self::getTimelineOrderBySession($this->session, $this->pConfig); $this->selectedTab = self::getTimelineOrderBySession($this->session, $this->pConfig);
} elseif (!$this->networkFactory->isTimeline($this->selectedTab) && !$this->channel->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) { } elseif (!$this->networkFactory->isTimeline($this->selectedTab) && !$this->channel->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.')); throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.'));
} }
if (($this->network || $this->circleId || $this->groupContactId) && ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) || $this->community->isTimeline($this->selectedTab))) { if (($this->network || $this->circleId) && ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) || $this->community->isTimeline($this->selectedTab))) {
$this->selectedTab = NetworkEntity::RECEIVED; $this->selectedTab = NetworkEntity::RECEIVED;
} }
@ -433,10 +404,6 @@ class Network extends Timeline
if ($this->circleId) { if ($this->circleId) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $this->circleId]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $this->circleId]);
} elseif ($this->groupContactId) {
$conditionStrings = DBA::mergeConditions($conditionStrings,
["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `verb` = ? AND `uid` = ?)))",
$this->groupContactId, $this->groupContactId, Item::GRAVITY_ACTIVITY, Activity::ANNOUNCE, $this->session->getLocalUserId()]);
} }
// Currently only the order modes "received" and "commented" are in use // Currently only the order modes "received" and "commented" are in use
@ -505,7 +472,7 @@ class Network extends Timeline
// We aren't going to try and figure out at the item, circle, and page // We aren't going to try and figure out at the item, circle, and page
// level which items you've seen and which you haven't. If you're looking // level which items you've seen and which you haven't. If you're looking
// at the top level network page just mark everything seen. // at the top level network page just mark everything seen.
if (!$this->circleId && !$this->groupContactId && !$this->star && !$this->mention) { if (!$this->circleId && !$this->star && !$this->mention) {
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId()]; $condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId()];
$this->setItemsSeenByCondition($condition); $this->setItemsSeenByCondition($condition);
} elseif (!empty($parents)) { } elseif (!empty($parents)) {

View file

@ -34,7 +34,7 @@ function showHideGroupList() {
<a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer"> <a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer">
<img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" /> <img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" />
</a> </a>
<a class="group-widget-link {{if $group.selected}}group-selected{{/if}}" id="group-widget-link-{{$group.id}}" href="{{$group.url}}">{{$group.name}}</a> <a class="group-widget-link" id="group-widget-link-{{$group.id}}" href="{{$group.url}}">{{$group.name}}</a>
</li> </li>
{{/if}} {{/if}}
@ -44,7 +44,7 @@ function showHideGroupList() {
<a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer"> <a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer">
<img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" /> <img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" />
</a> </a>
<a class="group-widget-link {{if $group.selected}}group-selected{{/if}}" id="group-widget-link-{{$group.id}}" href="{{$group.url}}">{{$group.name}}</a> <a class="group-widget-link" id="group-widget-link-{{$group.id}}" href="{{$group.url}}">{{$group.name}}</a>
</li> </li>
{{/if}} {{/if}}
{{/foreach}} {{/foreach}}

View file

@ -19,7 +19,7 @@ function showHideGroupList() {
<ul id="group-list-sidebar-ul" role="menu"> <ul id="group-list-sidebar-ul" role="menu">
{{foreach $groups as $group}} {{foreach $groups as $group}}
{{if $group.id <= $visible_groups}} {{if $group.id <= $visible_groups}}
<li class="group-widget-entry group-{{$group.cid}} tool {{if $group.selected}}selected{{/if}}" id="group-widget-entry-{{$group.id}}" role="menuitem"> <li class="group-widget-entry group-{{$group.cid}} tool" id="group-widget-entry-{{$group.id}}" role="menuitem">
<span class="notify badge pull-right"></span> <span class="notify badge pull-right"></span>
<a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer"> <a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer">
<img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" /> <img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" />
@ -29,7 +29,7 @@ function showHideGroupList() {
{{/if}} {{/if}}
{{if $group.id > $visible_groups}} {{if $group.id > $visible_groups}}
<li class="group-widget-entry group-{{$group.cid}} tool {{if $group.selected}}selected{{/if}}" id="group-widget-entry-extended-{{$group.id}}" role="menuitem" style="display: none;"> <li class="group-widget-entry group-{{$group.cid}} tool" id="group-widget-entry-extended-{{$group.id}}" role="menuitem" style="display: none;">
<span class="notify badge pull-right"></span> <span class="notify badge pull-right"></span>
<a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer"> <a href="{{$group.external_url}}" title="{{$group.link_desc}}" class="label sparkle" target="_blank" rel="noopener noreferrer">
<img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" /> <img class="group-list-img" src="{{$group.micro}}" alt="{{$group.link_desc}}" />

View file

@ -208,7 +208,7 @@ function vier_community_info()
//Community_Pages at right_aside //Community_Pages at right_aside
if ($show_pages && DI::userSession()->getLocalUserId()) { if ($show_pages && DI::userSession()->getLocalUserId()) {
$aside['$page'] = GroupManager::widget('network/group', DI::userSession()->getLocalUserId());; $aside['$page'] = GroupManager::widget(DI::userSession()->getLocalUserId());
} }
// END Community Page // END Community Page