3 * @copyright Copyright (C) 2010-2022, 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\Update;
24 use Friendica\Model\Post;
25 use Friendica\Module\Item\Display as DisplayModule;
26 use Friendica\Util\DateTimeFormat;
27 use Friendica\Network\HTTPException;
30 * Asynchronous update class for the display
32 class Display extends DisplayModule
34 protected function content(array $request = []): string
36 if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
37 throw new HTTPException\UnauthorizedException($this->t('Access denied.'));
40 $profileUid = $request['p'] ?? 0;
41 $force = $request['force'] ?? false;
42 $uriId = $request['uri_id'] ?? 0;
45 throw new HTTPException\BadRequestException($this->t('Parameter uri_id is missing.'));
48 $item = Post::selectFirst(
49 ['uid', 'parent-uri-id', 'uri-id'],
50 ['uri-id' => $uriId, 'uid' => [0, $profileUid]],
51 ['order' => ['uid' => true]]
55 throw new HTTPException\NotFoundException($this->t('The requested item doesn\'t exist or has been deleted.'));
58 $this->app->setProfileOwner($item['uid'] ?: $profileUid);
59 $parentUriId = $item['parent-uri-id'];
62 $browserUpdate = $this->pConfig->get($profileUid, 'system', 'update_interval');
63 if (!empty($browserUpdate)) {
64 $updateDate = date(DateTimeFormat::MYSQL, time() - (intval($browserUpdate) / 500));
66 "`parent-uri-id` = ? AND `uid` IN (?, ?) AND `received` > ?",
68 $profileUid, $updateDate])) {
69 $this->logger->debug('No updated content. Ending process',
70 ['uri-id' => $uriId, 'uid' => $profileUid, 'updated' => $updateDate]);
73 $this->logger->debug('Updated content found.',
74 ['uri-id' => $uriId, 'uid' => $profileUid, 'updated' => $updateDate]);
78 $this->logger->debug('Forced content update.', ['uri-id' => $uriId, 'uid' => $profileUid]);
81 if (!$this->pConfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
82 $this->notification->setAllSeenForUser($this->session->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]);
83 $this->notify->setAllSeenForUser($this->session->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]);
86 return $this->getDisplayData($item, true, $profileUid, $force);