]> git.mxchange.org Git - friendica.git/commitdiff
Preparations for "featured" posts
authorMichael <heluecht@pirati.ca>
Wed, 6 Apr 2022 13:34:11 +0000 (13:34 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 6 Apr 2022 13:34:11 +0000 (13:34 +0000)
database.sql
doc/database.md
doc/database/db_post-collection.md [new file with mode: 0644]
src/Model/APContact.php
src/Model/Post/Collection.php [new file with mode: 0644]
src/Protocol/ActivityPub/Processor.php
static/dbstructure.config.php
static/dbview.config.php

index 1f35cd0573cb40bc93a7a7e746d587a79cd3f46d..d52abf1ccbf8d9ce024c43543f79791f4efe888e 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1455
+-- DB_UPDATE_VERSION 1456
 -- ------------------------------------------
 
 
@@ -1062,6 +1062,17 @@ CREATE TABLE IF NOT EXISTS `post-category` (
        FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
 
+--
+-- TABLE post-collection
+--
+CREATE TABLE IF NOT EXISTS `post-collection` (
+       `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
+       `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
+        PRIMARY KEY(`uri-id`,`type`),
+        INDEX `type` (`type`),
+       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Collection of posts';
+
 --
 -- TABLE post-content
 --
@@ -1617,6 +1628,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `post-thread-user`.`origin` AS `parent-origin`,
        `post-thread-user`.`mention` AS `mention`,
        `post-user`.`global` AS `global`,
+       EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
        `post-user`.`network` AS `network`,
        `post-user`.`vid` AS `vid`,
        `post-user`.`psid` AS `psid`,
@@ -1777,6 +1789,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `post-thread-user`.`origin` AS `origin`,
        `post-thread-user`.`mention` AS `mention`,
        `post-user`.`global` AS `global`,
+       EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
        `post-thread-user`.`network` AS `network`,
        `post-user`.`vid` AS `vid`,
        `post-thread-user`.`psid` AS `psid`,
@@ -1923,6 +1936,7 @@ CREATE VIEW `post-view` AS SELECT
        `post`.`visible` AS `visible`,
        `post`.`deleted` AS `deleted`,
        `post`.`global` AS `global`,
+       EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
        `post`.`network` AS `network`,
        `post`.`vid` AS `vid`,
        IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
@@ -2044,6 +2058,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `post`.`visible` AS `visible`,
        `post`.`deleted` AS `deleted`,
        `post`.`global` AS `global`,
+       EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
        `post-thread`.`network` AS `network`,
        `post`.`vid` AS `vid`,
        IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
index f64434b8868df11729686d11971231d940b7cc1c..d436dcc32bcc577047ec2aaa94170f55367741e2 100644 (file)
@@ -47,6 +47,7 @@ Database Tables
 | [photo](help/database/db_photo) | photo storage |
 | [post](help/database/db_post) | Structure for all posts |
 | [post-category](help/database/db_post-category) | post relation to categories |
+| [post-collection](help/database/db_post-collection) | Collection of posts |
 | [post-content](help/database/db_post-content) | Content for all posts |
 | [post-delivery-data](help/database/db_post-delivery-data) | Delivery data for items |
 | [post-link](help/database/db_post-link) | Post related external links |
diff --git a/doc/database/db_post-collection.md b/doc/database/db_post-collection.md
new file mode 100644 (file)
index 0000000..1e8e368
--- /dev/null
@@ -0,0 +1,29 @@
+Table post-collection
+===========
+
+Collection of posts
+
+Fields
+------
+
+| Field  | Description                                               | Type             | Null | Key | Default | Extra |
+| ------ | --------------------------------------------------------- | ---------------- | ---- | --- | ------- | ----- |
+| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned     | NO   | PRI | NULL    |       |
+| type   |                                                           | tinyint unsigned | NO   | PRI | 0       |       |
+
+Indexes
+------------
+
+| Name    | Fields       |
+| ------- | ------------ |
+| PRIMARY | uri-id, type |
+| type    | type         |
+
+Foreign Keys
+------------
+
+| Field | Target Table | Target Field |
+|-------|--------------|--------------|
+| uri-id | [item-uri](help/database/db_item-uri) | id |
+
+Return to [database documentation](help/database)
index deed6299de8613f8c3c6fe78a15e0768651a81c0..e068ecefe2b9d534c6c10c5639f27cee90ddfab0 100644 (file)
@@ -39,7 +39,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\JsonLD;
 use Friendica\Util\Network;
-use Friendica\Util\Strings;
 
 class APContact
 {
diff --git a/src/Model/Post/Collection.php b/src/Model/Post/Collection.php
new file mode 100644 (file)
index 0000000..cf968d6
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Model\Post;
+
+use Friendica\Database\DBA;
+use \BadMethodCallException;
+use Friendica\Database\Database;
+
+class Collection
+{
+       const FEATURED = 0;
+
+       /**
+        * Add a post to a collection
+        *
+        * @param integer $uri_id
+        * @param integer $type
+        */
+       public static function add(int $uri_id, int $type)
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               DBA::insert('post-collection', ['uri-id' => $uri_id, 'type' => $type], Database::INSERT_IGNORE);
+       }
+
+       /**
+        * Remove a post from a collection
+        *
+        * @param integer $uri_id
+        * @param integer $type
+        */
+       public static function remove(int $uri_id, int $type)
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               DBA::delete('post-collection', ['uri-id' => $uri_id, 'type' => $type]);
+       }
+}
index 5604043fa42e49acbd44ddc8dc0e26f381523276..b8758a0c82ef5274c45a2f013e5615e13a831c8a 100644 (file)
@@ -492,7 +492,7 @@ class Processor
 
                Logger::debug('Add post to featured collection', ['uri-id' => $uriid]);
 
-               // @todo Add functionality
+               Post\Collection::add($uriid, Post\Collection::FEATURED);
        }
 
        /**
@@ -509,7 +509,7 @@ class Processor
 
                Logger::debug('Remove post from featured collection', ['uri-id' => $uriid]);
 
-               // @todo Add functionality
+               Post\Collection::remove($uriid, Post\Collection::FEATURED);
        }
 
        /**
index 95daab46494d9570d61083d8357f46df624fcaa8..7d3904444bd77a0139b4b55aeee03fe4ad93e307 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1455);
+       define('DB_UPDATE_VERSION', 1456);
 }
 
 return [
@@ -1103,6 +1103,17 @@ return [
                        "uid" => ["uid"],
                ]
        ],
+       "post-collection" => [
+               "comment" => "Collection of posts",
+               "fields" => [
+                       "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uri-id", "type"],
+                       "type" => ["type"],
+               ]
+       ],
        "post-content" => [
                "comment" => "Content for all posts",
                "fields" => [
index a5c52c9b1343b36f47cc1ffb6a0794ac8c6beeb3..f0a421484c18cc5238f965db1f18f066e9dfd3a6 100644 (file)
@@ -93,6 +93,7 @@
                        "parent-origin" => ["post-thread-user", "origin"],
                        "mention" => ["post-thread-user", "mention"],
                        "global" => ["post-user", "global"],
+                       "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`)",
                        "network" => ["post-user", "network"],
                        "vid" => ["post-user", "vid"],
                        "psid" => ["post-user", "psid"],
                        "origin" => ["post-thread-user", "origin"],
                        "mention" => ["post-thread-user", "mention"],
                        "global" => ["post-user", "global"],
+                       "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`)",
                        "network" => ["post-thread-user", "network"],
                        "vid" => ["post-user", "vid"],
                        "psid" => ["post-thread-user", "psid"],
                        "visible" => ["post", "visible"],
                        "deleted" => ["post", "deleted"],
                        "global" => ["post", "global"],
+                       "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`)",
                        "network" => ["post", "network"],
                        "vid" => ["post", "vid"],
                        "verb" => "IF (`post`.`vid` IS NULL, '', `verb`.`name`)",
                        "visible" => ["post", "visible"],
                        "deleted" => ["post", "deleted"],
                        "global" => ["post", "global"],
+                       "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`)",
                        "network" => ["post-thread", "network"],
                        "vid" => ["post", "vid"],
                        "verb" => "IF (`post`.`vid` IS NULL, '', `verb`.`name`)",