]> git.mxchange.org Git - friendica.git/commitdiff
Issue 13910: Display the unseen counter based on the channel
authorMichael <heluecht@pirati.ca>
Sun, 17 Mar 2024 21:27:37 +0000 (21:27 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 23 Mar 2024 17:17:56 +0000 (17:17 +0000)
doc/Addons.md
doc/de/Addons.md
src/Module/Conversation/Timeline.php
src/Module/Notifications/Ping.php
src/Module/Ping/Network.php [new file with mode: 0644]
static/routes.config.php
view/js/main.js

index b89a48d26d328ebf017808356f7335621b7f0de5..befabfd05a35e5bc16e9c1b319aa3014efda9405 100644 (file)
@@ -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);
index 0843c103abd2ee1e00d7372f076396b4b90de7fb..607f2d50dc534810cd5bd020f08352ffb396db45 100644 (file)
@@ -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);
index 88d2f83711bc355d075fb23ce078963bf41fc450..70491e9d2bec7bfd7bf4798d9a1bebeb5729878c 100644 (file)
@@ -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);
                                }
                        }
index c16e5064f88c6710e72e1966bfead345e2c56405..d483e3314bd8c0a4a94e2e851fa04718ce744d3a 100644 (file)
@@ -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`"]);
-                       }
-
-                       $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++;
-                               }
-                       }
+                       $home_count = Post::count($condition);
 
-                       $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 (file)
index 0000000..09ae7b2
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2024, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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+');
+       }
+}
index 93151c433da809c31d31b86e47b603bf0e48d7b2..559d87fca77edd1907f58e87c281ad67a1e3c502 100644 (file)
@@ -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]],
 
index 2d684088ac9686d1f7578f2d94661e4cb3a52c5b..5363e3df1672c627969c0663a4dc71d8e53e770d 100644 (file)
@@ -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) {