From 4bfd0abec73c028a85aa143dc1fd704c5e3c2f54 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Jan 2020 12:21:42 +0000 Subject: [PATCH] New "UserItem" class, new notification type field --- database.sql | 5 ++- src/Model/UserItem.php | 85 +++++++++++++++++++++++++++++++++++ static/dbstructure.config.php | 5 ++- 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/Model/UserItem.php diff --git a/database.sql b/database.sql index 6a55db5269..02d1ac895c 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ --- Friendica 2019.12-rc (Dalmatian Bellflower) --- DB_UPDATE_VERSION 1328 +-- Friendica 2020.03-dev (Dalmatian Bellflower) +-- DB_UPDATE_VERSION 1329 -- ------------------------------------------ @@ -1285,6 +1285,7 @@ CREATE TABLE IF NOT EXISTS `user-item` ( `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user', `ignored` boolean COMMENT 'Ignore this thread if set', `pinned` boolean COMMENT 'The item is pinned on the profile page', + `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', PRIMARY KEY(`uid`,`iid`), INDEX `uid_pinned` (`uid`,`pinned`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data'; diff --git a/src/Model/UserItem.php b/src/Model/UserItem.php new file mode 100644 index 0000000000..26c42f1093 --- /dev/null +++ b/src/Model/UserItem.php @@ -0,0 +1,85 @@ + $item['contact-id'], 'notify_new_posts' => true])) { + return true; + } + + // Or the contact is a mentioned forum + $tags = DBA::select('term', ['url'], ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => TERM_MENTION, 'uid' => $uid]); + while ($tag = DBA::fetch($tags)) { + $condition = ['nurl' => Strings::normaliseLink($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY]; + if (DBA::exists('contact', $condition)) { + return true; + } + } + + return false; + } + + // Is the user mentioned in this post? + private static function checkTagged($item, $uid) + { + if ($item["mention"]) { + return true; + } + + foreach ($profiles AS $profile) { + if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]")) + return true; + } + + if ($defaulttype == NOTIFY_TAGSELF) { + return true; + } + + return false; + } + + private static function checkCommented($item, $uid) + { + // Is it a post that the user had started? + $fields = ['ignored', 'mention']; + $thread = Item::selectFirstThreadForUser($uid, $fields, ['iid' => $item["parent"], 'deleted' => false]); + + if ($thread['mention'] && !$thread['ignored']) { + return true; + } + + // And now we check for participation of one of our contacts in the thread + $condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false]; + + if (!$thread['ignored'] && Item::exists($condition)) { + return true; + } + + return false; + } +} diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index ada837fb26..a7d851943d 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -34,7 +34,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1328); + define('DB_UPDATE_VERSION', 1329); } return [ @@ -1388,7 +1388,8 @@ return [ "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"], "ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"], - "pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"] + "pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"], + "notification-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], ], "indexes" => [ "PRIMARY" => ["uid", "iid"], -- 2.39.5