diff --git a/src/Module/Like.php b/src/Module/Item/Activity.php similarity index 78% rename from src/Module/Like.php rename to src/Module/Item/Activity.php index 8d699be5e..69f5db75d 100644 --- a/src/Module/Like.php +++ b/src/Module/Item/Activity.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\Item; use Friendica\BaseModule; use Friendica\Content\Text\BBCode; @@ -34,9 +34,10 @@ use Friendica\Network\HTTPException; use Friendica\Util\Strings; /** - * Performs a like and optionally redirects to a return path + * Performs an activity (like, dislike, announce, attendyes, attendno, attendmaybe) + * and optionally redirects to a return path */ -class Like extends BaseModule +class Activity extends BaseModule { public static function rawContent(array $parameters = []) { @@ -44,16 +45,12 @@ class Like extends BaseModule throw new HTTPException\ForbiddenException(); } - $verb = Strings::escapeTags(trim($_GET['verb'])); - - if (!$verb) { - $verb = 'like'; + if (empty($parameters['id']) || empty($parameters['verb'])) { + throw new HTTPException\BadRequestException(); } - $app = DI::app(); - - // @TODO: Replace with parameter from router - $itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0); + $verb = $parameters['verb']; + $itemId = $parameters['id']; if (in_array($verb, ['announce', 'unannounce'])) { $item = Post::selectFirst(['network'], ['id' => $itemId]); @@ -66,22 +63,27 @@ class Like extends BaseModule throw new HTTPException\BadRequestException(); } - // Decide how to return. If we were called with a 'return' argument, - // then redirect back to the calling page. If not, just quietly end - $returnPath = $_REQUEST['return'] ?? ''; - - if (!empty($returnPath)) { + // See if we've been passed a return path to redirect to + $return_path = $_REQUEST['return'] ?? ''; + if (!empty($return_path)) { $rand = '_=' . time(); - if (strpos($returnPath, '?')) { + if (strpos($return_path, '?')) { $rand = "&$rand"; } else { $rand = "?$rand"; } - DI::baseUrl()->redirect($returnPath . $rand); + DI::baseUrl()->redirect($return_path . $rand); } - System::jsonExit(['status' => 'OK']); + $return = [ + 'status' => 'ok', + 'item_id' => $itemId, + 'verb' => $verb, + 'state' => 1, + ]; + + System::jsonExit($return); } private static function performDiasporaReshare(int $itemId) diff --git a/static/routes.config.php b/static/routes.config.php index 5a2ee2ffd..564b920d6 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -292,10 +292,10 @@ return [ '/item' => [ '/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]], - '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], + '/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], + '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], ], - '/like/{item:\d+}' => [Module\Like::class, [R::GET]], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], '/login' => [Module\Security\Login::class, [R::GET, R::POST]], '/logout' => [Module\Security\Logout::class, [R::GET, R::POST]], diff --git a/view/js/main.js b/view/js/main.js index 1503529d1..1e051de83 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -665,11 +665,11 @@ function imgdull(node) { * @param {string} verb The verb of the action * @param {boolean} un Whether to perform an activity removal instead of creation */ -function dolike(ident, verb, un) { +function doActivityItem(ident, verb, un) { unpause(); $('#like-rotator-' + ident.toString()).show(); verb = un ? 'un' + verb : verb; - $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate); + $.post('item/' + ident.toString() + '/activity/' + verb, NavUpdate); liking = 1; force_update = true; update_item = ident.toString(); diff --git a/view/templates/like_noshare.tpl b/view/templates/like_noshare.tpl index 4419a5b97..3272c2831 100644 --- a/view/templates/like_noshare.tpl +++ b/view/templates/like_noshare.tpl @@ -1,8 +1,8 @@
diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index 4b1a42785..7dcdb15a5 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -84,9 +84,9 @@