]> git.mxchange.org Git - friendica.git/commitdiff
Issue 5158: Ignore all threads, even public ones (#5588)
authorMichael Vogel <icarus@dabo.de>
Wed, 8 Aug 2018 20:32:11 +0000 (22:32 +0200)
committerHypolite Petovan <mrpetovan@eml.cc>
Wed, 8 Aug 2018 20:32:11 +0000 (22:32 +0200)
* Issue 5158: Ignore all threads, even public ones

* Remove some notice

* Now it really should work

* Using "defaults"

boot.php
config/dbstructure.json
database.sql
include/enotify.php
mod/ignored.php
src/Model/Item.php
src/Object/Post.php

index ab73c6dedde81357f74c18a0eca353dafc97deb5..ebdb58236b2d9fd968eb3f4e5ec4243eda811ff3 100644 (file)
--- 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);
 
 /**
index fce2fcf930d72619783505ad7874e0feeaa46819..2c1ecddc56692cc6168e14beb21e321776d8f2d9 100644 (file)
                "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"]
index 528932846297541c0bf83d90dd06d34608a88a40..0dbeb80dd0741d5d58b070ee1c6e9c63184d6073 100644 (file)
@@ -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';
 
index 6d27aa8897136fecf5f9e0ea76563d7a21ad2acf..eb539c69f4dc91d8cf528c54b6ae63001359cedf 100644 (file)
@@ -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;
        }
index 0379d2d94509e52f5a6db230842d0533c90b5fce..f42e3a8bd3571d1a9d8024ffe2cd2fb67eda4a01 100644 (file)
@@ -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);
        }
index 6d0b1901bdc9fbc4b2ced855ccd5591e515cc60f..3b491cbe863f6e612ffd6a7d2d1087b286c7c1e1 100644 (file)
@@ -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) {
index a055f6525194b42d8ddda932de8647316ef6def6..05b21ebd4c7e2e23b571d3414b898b740ca91dd0 100644 (file)
@@ -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"),