Issue 13910: Display the unseen counter based on the channel

This commit is contained in:
Michael 2024-03-17 21:27:37 +00:00
parent 0ccb3e7efe
commit 618a3153ab
7 changed files with 107 additions and 47 deletions

View 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('register_account', $uid);
Hook::callAll('remove_user', $user); Hook::callAll('remove_user', $user);
### src/Module/Notifications/Ping.php
Hook::callAll('network_ping', $arr);
### src/Module/PermissionTooltip.php ### src/Module/PermissionTooltip.php
Hook::callAll('lockview_content', $item); Hook::callAll('lockview_content', $item);

View 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_instance', $data);
Hook::callAll('storage_config', $data); Hook::callAll('storage_config', $data);
### src/Module/Notifications/Ping.php
Hook::callAll('network_ping', $arr);
### src/Module/PermissionTooltip.php ### src/Module/PermissionTooltip.php
Hook::callAll('lockview_content', $item); Hook::callAll('lockview_content', $item);

View file

@ -235,6 +235,7 @@ class Timeline extends BaseModule
protected function getChannelItems(array $request) protected function getChannelItems(array $request)
{ {
$items = $this->getRawChannelItems($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')]); $contacts = $this->database->selectToArray('user-contact', ['cid'], ['channel-frequency' => Contact\User::FREQUENCY_REDUCED, 'cid' => array_column($items, 'owner-id')]);
$reduced = array_column($contacts, 'cid'); $reduced = array_column($contacts, 'cid');
@ -246,8 +247,8 @@ class Timeline extends BaseModule
$owner_posts = []; $owner_posts = [];
$selected_items = []; $selected_items = [];
while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) { while (count($selected_items) < $total && ++$count < 50 && count($items) > 0) {
$maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor); $maxposts = round((count($items) / $total) * $maxpostperauthor);
$minId = $items[array_key_first($items)][$this->order]; $minId = $items[array_key_first($items)][$this->order];
$maxId = $items[array_key_last($items)][$this->order]; $maxId = $items[array_key_last($items)][$this->order];
@ -279,7 +280,7 @@ class Timeline extends BaseModule
$this->maxId = $maxId; $this->maxId = $maxId;
} }
if (count($selected_items) < $this->itemsPerPage) { if (count($selected_items) < $total) {
$items = $this->getRawChannelItems($request); $items = $this->getRawChannelItems($request);
} }
} }

View file

@ -105,7 +105,6 @@ class Ping extends BaseModule
$intro_count = 0; $intro_count = 0;
$mail_count = 0; $mail_count = 0;
$home_count = 0; $home_count = 0;
$network_count = 0;
$register_count = 0; $register_count = 0;
$sysnotify_count = 0; $sysnotify_count = 0;
$circles_unseen = []; $circles_unseen = [];
@ -125,34 +124,13 @@ class Ping extends BaseModule
} }
$condition = [ $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) $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 $home_count = Post::count($condition);
if (Network::getTimelineOrderBySession($this->session, $this->pconfig) == 'received') {
$condition = DBA::mergeConditions($condition, ["`parent` = `id`"]);
}
$items_unseen = $this->database->toArray(Post::selectForUser( if ($this->config->get('system','compute_circle_counts')) {
$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) {
// Find out how unseen network posts are spread across circles // Find out how unseen network posts are spread across circles
foreach (Circle::countUnseen($this->session->getLocalUserId()) as $circle_count) { foreach (Circle::countUnseen($this->session->getLocalUserId()) as $circle_count) {
if ($circle_count['count'] > 0) { if ($circle_count['count'] > 0) {
@ -281,7 +259,6 @@ class Ping extends BaseModule
$data = []; $data = [];
$data['intro'] = $intro_count; $data['intro'] = $intro_count;
$data['mail'] = $mail_count; $data['mail'] = $mail_count;
$data['net'] = ($network_count < 1000) ? $network_count : '999+';
$data['home'] = ($home_count < 1000) ? $home_count : '999+'; $data['home'] = ($home_count < 1000) ? $home_count : '999+';
$data['register'] = $register_count; $data['register'] = $register_count;

View file

@ -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+');
}
}

View file

@ -674,6 +674,13 @@ return [
'/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]], '/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]],
'/tos' => [Module\Tos::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_channel[/{content}]' => [Module\Update\Channel::class, [R::GET]],
'/update_community[/{content}]' => [Module\Update\Community::class, [R::GET]], '/update_community[/{content}]' => [Module\Update\Community::class, [R::GET]],

View file

@ -260,15 +260,9 @@ $(function() {
document.title = originalTitle; 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]; var number = data[type];
if (number == 0) { updateCounter(type, number);
number = '';
$('#' + type + '-update').removeClass('show');
} else {
$('#' + type + '-update').addClass('show');
}
$('#' + type + '-update').text(number);
}); });
var intro = data['intro']; var intro = data['intro'];
@ -505,6 +499,14 @@ function NavUpdate() {
liveUpdate(src); 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 ($('#live-photos').length) {
if (liking) { if (liking) {
liking = 0; liking = 0;
@ -586,7 +588,7 @@ function liveUpdate(src) {
var udargs = ((netargs.length) ? '/' + netargs : ''); 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) { if (force_update) {
force_update = false; force_update = false;
@ -622,7 +624,7 @@ function liveUpdate(src) {
update_url += '&first_uriid=' + match[0].innerHTML; update_url += '&first_uriid=' + match[0].innerHTML;
} }
$.get(update_url, function(data) { $.get('update_' + update_url, function(data) {
in_progress = false; in_progress = false;
update_item = 0; update_item = 0;
@ -639,6 +641,26 @@ function liveUpdate(src) {
$(window).scrollTop($(window).scrollTop() + $("section").height() - orgHeight); $(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) { function updateItem(itemNo) {