<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Contact\Introduction\Repository\Introduction;
-use Friendica\Content\ForumManager;
+use Friendica\Content\GroupManager;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Database\DBA;
-use Friendica\Model\Group;
+use Friendica\Model\Circle;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Model\Verb;
use Friendica\Navigation\Notifications\Repository;
use Friendica\Navigation\Notifications\ValueObject;
use Friendica\Navigation\SystemMessages;
+use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
+use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
use Psr\Log\LoggerInterface;
$network_count = 0;
$register_count = 0;
$sysnotify_count = 0;
+ $circles_unseen = [];
$groups_unseen = [];
- $forums_unseen = [];
$event_count = 0;
$today_event_count = 0;
$birthday_count = 0;
$today_birthday_count = 0;
-
- if ($this->session->getLocalUserId()) {
+ // Suppress notification display for group accounts
+ if ($this->session->getLocalUserId() && $this->session->get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {
if ($this->pconfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
$notifications = $this->notificationRepo->selectDetailedForUser($this->session->getLocalUserId());
} else {
$this->session->getLocalUserId(), Verb::getID(Activity::FOLLOW)
];
+ // No point showing counts for non-top-level posts when the network page is ordered by received field
+ if (Network::getTimelineOrderBySession($this->session, $this->pconfig) == 'received') {
+ $condition = DBA::mergeConditions($condition, ["`parent` = `id`"]);
+ }
+
$items_unseen = $this->database->toArray(Post::selectForUser(
$this->session->getLocalUserId(),
['wall', 'uid', 'uri-id'],
}
}
- $compute_group_counts = $this->config->get('system','compute_group_counts');
- if ($network_count && $compute_group_counts) {
- // Find out how unseen network posts are spread across groups
- foreach (Group::countUnseen() as $group_count) {
- if ($group_count['count'] > 0) {
- $groups_unseen[] = $group_count;
+ $compute_circle_counts = $this->config->get('system','compute_group_counts') ?? $this->config->get('system','compute_circle_counts');
+ if ($network_count && $compute_circle_counts) {
+ // Find out how unseen network posts are spread across circles
+ foreach (Circle::countUnseen() as $circle_count) {
+ if ($circle_count['count'] > 0) {
+ $circles_unseen[] = $circle_count;
}
}
- foreach (ForumManager::countUnseenItems() as $forum_count) {
- if ($forum_count['count'] > 0) {
- $forums_unseen[] = $forum_count;
+ foreach (GroupManager::countUnseenItems() as $group_count) {
+ if ($group_count['count'] > 0) {
+ $groups_unseen[] = $group_count;
}
}
}
$myurl = $this->session->getMyUrl();
$mail_count = $this->database->count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", $this->session->getLocalUserId(), $myurl]);
- if (intval($this->config->get('config', 'register_policy')) === Register::APPROVE && $this->app->isSiteAdmin()) {
+ if (intval($this->config->get('config', 'register_policy')) === Register::APPROVE && $this->session->isSiteAdmin()) {
$registrations = \Friendica\Model\Register::getPending();
$register_count = count($registrations);
}
// merge all notification types in one array
foreach ($intros as $intro) {
- $navNotifications[] = $this->formattedNavNotification->createFromIntro($intro);
+ try {
+ $navNotifications[] = $this->formattedNavNotification->createFromIntro($intro);
+ } catch (HTTPException\NotFoundException $e) {
+ $this->introductionRepo->delete($intro);
+ }
}
if (count($registrations) <= 1 || $this->pconfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
- foreach ($registrations as $reg) {
+ foreach ($registrations as $registration) {
$navNotifications[] = $this->formattedNavNotification->createFromParams(
- [
- 'name' => $reg['name'],
- 'url' => $reg['url'],
- ],
+ $registration['name'],
+ $registration['url'],
$this->l10n->t('{0} requested registration'),
- new \DateTime($reg['created'], new \DateTimeZone('UTC')),
- new Uri($this->baseUrl->get(true) . '/admin/users/pending')
+ new \DateTime($registration['created'], new \DateTimeZone('UTC')),
+ new Uri($this->baseUrl . '/moderation/users/pending')
);
}
- } elseif (count($registrations) > 1) {
+ } else {
$navNotifications[] = $this->formattedNavNotification->createFromParams(
- [
- 'name' => $registrations[0]['name'],
- 'url' => $registrations[0]['url'],
- ],
+ $registrations[0]['name'],
+ $registrations[0]['url'],
$this->l10n->t('{0} and %d others requested registration', count($registrations) - 1),
new \DateTime($registrations[0]['created'], new \DateTimeZone('UTC')),
- new Uri($this->baseUrl->get(true) . '/admin/users/pending')
+ new Uri($this->baseUrl . '/moderation/users/pending')
);
}
$data['events-today'] = $today_event_count;
$data['birthdays'] = $birthday_count;
$data['birthdays-today'] = $today_birthday_count;
+ $data['circles'] = $circles_unseen;
$data['groups'] = $groups_unseen;
- $data['forums'] = $forums_unseen;
$data['notification'] = ($notification_count < 50) ? $notification_count : '49+';
$data['notifications'] = $navNotifications;
$data['sysmsgs'] = [
- 'notice' => $this->systemMessages->flushNotices(),
- 'info' => $this->systemMessages->flushInfos(),
+ 'notice' => array_map([Strings::class, 'escapeHtml'], $this->systemMessages->flushNotices()),
+ 'info' => array_map([Strings::class, 'escapeHtml'], $this->systemMessages->flushInfos()),
];
if (isset($_GET['callback'])) {