3 namespace Friendica\Module\Item;
6 use Friendica\BaseModule;
7 use Friendica\Core\L10n\L10n;
8 use Friendica\Core\Session;
9 use Friendica\Core\System;
10 use Friendica\Database\Database;
12 use Friendica\Model\Item;
13 use Friendica\Network\HTTPException;
16 * Module for ignoring threads or user items
18 class Ignore extends BaseModule
20 public static function rawContent(array $parameters = [])
24 if (!Session::isAuthenticated()) {
25 throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
31 $message_id = intval($args->get(2));
33 if (empty($message_id) || !is_int($message_id)) {
34 throw new HTTPException\BadRequestException();
37 $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
38 if (!$dba->isResult($thread)) {
39 throw new HTTPException\BadRequestException();
42 // Numeric values are needed for the json output further below
43 $ignored = !empty($thread['ignored']) ? 0 : 1;
45 switch ($thread['uid'] ?? 0) {
46 // if the thread is from the current user
48 $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
50 // 0 (null will get transformed to 0) => it's a public post
52 $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
54 // Throws a BadRequestException and not a ForbiddenException on purpose
55 // Avoids harvesting existing, but forbidden IIDs (security issue)
57 throw new HTTPException\BadRequestException();
60 // See if we've been passed a return path to redirect to
61 $return_path = $_REQUEST['return'] ?? '';
62 if (!empty($return_path)) {
63 $rand = '_=' . time();
64 if (strpos($return_path, '?')) {
70 DI::baseUrl()->redirect($return_path . $rand);
73 // the json doesn't really matter, it will either be 0 or 1
74 System::jsonExit($ignored);