3 * @copyright Copyright (C) 2010-2024, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Conversation;
25 use Friendica\App\Mode;
26 use Friendica\BaseModule;
27 use Friendica\Content\Conversation\Collection\Timelines;
28 use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
29 use Friendica\Content\Conversation\Repository\UserDefinedChannel;
30 use Friendica\Core\Cache\Capability\ICanCache;
31 use Friendica\Core\Cache\Enum\Duration;
32 use Friendica\Core\Config\Capability\IManageConfigValues;
33 use Friendica\Core\L10n;
34 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
35 use Friendica\Core\Renderer;
36 use Friendica\Core\Session\Capability\IHandleUserSessions;
37 use Friendica\Model\Contact;
38 use Friendica\Model\User;
39 use Friendica\Database\Database;
40 use Friendica\Database\DBA;
41 use Friendica\Model\Item;
42 use Friendica\Model\Post;
43 use Friendica\Model\Post\Engagement;
44 use Friendica\Model\Verb;
45 use Friendica\Module\Response;
46 use Friendica\Protocol\Activity;
47 use Friendica\Util\DateTimeFormat;
48 use Friendica\Util\Profiler;
49 use Psr\Log\LoggerInterface;
51 class Timeline extends BaseModule
54 protected $selectedTab;
60 protected $accountTypeString;
62 protected $accountType;
66 protected $itemsPerPage;
76 /** @var App\Mode $mode */
78 /** @var IHandleUserSessions */
82 /** @var IManagePersonalConfigValues */
84 /** @var IManageConfigValues The config */
88 /** @var UserDefinedChannel */
89 protected $channelRepository;
91 public function __construct(UserDefinedChannel $channel, Mode $mode, IHandleUserSessions $session, Database $database, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, ICanCache $cache, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
93 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
95 $this->channelRepository = $channel;
97 $this->session = $session;
98 $this->database = $database;
99 $this->pConfig = $pConfig;
100 $this->config = $config;
101 $this->cache = $cache;
105 * Computes module parameters from the request and local configuration
107 * @throws HTTPException\BadRequestException
108 * @throws HTTPException\ForbiddenException
110 protected function parseRequest(array $request)
112 $this->logger->debug('Got request', $request);
113 $this->selectedTab = $this->parameters['content'] ?? $request['channel'] ?? '';
115 $this->accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? '';
116 $this->accountType = User::getAccountTypeByString($this->accountTypeString);
118 if ($this->mode->isMobile()) {
119 $this->itemsPerPage = $this->pConfig->get(
120 $this->session->getLocalUserId(),
122 'itemspage_mobile_network',
123 $this->config->get('system', 'itemspage_network_mobile')
126 $this->itemsPerPage = $this->pConfig->get(
127 $this->session->getLocalUserId(),
130 $this->config->get('system', 'itemspage_network')
134 if (!empty($request['item'])) {
135 $item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]);
136 $this->itemUriId = $item['parent-uri-id'] ?? 0;
138 $this->itemUriId = 0;
141 $this->minId = $request['min_id'] ?? null;
142 $this->maxId = $request['max_id'] ?? null;
144 $this->noSharer = !empty($request['no_sharer']);
145 $this->force = !empty($request['force']) && !empty($request['item']);
146 $this->update = !empty($request['force']) && !empty($request['first_received']) && !empty($request['first_created']) && !empty($request['first_uriid']) && !empty($request['first_commented']);
147 $this->raw = !empty($request['mode']) && ($request['mode'] == 'raw');
150 protected function getNoSharerWidget(string $base): string
152 $path = $this->selectedTab;
153 if (!empty($this->accountTypeString)) {
154 $path .= '/' . $this->accountTypeString;
156 $query_parameters = [];
158 if (!empty($this->minId)) {
159 $query_parameters['min_id'] = $this->minId;
161 if (!empty($this->maxId)) {
162 $query_parameters['max_id'] = $this->maxId;
165 $path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
166 $path_no_sharer = $path . '?' . http_build_query(array_merge($query_parameters, ['no_sharer' => true]));
167 return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_sharer.tpl'), [
168 '$title' => $this->l10n->t('Own Contacts'),
169 '$path_all' => $path_all,
170 '$path_no_sharer' => $path_no_sharer,
171 '$no_sharer' => $this->noSharer,
172 '$all' => $this->l10n->t('Include'),
173 '$no_sharer_label' => $this->l10n->t('Hide'),
178 protected function getTabArray(Timelines $timelines, string $prefix, string $parameter = ''): array
182 foreach ($timelines as $tab) {
183 if (is_null($tab->path) && !empty($parameter)) {
184 $path = $prefix . '?' . http_build_query([$parameter => $tab->code]);
186 $path = $tab->path ?? $prefix . '/' . $tab->code;
188 $tabs[$tab->code] = [
189 'code' => $tab->code,
190 'label' => $tab->label,
192 'sel' => $this->selectedTab == $tab->code ? 'active' : '',
193 'title' => $tab->description,
194 'id' => $prefix . '-' . $tab->code . '-tab',
195 'accesskey' => $tab->accessKey,
202 * Database query for the channel page
207 protected function getChannelItems()
209 $items = $this->getRawChannelItems();
211 $contacts = $this->database->selectToArray('user-contact', ['cid'], ['channel-frequency' => Contact\User::FREQUENCY_REDUCED, 'cid' => array_column($items, 'owner-id')]);
212 $reduced = array_column($contacts, 'cid');
214 $maxpostperauthor = $this->config->get('channel', 'max_posts_per_author');
216 if ($maxpostperauthor != 0) {
219 $selected_items = [];
221 while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
222 $maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
223 $minId = $items[array_key_first($items)]['created'];
224 $maxId = $items[array_key_last($items)]['created'];
226 foreach ($items as $item) {
227 if (!in_array($item['owner-id'], $reduced)) {
230 $owner_posts[$item['owner-id']][$item['uri-id']] = (($item['comments'] * 100) + $item['activities']);
232 foreach ($owner_posts as $posts) {
233 if (count($posts) <= $maxposts) {
237 while (count($posts) > $maxposts) {
238 $uri_id = array_key_first($posts);
239 unset($posts[$uri_id]);
240 unset($items[$uri_id]);
243 $selected_items = array_merge($selected_items, $items);
245 // If we're looking at a "previous page", the lookup continues forward in time because the list is
246 // sorted in chronologically decreasing order
247 if (!empty($this->minId)) {
248 $this->minId = $minId;
250 // In any other case, the lookup continues backwards in time
251 $this->maxId = $maxId;
254 if (count($selected_items) < $this->itemsPerPage) {
255 $items = $this->getRawChannelItems();
259 $selected_items = $items;
262 $condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
263 $this->setItemsSeenByCondition($condition);
265 return $selected_items;
269 * Database query for the channel page
274 private function getRawChannelItems()
276 $uid = $this->session->getLocalUserId();
278 if ($this->selectedTab == ChannelEntity::WHATSHOT) {
279 if (!is_null($this->accountType)) {
280 $condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $this->accountType];
282 $condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` != ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), Contact::TYPE_COMMUNITY];
284 } elseif ($this->selectedTab == ChannelEntity::FORYOU) {
285 $cid = Contact::getPublicIdByUserId($uid);
288 "(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?) OR
289 ((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?)) OR
290 (`owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`notify_new_posts` OR `channel-frequency` = ?))))",
291 $cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid,
292 $uid, Contact\User::FREQUENCY_ALWAYS
294 } elseif ($this->selectedTab == ChannelEntity::FOLLOWERS) {
295 $condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER];
296 } elseif ($this->selectedTab == ChannelEntity::SHARERSOFSHARERS) {
297 $cid = Contact::getPublicIdByUserId($uid);
299 // @todo Suggest posts from contacts that are followed most by our followers
301 "`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `last-interaction` > ?
302 AND `relation-cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ? AND `relation-thread-score` >= ?)
303 AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))",
304 DateTimeFormat::utc('now - ' . $this->config->get('channel', 'sharer_interaction_days') . ' day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid
306 } elseif ($this->selectedTab == ChannelEntity::IMAGE) {
307 $condition = ["`media-type` & ?", 1];
308 } elseif ($this->selectedTab == ChannelEntity::VIDEO) {
309 $condition = ["`media-type` & ?", 2];
310 } elseif ($this->selectedTab == ChannelEntity::AUDIO) {
311 $condition = ["`media-type` & ?", 4];
312 } elseif ($this->selectedTab == ChannelEntity::LANGUAGE) {
313 $condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", User::getLanguageCode($uid)];
314 } elseif (is_numeric($this->selectedTab)) {
315 $condition = $this->getUserChannelConditions($this->selectedTab, $uid);
318 if (($this->selectedTab != ChannelEntity::LANGUAGE) && !is_numeric($this->selectedTab)) {
319 $condition = $this->addLanguageCondition($uid, $condition);
322 $condition = DBA::mergeConditions($condition, ["(NOT `restricted` OR EXISTS(SELECT `id` FROM `post-user` WHERE `uid` = ? AND `uri-id` = `post-engagement`.`uri-id`))", $uid]);
324 $condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed` OR `is-blocked` OR `channel-frequency` = ?))", $uid, Contact\User::FREQUENCY_NEVER]);
326 if (($this->selectedTab != ChannelEntity::WHATSHOT) && !is_null($this->accountType)) {
327 $condition = DBA::mergeConditions($condition, ['contact-type' => $this->accountType]);
330 $params = ['order' => ['created' => true], 'limit' => $this->itemsPerPage];
332 if (!empty($this->itemUriId)) {
333 $condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
335 if ($this->noSharer) {
336 $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]);
339 if (isset($this->maxId)) {
340 $condition = DBA::mergeConditions($condition, ["`created` < ?", $this->maxId]);
343 if (isset($this->minId)) {
344 $condition = DBA::mergeConditions($condition, ["`created` > ?", $this->minId]);
346 // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
347 if (!isset($this->maxId)) {
348 $params['order']['created'] = false;
354 $result = $this->database->select('post-engagement', ['uri-id', 'created', 'owner-id', 'comments', 'activities'], $condition, $params);
355 if ($this->database->errorNo()) {
356 throw new \Exception($this->database->errorMessage(), $this->database->errorNo());
359 while ($item = $this->database->fetch($result)) {
360 $items[$item['uri-id']] = $item;
362 $this->database->close($result);
368 // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
369 if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
370 $items = array_reverse($items, true);
373 $condition = ['unseen' => true, 'uid' => $uid, 'parent-uri-id' => array_column($items, 'uri-id')];
374 $this->setItemsSeenByCondition($condition);
379 private function getUserChannelConditions(int $id, int $uid): array
381 $channel = $this->channelRepository->selectById($id, $uid);
382 if (empty($channel)) {
388 if (!empty($channel->circle)) {
389 if ($channel->circle == -1) {
390 $condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))", $uid, Contact::SHARING, Contact::FRIEND];
391 } elseif ($channel->circle == -2) {
392 $condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER];
393 } elseif ($channel->circle == -3) {
394 $condition = ["EXISTS(SELECT `uri-id` FROM `post-thread-user` WHERE `uid` = ? AND `post-thread-user`.`uri-id` = `post-engagement`.`uri-id`)", $uid];
395 } elseif ($channel->circle > 0) {
396 $condition = DBA::mergeConditions($condition, ["`owner-id` IN (SELECT `pid` FROM `group_member` INNER JOIN `account-user-view` ON `group_member`.`contact-id` = `account-user-view`.`id` WHERE `gid` = ? AND `account-user-view`.`uid` = ?)", $channel->circle, $uid]);
400 if (!empty($channel->fullTextSearch)) {
401 $search = $channel->fullTextSearch;
402 foreach (Engagement::KEYWORDS as $keyword) {
403 $search = preg_replace('~(' . $keyword . ':.[\w@\.-]+)~', '"$1"', $search);
405 $condition = DBA::mergeConditions($condition, ["MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", $search]);
408 if (!empty($channel->includeTags)) {
409 $search = explode(',', mb_strtolower($channel->includeTags));
410 $placeholders = substr(str_repeat("?, ", count($search)), 0, -2);
411 $condition = DBA::mergeConditions($condition, array_merge(["`uri-id` IN (SELECT `uri-id` FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` WHERE `post-tag`.`type` = 1 AND `name` IN (" . $placeholders . "))"], $search));
414 if (!empty($channel->excludeTags)) {
415 $search = explode(',', mb_strtolower($channel->excludeTags));
416 $placeholders = substr(str_repeat("?, ", count($search)), 0, -2);
417 $condition = DBA::mergeConditions($condition, array_merge(["NOT `uri-id` IN (SELECT `uri-id` FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` WHERE `post-tag`.`type` = 1 AND `name` IN (" . $placeholders . "))"], $search));
420 if (!empty($channel->mediaType)) {
421 $condition = DBA::mergeConditions($condition, ["`media-type` & ?", $channel->mediaType]);
424 // For "addLanguageCondition" to work, the condition must not be empty
425 $condition = $this->addLanguageCondition($uid, $condition ?: ["true"], $channel->languages);
430 private function addLanguageCondition(int $uid, array $condition, $languages = null): array
433 $languages = $languages ?: User::getWantedLanguages($uid);
434 foreach ($languages as $language) {
435 $conditions[] = "JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?";
436 $condition[] = $language;
438 if (!empty($conditions)) {
439 $condition[0] .= " AND (`language` IS NULL OR " . implode(' OR ', $conditions) . ")";
444 private function getMedianComments(int $uid, int $divider): int
446 $languages = User::getWantedLanguages($uid);
447 $cache_key = 'Channel:getMedianComments:' . $divider . ':' . implode(':', $languages);
448 $comments = $this->cache->get($cache_key);
449 if (!empty($comments)) {
453 $condition = ["`contact-type` != ? AND `comments` > ? AND NOT `restricted`", Contact::TYPE_COMMUNITY, 0];
454 $condition = $this->addLanguageCondition($uid, $condition);
456 $limit = $this->database->count('post-engagement', $condition) / $divider;
457 $post = $this->database->selectToArray('post-engagement', ['comments'], $condition, ['order' => ['comments' => true], 'limit' => [$limit, 1]]);
458 $comments = $post[0]['comments'] ?? 0;
459 if (empty($comments)) {
463 $this->cache->set($cache_key, $comments, Duration::HALF_HOUR);
464 $this->logger->debug('Calculated median comments', ['divider' => $divider, 'languages' => $languages, 'median' => $comments]);
468 private function getMedianActivities(int $uid, int $divider): int
470 $languages = User::getWantedLanguages($uid);
471 $cache_key = 'Channel:getMedianActivities:' . $divider . ':' . implode(':', $languages);
472 $activities = $this->cache->get($cache_key);
473 if (!empty($activities)) {
477 $condition = ["`contact-type` != ? AND `activities` > ? AND NOT `restricted`", Contact::TYPE_COMMUNITY, 0];
478 $condition = $this->addLanguageCondition($uid, $condition);
480 $limit = $this->database->count('post-engagement', $condition) / $divider;
481 $post = $this->database->selectToArray('post-engagement', ['activities'], $condition, ['order' => ['activities' => true], 'limit' => [$limit, 1]]);
482 $activities = $post[0]['activities'] ?? 0;
483 if (empty($activities)) {
487 $this->cache->set($cache_key, $activities, Duration::HALF_HOUR);
488 $this->logger->debug('Calculated median activities', ['divider' => $divider, 'languages' => $languages, 'median' => $activities]);
492 private function getMedianRelationThreadScore(int $cid, int $divider): int
494 $cache_key = 'Channel:getThreadScore:' . $cid . ':' . $divider;
495 $score = $this->cache->get($cache_key);
496 if (!empty($score)) {
500 $condition = ["`relation-cid` = ? AND `relation-thread-score` > ?", $cid, 0];
502 $limit = $this->database->count('contact-relation', $condition) / $divider;
503 $relation = $this->database->selectToArray('contact-relation', ['relation-thread-score'], $condition, ['order' => ['relation-thread-score' => true], 'limit' => [$limit, 1]]);
504 $score = $relation[0]['relation-thread-score'] ?? 0;
509 $this->cache->set($cache_key, $score, Duration::HALF_HOUR);
510 $this->logger->debug('Calculated median score', ['cid' => $cid, 'divider' => $divider, 'median' => $score]);
515 * Computes the displayed items.
517 * Community pages have a restriction on how many successive posts by the same author can show on any given page,
518 * so we may have to retrieve more content beyond the first query
523 protected function getCommunityItems()
525 $items = $this->selectItems();
527 if ($this->selectedTab == 'local') {
528 $maxpostperauthor = (int)$this->config->get('system', 'max_author_posts_community_page');
530 } elseif ($this->selectedTab == 'global') {
531 $maxpostperauthor = (int)$this->config->get('system', 'max_server_posts_community_page');
532 $key = 'author-gsid';
534 $maxpostperauthor = 0;
536 if ($maxpostperauthor != 0) {
539 $selected_items = [];
541 while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
542 $maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
543 $minId = $items[array_key_first($items)]['received'];
544 $maxId = $items[array_key_last($items)]['received'];
546 foreach ($items as $item) {
547 $author_posts[$item[$key]][$item['uri-id']] = $item['received'];
549 foreach ($author_posts as $posts) {
550 if (count($posts) <= $maxposts) {
554 while (count($posts) > $maxposts) {
555 $uri_id = array_key_first($posts);
556 unset($posts[$uri_id]);
557 unset($items[$uri_id]);
560 $selected_items = array_merge($selected_items, $items);
562 // If we're looking at a "previous page", the lookup continues forward in time because the list is
563 // sorted in chronologically decreasing order
564 if (!empty($this->minId)) {
565 $this->minId = $minId;
567 // In any other case, the lookup continues backwards in time
568 $this->maxId = $maxId;
571 if (count($selected_items) < $this->itemsPerPage) {
572 $items = $this->selectItems();
576 $selected_items = $items;
579 $condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
580 $this->setItemsSeenByCondition($condition);
582 return $selected_items;
586 * Database query for the community page
590 * @TODO Move to repository/factory
592 private function selectItems()
594 if ($this->selectedTab == 'local') {
595 $condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
596 } elseif ($this->selectedTab == 'global') {
597 $condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
602 if (!is_null($this->accountType)) {
603 $condition = DBA::mergeConditions($condition, ['owner-contact-type' => $this->accountType]);
606 $params = ['order' => ['received' => true], 'limit' => $this->itemsPerPage];
608 if (!empty($this->itemUriId)) {
609 $condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
611 if ($this->session->getLocalUserId() && $this->noSharer) {
612 $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]);
615 if (isset($this->maxId)) {
616 $condition = DBA::mergeConditions($condition, ["`received` < ?", $this->maxId]);
619 if (isset($this->minId)) {
620 $condition = DBA::mergeConditions($condition, ["`received` > ?", $this->minId]);
622 // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
623 if (!isset($this->maxId)) {
624 $params['order']['received'] = false;
630 $result = Post::selectThreadForUser($this->session->getLocalUserId() ?: 0, ['uri-id', 'received', 'author-id', 'author-gsid'], $condition, $params);
632 while ($item = $this->database->fetch($result)) {
633 $item['comments'] = 0;
635 $items[$item['uri-id']] = $item;
637 $this->database->close($result);
643 $uriids = array_keys($items);
645 foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'verb' => Activity::POST]) as $count) {
646 $items[$count['parent-uri-id']]['comments'] += $count['count'];
649 // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
650 if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
651 $items = array_reverse($items);
660 * @param array $condition The array with the SQL condition
661 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
663 protected function setItemsSeenByCondition(array $condition)
665 if (empty($condition)) {
669 $unseen = Post::exists($condition);
672 /// @todo handle huge "unseen" updates in the background to avoid timeout errors
673 Item::update(['unseen' => false], $condition);