Add jsonExit() and fix UID issue

This commit is contained in:
Philipp Holzer 2019-10-23 16:24:19 +02:00
parent 17aca9bee8
commit db25f5b6ca
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90

View File

@ -6,6 +6,7 @@ use Friendica\App;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\L10n\L10n; use Friendica\Core\L10n\L10n;
use Friendica\Core\Session; use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -43,10 +44,20 @@ class Ignored extends BaseModule
// Numeric values are needed for the json output further below // Numeric values are needed for the json output further below
$ignored = !empty($thread['ignored']) ? 0 : 1; $ignored = !empty($thread['ignored']) ? 0 : 1;
if (!empty($thread['uid']) && $thread['uid'] != 0) { switch ($thread['uid'] ?? 0) {
$dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]); // if the thread is from the current user
} else { case local_user():
$dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true); $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
break;
// Empty or 0 (null will get transformed to 0) => it's a public post
case 0:
case '':
$dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
break;
// In case we retrieved a thread which isn't our or a public, it's a forbidden action
// but due to security reason (brute force), we print a Bad request exception
default:
throw new HTTPException\BadRequestException();
} }
// See if we've been passed a return path to redirect to // See if we've been passed a return path to redirect to
@ -63,8 +74,6 @@ class Ignored extends BaseModule
} }
// the json doesn't really matter, it will either be 0 or 1 // the json doesn't really matter, it will either be 0 or 1
System::jsonExit([$ignored]);
echo json_encode($ignored);
exit();
} }
} }