From 15e9f219e7c0fb13b3ed430bad92bc1dcf01a5ac Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 15:34:58 -0500 Subject: [PATCH] Add new item/{id}/follow module and POST route - It is meant to replace mod/subthread --- src/Module/Item/Follow.php | 77 ++++++++++++++++++++++++++++++++++++++ static/routes.config.php | 11 +++--- 2 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/Module/Item/Follow.php diff --git a/src/Module/Item/Follow.php b/src/Module/Item/Follow.php new file mode 100644 index 000000000..ca8aac72b --- /dev/null +++ b/src/Module/Item/Follow.php @@ -0,0 +1,77 @@ +. + * + */ + +namespace Friendica\Module\Item; + +use Friendica\BaseModule; +use Friendica\Core\Session; +use Friendica\Core\System; +use Friendica\DI; +use Friendica\Model\Item; +use Friendica\Model\Post; +use Friendica\Network\HTTPException; + +/** + * Module for following threads + */ +class Follow extends BaseModule +{ + public static function rawContent(array $parameters = []) + { + $l10n = DI::l10n(); + + if (!Session::isAuthenticated()) { + throw new HttpException\ForbiddenException($l10n->t('Access denied.')); + } + + if (empty($parameters['id'])) { + throw new HTTPException\BadRequestException(); + } + + $itemId = intval($parameters['id']); + + if (!Item::performActivity($itemId, 'follow', local_user())) { + throw new HTTPException\BadRequestException($l10n->t('Unable to follow this item.')); + } + + // See if we've been passed a return path to redirect to + $return_path = $_REQUEST['return'] ?? ''; + if (!empty($return_path)) { + $rand = '_=' . time(); + if (strpos($return_path, '?')) { + $rand = "&$rand"; + } else { + $rand = "?$rand"; + } + + DI::baseUrl()->redirect($return_path . $rand); + } + + $return = [ + 'status' => 'ok', + 'item_id' => $itemId, + 'verb' => 'follow', + 'state' => 1 + ]; + + System::jsonExit($return); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 7d1d9a1bf..afb8ee12f 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -290,11 +290,12 @@ return [ '/testrewrite' => [Module\Install::class, [R::GET]], ], - '/item' => [ - '/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], - '/{id:\d+}/ignore' => [Module\Item\Ignore::class, [ R::POST]], - '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], - '/{id:\d+}/star' => [Module\Item\Star::class, [ R::POST]], + '/item/{id:\d+}' => [ + '/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], + '/follow' => [Module\Item\Follow::class, [ R::POST]], + '/ignore' => [Module\Item\Ignore::class, [ R::POST]], + '/pin' => [Module\Item\Pin::class, [ R::POST]], + '/star' => [Module\Item\Star::class, [ R::POST]], ], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]],