]> git.mxchange.org Git - friendica.git/commitdiff
Move GET item/ignore/{id} to POST item/{id}/ignore
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 30 Jan 2021 21:23:46 +0000 (16:23 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 31 Jan 2021 17:56:44 +0000 (12:56 -0500)
src/Module/Item/Ignore.php
static/routes.config.php
view/js/main.js

index 1883faa90502d87ecaf65a18e22e0165e8b266d2..668e493109bdfe8102ded2add315ab5216f7704b 100644 (file)
@@ -41,18 +41,17 @@ class Ignore extends BaseModule
                        throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
                }
 
-               $args = DI::args();
-               $dba = DI::dba();
-
-               $message_id = intval($args->get(2));
-
-               if (empty($message_id) || !is_int($message_id)) {
+               if (empty($parameters['id'])) {
                        throw new HTTPException\BadRequestException();
                }
 
-               $thread = Post::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
+               $itemId = intval($parameters['id']);
+
+               $dba = DI::dba();
+
+               $thread = Post::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $itemId]);
                if (!$dba->isResult($thread)) {
-                       throw new HTTPException\BadRequestException();
+                       throw new HTTPException\NotFoundException();
                }
 
                // Numeric values are needed for the json output further below
@@ -61,11 +60,11 @@ class Ignore extends BaseModule
                switch ($thread['uid'] ?? 0) {
                        // if the thread is from the current user
                        case local_user():
-                               $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
+                               $dba->update('thread', ['ignored' => $ignored], ['iid' => $itemId]);
                                break;
                        // 0 (null will get transformed to 0) => it's a public post
                        case 0:
-                               $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
+                               $dba->update('user-item', ['ignored' => $ignored], ['iid' => $itemId, 'uid' => local_user()], true);
                                break;
                        // Throws a BadRequestException and not a ForbiddenException on purpose
                        // Avoids harvesting existing, but forbidden IIDs (security issue)
@@ -86,7 +85,13 @@ class Ignore extends BaseModule
                        DI::baseUrl()->redirect($return_path . $rand);
                }
 
-               // the json doesn't really matter, it will either be 0 or 1
-               System::jsonExit($ignored);
+               $return = [
+                       'status'  => 'ok',
+                       'item_id' => $itemId,
+                       'verb'    => 'ignore',
+                       'state'   => $ignored,
+               ];
+
+               System::jsonExit($return);
        }
 }
index 564b920d61e36a3c033b93b19ea4db83d01f2fc1..6acad3827ebd7dfb70cf0bf376e0364be525ea58 100644 (file)
@@ -291,8 +291,8 @@ return [
        ],
 
        '/item'            => [
-               '/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]],
                '/{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]],
        ],
 
index 3613ee78f6cc3640b3ea05e25625c850cccfa47d..4921ea94f791100a53dabe23e8dc328362cbc49c 100644 (file)
@@ -728,8 +728,8 @@ function doPin(ident) {
 function doIgnoreThread(ident) {
        ident = ident.toString();
        $('#like-rotator-' + ident).show();
-       $.get('item/ignore/' + ident, function(data) {
-               if (data === 1) {
+       $.post('item/' + ident + '/ignore', function(data) {
+               if (data.state === 1) {
                        $('#ignored-' + ident)
                                .addClass('ignored')
                                .removeClass('unignored');