From 5d270fbb54c679f8f41ae83a4b3e1f2f7962ecd5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 17:51:27 -0500 Subject: [PATCH 1/8] Rename dostar() to doStar() --- view/js/main.js | 19 ++++++++++++------- view/templates/wall_thread.tpl | 2 +- view/theme/frio/templates/search_item.tpl | 4 ++-- view/theme/frio/templates/wall_thread.tpl | 8 ++++---- view/theme/quattro/templates/photo_item.tpl | 4 ++-- view/theme/quattro/templates/search_item.tpl | 4 ++-- view/theme/quattro/templates/wall_thread.tpl | 4 ++-- view/theme/smoothly/templates/wall_thread.tpl | 2 +- view/theme/vier/templates/photo_item.tpl | 4 ++-- view/theme/vier/templates/search_item.tpl | 4 ++-- view/theme/vier/templates/wall_thread.tpl | 4 ++-- 11 files changed, 32 insertions(+), 27 deletions(-) diff --git a/view/js/main.js b/view/js/main.js index 4921ea94f7..d1976fdaa9 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -682,21 +682,26 @@ function dosubthread(ident) { liking = 1; } -function dostar(ident) { +function doStar(ident) { ident = ident.toString(); $('#like-rotator-' + ident).show(); - $.get('starred/' + ident, function(data) { - if (data.match(/1/)) { - $('#starred-' + ident).addClass('starred'); - $('#starred-' + ident).removeClass('unstarred'); + $.get('starred/' + ident) + .then(function(data) { + if (data.state === 1) { + $('#starred-' + ident) + .addClass('starred') + .removeClass('unstarred'); $('#star-' + ident).addClass('hidden'); $('#unstar-' + ident).removeClass('hidden'); } else { - $('#starred-' + ident).addClass('unstarred'); - $('#starred-' + ident).removeClass('starred'); + $('#starred-' + ident) + .addClass('unstarred') + .removeClass('starred'); $('#star-' + ident).removeClass('hidden'); $('#unstar-' + ident).addClass('hidden'); } + }) + .always(function () { $('#like-rotator-' + ident).hide(); }); } diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index 7dcdb15a5d..0d2561869f 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -105,7 +105,7 @@ {{/if}} {{if $item.star}} - + {{/if}} {{if $item.tagger}} diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 6e76f23d6a..bcd957396b 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -206,8 +206,8 @@ {{if $item.star}}
  • -  {{$item.star.do}} -  {{$item.star.undo}} +  {{$item.star.do}} +  {{$item.star.undo}}
  • {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index f632b0bba1..34d2a73747 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -358,8 +358,8 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.star}}
  • -  {{$item.star.do}} -  {{$item.star.undo}} +  {{$item.star.do}} +  {{$item.star.undo}}
  • {{/if}} @@ -523,8 +523,8 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.star}}
  • -  {{$item.star.do}} -  {{$item.star.undo}} +  {{$item.star.do}} +  {{$item.star.undo}}
  • {{/if}} diff --git a/view/theme/quattro/templates/photo_item.tpl b/view/theme/quattro/templates/photo_item.tpl index 182607ab35..4a43d2cb81 100644 --- a/view/theme/quattro/templates/photo_item.tpl +++ b/view/theme/quattro/templates/photo_item.tpl @@ -33,8 +33,8 @@
    {{if $star}} - {{$star.do}} - {{$star.undo}} + {{$star.do}} + {{$star.undo}} {{$star.tagger}} {{/if}} diff --git a/view/theme/quattro/templates/search_item.tpl b/view/theme/quattro/templates/search_item.tpl index 70aa2ed863..3793cb1033 100644 --- a/view/theme/quattro/templates/search_item.tpl +++ b/view/theme/quattro/templates/search_item.tpl @@ -52,8 +52,8 @@
    {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{$item.star.tagger}} {{/if}} diff --git a/view/theme/quattro/templates/wall_thread.tpl b/view/theme/quattro/templates/wall_thread.tpl index 671b7643f3..e3ed4f26ca 100644 --- a/view/theme/quattro/templates/wall_thread.tpl +++ b/view/theme/quattro/templates/wall_thread.tpl @@ -102,8 +102,8 @@ {{$item.pin.undo}} {{/if}} {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{/if}} {{if $item.ignore}} {{$item.ignore.do}} diff --git a/view/theme/smoothly/templates/wall_thread.tpl b/view/theme/smoothly/templates/wall_thread.tpl index 4f70ea6d5b..53f918813f 100644 --- a/view/theme/smoothly/templates/wall_thread.tpl +++ b/view/theme/smoothly/templates/wall_thread.tpl @@ -117,7 +117,7 @@ {{/if}} {{if $item.star}} - + {{/if}} {{if $item.tagger}} diff --git a/view/theme/vier/templates/photo_item.tpl b/view/theme/vier/templates/photo_item.tpl index aafadae911..069bd22296 100644 --- a/view/theme/vier/templates/photo_item.tpl +++ b/view/theme/vier/templates/photo_item.tpl @@ -40,8 +40,8 @@
    {{if $star}} - {{$star.do}} - {{$star.undo}} + {{$star.do}} + {{$star.undo}} {{$star.tagger}} {{/if}} diff --git a/view/theme/vier/templates/search_item.tpl b/view/theme/vier/templates/search_item.tpl index 7a4c332d08..063e0e9433 100644 --- a/view/theme/vier/templates/search_item.tpl +++ b/view/theme/vier/templates/search_item.tpl @@ -57,8 +57,8 @@
    {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{$item.star.tagger}} {{/if}} diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl index 1e4806c9e0..73997e7c53 100644 --- a/view/theme/vier/templates/wall_thread.tpl +++ b/view/theme/vier/templates/wall_thread.tpl @@ -140,8 +140,8 @@ {{$item.pin.undo}} {{/if}} {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{/if}} {{if $item.ignore}} {{$item.ignore.do}} From b31fc3bfa939c2b384e86182e57d12188624e909 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 17:52:01 -0500 Subject: [PATCH 2/8] Move GET starred/{id} to POST item/{id}/star --- src/Module/{Starred.php => Item/Star.php} | 46 +++++++++++++++-------- static/routes.config.php | 2 +- view/js/main.js | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) rename src/Module/{Starred.php => Item/Star.php} (60%) diff --git a/src/Module/Starred.php b/src/Module/Item/Star.php similarity index 60% rename from src/Module/Starred.php rename to src/Module/Item/Star.php index 8bc0fa3e4e..fb1a5d2044 100644 --- a/src/Module/Starred.php +++ b/src/Module/Item/Star.php @@ -19,33 +19,38 @@ * */ -namespace Friendica\Module; +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; /** * Toggle starred items */ -class Starred extends BaseModule +class Star extends BaseModule { public static function rawContent(array $parameters = []) { - if (!local_user()) { - throw new \Friendica\Network\HTTPException\ForbiddenException(); + $l10n = DI::l10n(); + + if (!Session::isAuthenticated()) { + throw new HttpException\ForbiddenException($l10n->t('Access denied.')); } - if (empty($parameters['item'])) { - throw new \Friendica\Network\HTTPException\BadRequestException(); + if (empty($parameters['id'])) { + throw new HTTPException\BadRequestException(); } - $itemId = intval($parameters['item']); + $itemId = intval($parameters['id']); $item = Post::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]); if (empty($item)) { - throw new \Friendica\Network\HTTPException\NotFoundException(); + throw new HTTPException\NotFoundException(); } $starred = !(bool)$item['starred']; @@ -53,14 +58,25 @@ class Starred extends BaseModule Item::update(['starred' => $starred], ['id' => $itemId]); // See if we've been passed a return path to redirect to - $returnPath = $_REQUEST['return'] ?? ''; - if (!empty($returnPath)) { - $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; - DI::baseUrl()->redirect($returnPath . $rand); + $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); } - // the json doesn't really matter, it will either be 0 or 1 - echo json_encode((int)$starred); - exit(); + $return = [ + 'status' => 'ok', + 'item_id' => $itemId, + 'verb' => 'star', + 'state' => (int)$starred, + ]; + + System::jsonExit($return); } } diff --git a/static/routes.config.php b/static/routes.config.php index 6acad3827e..7d1d9a1bfc 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -294,6 +294,7 @@ return [ '/{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]], ], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], @@ -412,7 +413,6 @@ return [ '/rsd.xml' => [Module\ReallySimpleDiscovery::class, [R::GET]], '/smilies[/json]' => [Module\Smilies::class, [R::GET]], '/statistics.json' => [Module\Statistics::class, [R::GET]], - '/starred/{item:\d+}' => [Module\Starred::class, [R::GET]], '/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]], '/tos' => [Module\Tos::class, [R::GET]], diff --git a/view/js/main.js b/view/js/main.js index d1976fdaa9..0b9c1da283 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -685,7 +685,7 @@ function dosubthread(ident) { function doStar(ident) { ident = ident.toString(); $('#like-rotator-' + ident).show(); - $.get('starred/' + ident) + $.post('item/' + ident + '/star') .then(function(data) { if (data.state === 1) { $('#starred-' + ident) From 15e9f219e7c0fb13b3ed430bad92bc1dcf01a5ac Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 15:34:58 -0500 Subject: [PATCH 3/8] 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 4/8] 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}}