1
0
Fork 0

Move GET /like/{id} to POST /item/{id}/activity/{verb}

This commit is contained in:
Hypolite Petovan 2021-01-30 17:11:54 -05:00
parent 3a18669730
commit 151db1104a
3 changed files with 24 additions and 22 deletions

View file

@ -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)

View file

@ -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]],

View file

@ -669,7 +669,7 @@ 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();