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