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/>.
20 * See update_profile.php for documentation
23 namespace Friendica\Module\Update;
25 use Friendica\Model\Post;
26 use Friendica\Module\Item\Display as DisplayModule;
27 use Friendica\Util\DateTimeFormat;
28 use Friendica\Network\HTTPException;
31 * Asynchronous update class for the display
33 class Display extends DisplayModule
35 protected function content(array $request = []): string
37 if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
38 throw new HTTPException\UnauthorizedException($this->t('Access denied.'));
41 $profileUid = $request['p'] ?? 0;
42 $force = $request['force'] ?? false;
43 $uriId = $request['uri_id'] ?? 0;
46 throw new HTTPException\BadRequestException($this->t('Parameter uri_id is missing.'));
49 $item = Post::selectFirst(
50 ['uid', 'parent-uri-id', 'uri-id'],
51 ['uri-id' => $uriId, 'uid' => [0, $profileUid]],
52 ['order' => ['uid' => true]]
56 throw new HTTPException\NotFoundException($this->t('The requested item doesn\'t exist or has been deleted.'));
59 $this->app->setProfileOwner($item['uid'] ?? $profileUid);
60 $parentUriId = $item['parent-uri-id'];
63 $browserUpdate = $this->pConfig->get($profileUid, 'system', 'update_interval');
64 if (!empty($browserUpdate)) {
65 $updateDate = date(DateTimeFormat::MYSQL, time() - (intval($browserUpdate) / 500));
67 "`parent-uri-id` = ? AND `uid` IN (?, ?) AND `received` > ?",
69 $profileUid, $updateDate])) {
70 $this->logger->debug('No updated content. Ending process',
71 ['uri-id' => $uriId, 'uid' => $profileUid, 'updated' => $updateDate]);
74 $this->logger->debug('Updated content found.',
75 ['uri-id' => $uriId, 'uid' => $profileUid, 'updated' => $updateDate]);
79 $this->logger->debug('Forced content update.', ['uri-id' => $uriId, 'uid' => $profileUid]);
82 if (!$this->pConfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
83 $this->notification->setAllSeenForUser($this->session->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]);
84 $this->notify->setAllSeenForUser($this->session->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]);
87 return $this->getDisplayData($item, true, $profileUid, $force);