From 618a3153abfc3bcee4b46d849b72bc532c30cf0c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Mar 2024 21:27:37 +0000 Subject: [PATCH] Issue 13910: Display the unseen counter based on the channel --- doc/Addons.md | 4 -- doc/de/Addons.md | 4 -- src/Module/Conversation/Timeline.php | 7 ++-- src/Module/Notifications/Ping.php | 29 ++----------- src/Module/Ping/Network.php | 61 ++++++++++++++++++++++++++++ static/routes.config.php | 7 ++++ view/js/main.js | 42 ++++++++++++++----- 7 files changed, 107 insertions(+), 47 deletions(-) create mode 100644 src/Module/Ping/Network.php diff --git a/doc/Addons.md b/doc/Addons.md index b89a48d26d..befabfd05a 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -850,10 +850,6 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep- Hook::callAll('register_account', $uid); Hook::callAll('remove_user', $user); -### src/Module/Notifications/Ping.php - - Hook::callAll('network_ping', $arr); - ### src/Module/PermissionTooltip.php Hook::callAll('lockview_content', $item); diff --git a/doc/de/Addons.md b/doc/de/Addons.md index 0843c103ab..607f2d50dc 100644 --- a/doc/de/Addons.md +++ b/doc/de/Addons.md @@ -418,10 +418,6 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap Hook::callAll('storage_instance', $data); Hook::callAll('storage_config', $data); -### src/Module/Notifications/Ping.php - - Hook::callAll('network_ping', $arr); - ### src/Module/PermissionTooltip.php Hook::callAll('lockview_content', $item); diff --git a/src/Module/Conversation/Timeline.php b/src/Module/Conversation/Timeline.php index 88d2f83711..70491e9d2b 100644 --- a/src/Module/Conversation/Timeline.php +++ b/src/Module/Conversation/Timeline.php @@ -235,6 +235,7 @@ class Timeline extends BaseModule protected function getChannelItems(array $request) { $items = $this->getRawChannelItems($request); + $total = min(count($items), $this->itemsPerPage); $contacts = $this->database->selectToArray('user-contact', ['cid'], ['channel-frequency' => Contact\User::FREQUENCY_REDUCED, 'cid' => array_column($items, 'owner-id')]); $reduced = array_column($contacts, 'cid'); @@ -246,8 +247,8 @@ class Timeline extends BaseModule $owner_posts = []; $selected_items = []; - while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) { - $maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor); + while (count($selected_items) < $total && ++$count < 50 && count($items) > 0) { + $maxposts = round((count($items) / $total) * $maxpostperauthor); $minId = $items[array_key_first($items)][$this->order]; $maxId = $items[array_key_last($items)][$this->order]; @@ -279,7 +280,7 @@ class Timeline extends BaseModule $this->maxId = $maxId; } - if (count($selected_items) < $this->itemsPerPage) { + if (count($selected_items) < $total) { $items = $this->getRawChannelItems($request); } } diff --git a/src/Module/Notifications/Ping.php b/src/Module/Notifications/Ping.php index c16e5064f8..d483e3314b 100644 --- a/src/Module/Notifications/Ping.php +++ b/src/Module/Notifications/Ping.php @@ -105,7 +105,6 @@ class Ping extends BaseModule $intro_count = 0; $mail_count = 0; $home_count = 0; - $network_count = 0; $register_count = 0; $sysnotify_count = 0; $circles_unseen = []; @@ -125,34 +124,13 @@ class Ping extends BaseModule } $condition = [ - "`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)", + "`unseen` AND `uid` = ? AND NOT `origin` AND `wall` AND (`vid` != ? OR `vid` IS NULL)", $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`"]); - } + $home_count = Post::count($condition); - $items_unseen = $this->database->toArray(Post::selectForUser( - $this->session->getLocalUserId(), - ['wall', 'uid', 'uri-id'], - $condition, - ['limit' => 1000], - )); - $arr = ['items' => $items_unseen]; - Hook::callAll('network_ping', $arr); - - foreach ($items_unseen as $item) { - if ($item['wall']) { - $home_count++; - } else { - $network_count++; - } - } - - $compute_circle_counts = $this->config->get('system','compute_circle_counts'); - if ($network_count && $compute_circle_counts) { + if ($this->config->get('system','compute_circle_counts')) { // Find out how unseen network posts are spread across circles foreach (Circle::countUnseen($this->session->getLocalUserId()) as $circle_count) { if ($circle_count['count'] > 0) { @@ -281,7 +259,6 @@ class Ping extends BaseModule $data = []; $data['intro'] = $intro_count; $data['mail'] = $mail_count; - $data['net'] = ($network_count < 1000) ? $network_count : '999+'; $data['home'] = ($home_count < 1000) ? $home_count : '999+'; $data['register'] = $register_count; diff --git a/src/Module/Ping/Network.php b/src/Module/Ping/Network.php new file mode 100644 index 0000000000..09ae7b2b44 --- /dev/null +++ b/src/Module/Ping/Network.php @@ -0,0 +1,61 @@ +. + * + */ + +namespace Friendica\Module\Ping; + +use Friendica\Core\System; +use Friendica\Module\Conversation\Network as NetworkModule; + +class Network extends NetworkModule +{ + protected function rawContent(array $request = []) + { + if (!empty($request['ping'])) { + $request = $this->session->get('network-request'); + } + + if (!isset($request['p']) || !isset($request['item'])) { + System::exit(); + } + + $this->parseRequest($request); + + if ($this->force || !is_null($this->maxId)) { + System::httpExit(''); + } + + if (empty($request['ping'])) { + $this->session->set('network-request', $request); + } + + $this->itemsPerPage = 100; + + if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) { + $items = $this->getChannelItems($request); + } elseif ($this->community->isTimeline($this->selectedTab)) { + $items = $this->getCommunityItems(); + } else { + $items = $this->getItems(); + } + $count = count($items); + System::httpExit(($count < 100) ? $count : '99+'); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 93151c433d..559d87fca7 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -674,6 +674,13 @@ return [ '/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]], '/tos' => [Module\Tos::class, [R::GET]], + '/ping_network' => [ + '[/]' => [Module\Ping\Network::class, [R::GET]], + '/archive/{from:\d\d\d\d-\d\d-\d\d}[/{to:\d\d\d\d-\d\d-\d\d}]' => [Module\Ping\Network::class, [R::GET]], + '/group/{contact_id:\d+}' => [Module\Ping\Network::class, [R::GET]], + '/circle/{circle_id:\d+}' => [Module\Ping\Network::class, [R::GET]], + ], + '/update_channel[/{content}]' => [Module\Update\Channel::class, [R::GET]], '/update_community[/{content}]' => [Module\Update\Community::class, [R::GET]], diff --git a/view/js/main.js b/view/js/main.js index 2d684088ac..5363e3df16 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -260,15 +260,9 @@ $(function() { document.title = originalTitle; } - ['net', 'home', 'intro', 'mail', 'events', 'birthdays', 'notification'].forEach(function(type) { + ['home', 'intro', 'mail', 'events', 'birthdays', 'notification'].forEach(function(type) { var number = data[type]; - if (number == 0) { - number = ''; - $('#' + type + '-update').removeClass('show'); - } else { - $('#' + type + '-update').addClass('show'); - } - $('#' + type + '-update').text(number); + updateCounter(type, number); }); var intro = data['intro']; @@ -505,6 +499,14 @@ function NavUpdate() { liveUpdate(src); } }); + + if (!$('#live-network').length) { + var update_url = 'ping_network?ping=1'; + $.get(update_url, function(net) { + updateCounter('net', net); + }); + } + if ($('#live-photos').length) { if (liking) { liking = 0; @@ -586,7 +588,7 @@ function liveUpdate(src) { var udargs = ((netargs.length) ? '/' + netargs : ''); - var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&force=' + (force ? 1 : 0) + '&item=' + update_item; + var update_url = src + udargs + '&p=' + profile_uid + '&force=' + (force ? 1 : 0) + '&item=' + update_item; if (force_update) { force_update = false; @@ -622,7 +624,7 @@ function liveUpdate(src) { update_url += '&first_uriid=' + match[0].innerHTML; } - $.get(update_url, function(data) { + $.get('update_' + update_url, function(data) { in_progress = false; update_item = 0; @@ -639,6 +641,26 @@ function liveUpdate(src) { $(window).scrollTop($(window).scrollTop() + $("section").height() - orgHeight); }); }); + + if (src == 'network') { + $.get('ping_' + update_url, function(net) { + updateCounter('net', net); + }); + } +} + +function updateCounter(type, counter) { + if (counter < 0) { + return; + } + + if (counter == 0) { + counter = ''; + $('#' + type + '-update').removeClass('show'); + } else { + $('#' + type + '-update').addClass('show'); + } + $('#' + type + '-update').text(counter); } function updateItem(itemNo) {