Move GET /like/{id} to POST /item/{id}/activity/{verb}
This commit is contained in:
parent
3a18669730
commit
151db1104a
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Module;
|
namespace Friendica\Module\Item;
|
||||||
|
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
|
@ -34,9 +34,10 @@ use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Strings;
|
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 = [])
|
public static function rawContent(array $parameters = [])
|
||||||
{
|
{
|
||||||
|
@ -44,16 +45,12 @@ class Like extends BaseModule
|
||||||
throw new HTTPException\ForbiddenException();
|
throw new HTTPException\ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$verb = Strings::escapeTags(trim($_GET['verb']));
|
if (empty($parameters['id']) || empty($parameters['verb'])) {
|
||||||
|
throw new HTTPException\BadRequestException();
|
||||||
if (!$verb) {
|
|
||||||
$verb = 'like';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$app = DI::app();
|
$verb = $parameters['verb'];
|
||||||
|
$itemId = $parameters['id'];
|
||||||
// @TODO: Replace with parameter from router
|
|
||||||
$itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0);
|
|
||||||
|
|
||||||
if (in_array($verb, ['announce', 'unannounce'])) {
|
if (in_array($verb, ['announce', 'unannounce'])) {
|
||||||
$item = Post::selectFirst(['network'], ['id' => $itemId]);
|
$item = Post::selectFirst(['network'], ['id' => $itemId]);
|
||||||
|
@ -66,22 +63,27 @@ class Like extends BaseModule
|
||||||
throw new HTTPException\BadRequestException();
|
throw new HTTPException\BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide how to return. If we were called with a 'return' argument,
|
// See if we've been passed a return path to redirect to
|
||||||
// then redirect back to the calling page. If not, just quietly end
|
$return_path = $_REQUEST['return'] ?? '';
|
||||||
$returnPath = $_REQUEST['return'] ?? '';
|
if (!empty($return_path)) {
|
||||||
|
|
||||||
if (!empty($returnPath)) {
|
|
||||||
$rand = '_=' . time();
|
$rand = '_=' . time();
|
||||||
if (strpos($returnPath, '?')) {
|
if (strpos($return_path, '?')) {
|
||||||
$rand = "&$rand";
|
$rand = "&$rand";
|
||||||
} else {
|
} else {
|
||||||
$rand = "?$rand";
|
$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)
|
private static function performDiasporaReshare(int $itemId)
|
|
@ -292,10 +292,10 @@ return [
|
||||||
|
|
||||||
'/item' => [
|
'/item' => [
|
||||||
'/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]],
|
'/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]],
|
'/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]],
|
||||||
'/login' => [Module\Security\Login::class, [R::GET, R::POST]],
|
'/login' => [Module\Security\Login::class, [R::GET, R::POST]],
|
||||||
'/logout' => [Module\Security\Logout::class, [R::GET, R::POST]],
|
'/logout' => [Module\Security\Logout::class, [R::GET, R::POST]],
|
||||||
|
|
|
@ -669,7 +669,7 @@ function doActivityItem(ident, verb, un) {
|
||||||
unpause();
|
unpause();
|
||||||
$('#like-rotator-' + ident.toString()).show();
|
$('#like-rotator-' + ident.toString()).show();
|
||||||
verb = un ? 'un' + verb : verb;
|
verb = un ? 'un' + verb : verb;
|
||||||
$.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate);
|
$.post('item/' + ident.toString() + '/activity/' + verb, NavUpdate);
|
||||||
liking = 1;
|
liking = 1;
|
||||||
force_update = true;
|
force_update = true;
|
||||||
update_item = ident.toString();
|
update_item = ident.toString();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user