From 276abfaba68a9d6f750552479eeb873ac0b1c806 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 8 Aug 2018 22:32:11 +0200 Subject: [PATCH] Issue 5158: Ignore all threads, even public ones (#5588) * Issue 5158: Ignore all threads, even public ones * Remove some notice * Now it really should work * Using "defaults" --- boot.php | 2 +- config/dbstructure.json | 3 ++- database.sql | 3 ++- include/enotify.php | 11 ++++------- mod/ignored.php | 41 ++++++++++++++++++++++------------------- src/Model/Item.php | 21 ++++++++++++++++++--- src/Object/Post.php | 24 ++++++++++++------------ 7 files changed, 61 insertions(+), 44 deletions(-) diff --git a/boot.php b/boot.php index ab73c6dedd..ebdb58236b 100644 --- a/boot.php +++ b/boot.php @@ -41,7 +41,7 @@ define('FRIENDICA_PLATFORM', 'Friendica'); define('FRIENDICA_CODENAME', 'The Tazmans Flax-lily'); define('FRIENDICA_VERSION', '2018.08-dev'); define('DFRN_PROTOCOL_VERSION', '2.23'); -define('DB_UPDATE_VERSION', 1281); +define('DB_UPDATE_VERSION', 1282); define('NEW_UPDATE_ROUTINE_VERSION', 1170); /** diff --git a/config/dbstructure.json b/config/dbstructure.json index fce2fcf930..2c1ecddc56 100644 --- a/config/dbstructure.json +++ b/config/dbstructure.json @@ -1229,7 +1229,8 @@ "fields": { "iid": {"type": "int unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"item": "id"}, "comment": "Item id"}, "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"user": "uid"}, "comment": "User id"}, - "hidden": {"type": "boolean", "not null": "1", "default": "0", "comment": "Marker to hide an item from the user"} + "hidden": {"type": "boolean", "not null": "1", "default": "0", "comment": "Marker to hide an item from the user"}, + "ignored": {"type": "boolean", "comment": "Ignore this thread if set"} }, "indexes": { "PRIMARY": ["uid", "iid"] diff --git a/database.sql b/database.sql index 5289328462..0dbeb80dd0 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2018.08-dev (The Tazmans Flax-lily) --- DB_UPDATE_VERSION 1281 +-- DB_UPDATE_VERSION 1282 -- ------------------------------------------ @@ -1180,6 +1180,7 @@ CREATE TABLE IF NOT EXISTS `user-item` ( `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item id', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user', + `ignored` boolean COMMENT 'Ignore this thread if set', PRIMARY KEY(`uid`,`iid`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data'; diff --git a/include/enotify.php b/include/enotify.php index 6d27aa8897..eb539c69f4 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -117,7 +117,7 @@ function notification($params) } if ($params['type'] == NOTIFY_COMMENT) { - $thread = DBA::selectFirst('thread', ['ignored'], ['iid' => $parent_id]); + $thread = Item::selectFirstThreadForUser($params['uid'] ,['ignored'], ['iid' => $parent_id]); if (DBA::isResult($thread) && $thread["ignored"]) { logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG); return; @@ -814,13 +814,10 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { } // Is it a post that the user had started or where he interacted? - $parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid` - WHERE `thread`.`iid` = %d AND NOT `thread`.`ignored` AND - (`thread`.`mention` OR `item`.`author-id` IN ($contact_list)) - LIMIT 1", - intval($item["parent"])); + $fields = ['ignored', 'mention', 'author-id']; + $thread = Item::selectFirstThreadForUser($params['uid'], $fields, ['iid' => $item["parent"]]); - if ($parent && !isset($params["type"])) { + if (($thread['mention'] || in_array($thread['author-id'], $contacts)) && !$thread['ignored'] && !isset($params["type"])) { $params["type"] = NOTIFY_COMMENT; $params["verb"] = ACTIVITY_POST; } diff --git a/mod/ignored.php b/mod/ignored.php index 0379d2d945..f42e3a8bd3 100644 --- a/mod/ignored.php +++ b/mod/ignored.php @@ -3,45 +3,48 @@ use Friendica\App; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\Item; -function ignored_init(App $a) { - +function ignored_init(App $a) +{ $ignored = 0; - if (! local_user()) { + if (!local_user()) { killme(); } + if ($a->argc > 1) { $message_id = intval($a->argv[1]); } - if (! $message_id) { + + if (!$message_id) { killme(); } - $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", - intval(local_user()), - intval($message_id) - ); - if (! DBA::isResult($r)) { + $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]); + if (!DBA::isResult($thread)) { killme(); } - if (! intval($r[0]['ignored'])) { - $ignored = 1; + if (!$thread['ignored']) { + $ignored = true; } - $r = q("UPDATE `thread` SET `ignored` = %d WHERE `uid` = %d and `iid` = %d", - intval($ignored), - intval(local_user()), - intval($message_id) - ); + if ($thread['uid'] != 0) { + DBA::update('thread', ['ignored' => $ignored], ['iid' => $message_id]); + } else { + DBA::update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true); + } // See if we've been passed a return path to redirect to - $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); + $return_path = defaults($_REQUEST, 'return', ''); if ($return_path) { $rand = '_=' . time(); - if(strpos($return_path, '?')) $rand = "&$rand"; - else $rand = "?$rand"; + if (strpos($return_path, '?')) { + $rand = "&$rand"; + } else { + $rand = "?$rand"; + } goaway(System::baseUrl() . "/" . $return_path . $rand); } diff --git a/src/Model/Item.php b/src/Model/Item.php index 6d0b1901bd..3b491cbe86 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -230,12 +230,17 @@ class Item extends BaseObject } } + if (array_key_exists('ignored', $row) && array_key_exists('internal-user-ignored', $row) && !is_null($row['internal-user-ignored'])) { + $row['ignored'] = $row['internal-user-ignored']; + } + // Remove internal fields unset($row['internal-activity']); unset($row['internal-network']); unset($row['internal-iid']); unset($row['internal-iaid']); unset($row['internal-icid']); + unset($row['internal-user-ignored']); return $row; } @@ -369,7 +374,7 @@ class Item extends BaseObject $usermode = true; } - $fields = self::fieldlist($selected); + $fields = self::fieldlist($selected, $usermode); $select_fields = self::constructSelectFields($fields, $selected); @@ -476,7 +481,9 @@ class Item extends BaseObject $usermode = true; } - $fields = self::fieldlist($selected); + $fields = self::fieldlist($selected, $usermode); + + $fields['thread'] = ['mention', 'ignored', 'iid']; $threadfields = ['thread' => ['iid', 'uid', 'contact-id', 'owner-id', 'author-id', 'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private', @@ -510,7 +517,7 @@ class Item extends BaseObject * * @return array field list */ - private static function fieldlist($selected) + private static function fieldlist($selected, $usermode) { $fields = []; @@ -524,6 +531,10 @@ class Item extends BaseObject 'network' => 'internal-network', 'icid' => 'internal-icid', 'iaid' => 'internal-iaid']; + if ($usermode) { + $fields['user-item'] = ['ignored' => 'internal-user-ignored']; + } + $fields['item-activity'] = ['activity', 'activity' => 'internal-activity']; $fields['item-content'] = array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST); @@ -681,6 +692,10 @@ class Item extends BaseObject $selected[] = 'internal-activity'; } + if (in_array('ignored', $selected)) { + $selected[] = 'internal-user-ignored'; + } + $selection = []; foreach ($fields as $table => $table_fields) { foreach ($table_fields as $field => $select) { diff --git a/src/Object/Post.php b/src/Object/Post.php index a055f65251..05b21ebd4c 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -252,6 +252,18 @@ class Post extends BaseObject $tagger = ''; if ($this->isToplevel()) { + $thread = Item::selectFirstThreadForUser(local_user(), ['ignored'], ['iid' => $item['id']]); + if (DBA::isResult($thread)) { + $ignore = [ + 'do' => L10n::t("ignore thread"), + 'undo' => L10n::t("unignore thread"), + 'toggle' => L10n::t("toggle ignore status"), + 'classdo' => $thread['ignored'] ? "hidden" : "", + 'classundo' => $thread['ignored'] ? "" : "hidden", + 'ignored' => L10n::t('ignored'), + ]; + } + if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); @@ -264,18 +276,6 @@ class Post extends BaseObject 'starred' => L10n::t('starred'), ]; - $thread = DBA::selectFirst('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]); - if (DBA::isResult($thread)) { - $ignore = [ - 'do' => L10n::t("ignore thread"), - 'undo' => L10n::t("unignore thread"), - 'toggle' => L10n::t("toggle ignore status"), - 'classdo' => $thread['ignored'] ? "hidden" : "", - 'classundo' => $thread['ignored'] ? "" : "hidden", - 'ignored' => L10n::t('ignored'), - ]; - } - if (Feature::isEnabled($conv->getProfileOwner(), 'commtag')) { $tagger = [ 'add' => L10n::t("add tag"),