From 15e9f219e7c0fb13b3ed430bad92bc1dcf01a5ac Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 15:34:58 -0500 Subject: [PATCH 1/3] 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 0000000000..ca8aac72bd --- /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 7d1d9a1bfc..afb8ee12f8 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]], From 7f78d6e722a8c101553c557b327a06d9537418dc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 15:51:27 -0500 Subject: [PATCH 2/3] Replace references of GET mod/substhread with POST item/{id}/follow --- include/conversation.php | 2 +- view/js/main.js | 4 ++-- view/theme/frio/templates/search_item.tpl | 8 ++++---- view/theme/frio/templates/wall_thread.tpl | 14 +++++++------- view/theme/frio/theme.php | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index b2353db2a3..5b49bc9dc1 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -894,7 +894,7 @@ function item_photo_menu($item) { $ignore_link = ''; if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) { - $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; + $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;'; } $author = ['uid' => 0, 'id' => $item['author-id'], diff --git a/view/js/main.js b/view/js/main.js index 0b9c1da283..4db78f6652 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -675,10 +675,10 @@ function doActivityItem(ident, verb, un) { update_item = ident.toString(); } -function dosubthread(ident) { +function doFollowThread(ident) { unpause(); $('#like-rotator-' + ident.toString()).show(); - $.get('subthread/' + ident.toString(), NavUpdate); + $.post('item/' + ident.toString() + '/follow', NavUpdate); liking = 1; } diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index bcd957396b..2791a670b3 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -174,7 +174,7 @@ {{* Put additional actions in a dropdown menu *}} - {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread || $item.ignore || $item.drop.dropping}} + {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}} @@ -211,9 +211,9 @@ {{/if}} - {{if $item.subthread}} + {{if $item.follow_thread}}
  • -  {{$item.subthread.title}} +  {{$item.follow_thread.title}}
  • {{/if}} @@ -223,7 +223,7 @@ {{/if}} - {{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread) && ($item.ignore || $item.drop.dropping)}} + {{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread) && ($item.ignore || $item.drop.dropping)}} {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 34d2a73747..52a0e7c486 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -326,7 +326,7 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} {{* Put additional actions in a dropdown menu *}} - {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread || $item.ignore || $item.drop.dropping}} + {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}} @@ -363,9 +363,9 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} - {{if $item.subthread}} + {{if $item.follow_thread}}
  • -  {{$item.subthread.title}} +  {{$item.follow_thread.title}}
  • {{/if}} @@ -375,7 +375,7 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} - {{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread) && ($item.ignore || $item.drop.dropping)}} + {{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread) && ($item.ignore || $item.drop.dropping)}} {{/if}} @@ -492,7 +492,7 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} - {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread || $item.ignore || $item.drop.dropping}} + {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}}