]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/2021.06-rc' into public-timeline
authorMichael <heluecht@pirati.ca>
Wed, 16 Jun 2021 21:01:20 +0000 (21:01 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 16 Jun 2021 21:01:20 +0000 (21:01 +0000)
database.sql
src/Factory/Api/Mastodon/Status.php
src/Model/Post.php
src/Module/Api/Mastodon/Preferences.php
src/Module/Api/Mastodon/Statuses/FavouritedBy.php
src/Module/Api/Mastodon/Statuses/RebloggedBy.php
src/Module/Api/Mastodon/Timelines/PublicTimeline.php
static/dbstructure.config.php
static/dbview.config.php

index cc2e4b790a487531dccd6b6ee090e902b4c72881..7102b40df63003654416751f65a71599c18954b2 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.06-rc (Siberian Iris)
--- DB_UPDATE_VERSION 1421
+-- DB_UPDATE_VERSION 1422
 -- ------------------------------------------
 
 
@@ -1874,7 +1874,9 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `parent-post`.`author-id` AS `parent-author-id`,
        `parent-post-author`.`url` AS `parent-author-link`,
        `parent-post-author`.`name` AS `parent-author-name`,
-       `parent-post-author`.`network` AS `parent-author-network`
+       `parent-post-author`.`network` AS `parent-author-network`,
+       `parent-post-author`.`blocked` AS `parent-author-blocked`,
+       `parent-post-author`.`hidden` AS `parent-author-hidden`
        FROM `post-thread-user`
                        INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
                        STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
@@ -1938,6 +1940,31 @@ CREATE VIEW `post-view` AS SELECT
        `post-content`.`target-type` AS `target-type`,
        `post-content`.`target` AS `target`,
        `post-content`.`resource-id` AS `resource-id`,
+       `post`.`author-id` AS `contact-id`,
+       `author`.`url` AS `contact-link`,
+       `author`.`addr` AS `contact-addr`,
+       `author`.`name` AS `contact-name`,
+       `author`.`nick` AS `contact-nick`,
+       `author`.`thumb` AS `contact-avatar`,
+       `author`.`network` AS `contact-network`,
+       `author`.`blocked` AS `contact-blocked`,
+       `author`.`hidden` AS `contact-hidden`,
+       `author`.`readonly` AS `contact-readonly`,
+       `author`.`archive` AS `contact-archive`,
+       `author`.`pending` AS `contact-pending`,
+       `author`.`rel` AS `contact-rel`,
+       `author`.`uid` AS `contact-uid`,
+       `author`.`contact-type` AS `contact-contact-type`,
+       IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
+       false AS `self`,
+       `author`.`id` AS `cid`,
+       `author`.`alias` AS `alias`,
+       `author`.`photo` AS `photo`,
+       `author`.`name-date` AS `name-date`,
+       `author`.`uri-date` AS `uri-date`,
+       `author`.`avatar-date` AS `avatar-date`,
+       `author`.`thumb` AS `thumb`,
+       `author`.`dfrn-id` AS `dfrn-id`,
        `post`.`author-id` AS `author-id`,
        `author`.`url` AS `author-link`,
        `author`.`addr` AS `author-addr`,
@@ -1973,7 +2000,9 @@ CREATE VIEW `post-view` AS SELECT
        `parent-post`.`author-id` AS `parent-author-id`,
        `parent-post-author`.`url` AS `parent-author-link`,
        `parent-post-author`.`name` AS `parent-author-name`,
-       `parent-post-author`.`network` AS `parent-author-network`
+       `parent-post-author`.`network` AS `parent-author-network`,
+       `parent-post-author`.`blocked` AS `parent-author-blocked`,
+       `parent-post-author`.`hidden` AS `parent-author-hidden`
        FROM `post`
                        STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
                        STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
@@ -2033,6 +2062,31 @@ CREATE VIEW `post-thread-view` AS SELECT
        `post-content`.`target-type` AS `target-type`,
        `post-content`.`target` AS `target`,
        `post-content`.`resource-id` AS `resource-id`,
+       `post-thread`.`author-id` AS `contact-id`,
+       `author`.`url` AS `contact-link`,
+       `author`.`addr` AS `contact-addr`,
+       `author`.`name` AS `contact-name`,
+       `author`.`nick` AS `contact-nick`,
+       `author`.`thumb` AS `contact-avatar`,
+       `author`.`network` AS `contact-network`,
+       `author`.`blocked` AS `contact-blocked`,
+       `author`.`hidden` AS `contact-hidden`,
+       `author`.`readonly` AS `contact-readonly`,
+       `author`.`archive` AS `contact-archive`,
+       `author`.`pending` AS `contact-pending`,
+       `author`.`rel` AS `contact-rel`,
+       `author`.`uid` AS `contact-uid`,
+       `author`.`contact-type` AS `contact-contact-type`,
+       IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
+       false AS `self`,
+       `author`.`id` AS `cid`,
+       `author`.`alias` AS `alias`,
+       `author`.`photo` AS `photo`,
+       `author`.`name-date` AS `name-date`,
+       `author`.`uri-date` AS `uri-date`,
+       `author`.`avatar-date` AS `avatar-date`,
+       `author`.`thumb` AS `thumb`,
+       `author`.`dfrn-id` AS `dfrn-id`,
        `post-thread`.`author-id` AS `author-id`,
        `author`.`url` AS `author-link`,
        `author`.`addr` AS `author-addr`,
@@ -2068,7 +2122,9 @@ CREATE VIEW `post-thread-view` AS SELECT
        `parent-post`.`author-id` AS `parent-author-id`,
        `parent-post-author`.`url` AS `parent-author-link`,
        `parent-post-author`.`name` AS `parent-author-name`,
-       `parent-post-author`.`network` AS `parent-author-network`
+       `parent-post-author`.`network` AS `parent-author-network`,
+       `parent-post-author`.`blocked` AS `parent-author-blocked`,
+       `parent-post-author`.`hidden` AS `parent-author-hidden`
        FROM `post-thread`
                        INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
                        STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
index 1312cb7f476119ea240721f2d54981a3ee8faf2c..c5e18219d1626c8dc20bc423745444a150624121 100644 (file)
@@ -72,9 +72,9 @@ class Status extends BaseFactory
                $account = DI::mstdnAccount()->createFromContactId($item['author-id']);
 
                $counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
-                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], [], false),
-                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE), 'deleted' => false], [], false),
-                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false], [], false)
+                       Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], []),
+                       Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE), 'deleted' => false], []),
+                       Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false], [])
                );
 
                $userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
index 2dc73446be188955ff7d38d48bc6da3f0f7eabbf..902525f9922415b738ef85ae3bfdffbdc1dc45f1 100644 (file)
@@ -124,24 +124,22 @@ class Post
        }
 
        /**
-        * Check if post data exists
+        * Check if post-user-view records exists
         *
         * @param array $condition array of fields for condition
-        * @param bool  $user_mode true = post-user-view, false = post-view
         *
         * @return boolean Are there rows for that condition?
         * @throws \Exception
         */
-       public static function exists($condition, bool $user_mode = true) {
-               return DBA::exists($user_mode ? 'post-user-view' : 'post-view', $condition);
+       public static function exists($condition) {
+               return DBA::exists('post-user-view', $condition);
        }
 
        /**
-        * Counts the posts satisfying the provided condition
+        * Counts the post-user-view records satisfying the provided condition
         *
         * @param array        $condition array of fields for condition
         * @param array        $params    Array of several parameters
-        * @param bool         $user_mode true = post-user-view, false = post-view
         *
         * @return int
         *
@@ -153,13 +151,34 @@ class Post
         * $count = Post::count($condition);
         * @throws \Exception
         */
-       public static function count(array $condition = [], array $params = [], bool $user_mode = true)
+       public static function count(array $condition = [], array $params = [])
+       {
+               return DBA::count('post-user-view', $condition, $params);
+       }
+
+       /**
+        * Counts the post-view records satisfying the provided condition
+        *
+        * @param array        $condition array of fields for condition
+        * @param array        $params    Array of several parameters
+        *
+        * @return int
+        *
+        * Example:
+        * $condition = ["network" => 'dspr'];
+        * or:
+        * $condition = ["`network` IN (?, ?)", 1, 'dfrn', 'dspr'];
+        *
+        * $count = Post::count($condition);
+        * @throws \Exception
+        */
+       public static function countPosts(array $condition = [], array $params = [])
        {
-               return DBA::count($user_mode ? 'post-user-view' : 'post-view', $condition, $params);
+               return DBA::count('post-view', $condition, $params);
        }
 
        /**
-        * Retrieve a single record from the post table and returns it in an associative array
+        * Retrieve a single record from the post-user-view view and returns it in an associative array
         *
         * @param array $fields
         * @param array $condition
@@ -169,11 +188,11 @@ class Post
         * @throws \Exception
         * @see   DBA::select
         */
-       public static function selectFirst(array $fields = [], array $condition = [], $params = [], bool $user_mode = true)
+       public static function selectFirst(array $fields = [], array $condition = [], $params = [])
        {
                $params['limit'] = 1;
 
-               $result = self::select($fields, $condition, $params, $user_mode);
+               $result = self::select($fields, $condition, $params);
 
                if (is_bool($result)) {
                        return $result;
@@ -185,7 +204,32 @@ class Post
        }
 
        /**
-        * Retrieve a single record from the post-thread table and returns it in an associative array
+        * Retrieve a single record from the post-view view and returns it in an associative array
+        *
+        * @param array $fields
+        * @param array $condition
+        * @param array $params
+        * @return bool|array
+        * @throws \Exception
+        * @see   DBA::select
+        */
+       public static function selectFirstPost(array $fields = [], array $condition = [], $params = [])
+       {
+               $params['limit'] = 1;
+
+               $result = self::selectPosts($fields, $condition, $params);
+
+               if (is_bool($result)) {
+                       return $result;
+               } else {
+                       $row = self::fetch($result);
+                       DBA::close($result);
+                       return $row;
+               }
+       }
+
+       /**
+        * Retrieve a single record from the post-thread-user-view view and returns it in an associative array
         *
         * @param array $fields
         * @param array $condition
@@ -210,7 +254,7 @@ class Post
        }
 
        /**
-        * Select rows from the post table and returns them as an array
+        * Select rows from the post-user-view view and returns them as an array
         *
         * @param array $selected  Array of selected fields, empty for all
         * @param array $condition Array of fields for condition
@@ -263,23 +307,37 @@ class Post
        }
 
        /**
-        * Select rows from the post table
+        * Select rows from the post-user-view view
         *
         * @param array $selected  Array of selected fields, empty for all
         * @param array $condition Array of fields for condition
         * @param array $params    Array of several parameters
-        * @param bool  $user_mode true = post-user-view, false = post-view
         *
         * @return boolean|object
         * @throws \Exception
         */
-       public static function select(array $selected = [], array $condition = [], $params = [], bool $user_mode = true)
+       public static function select(array $selected = [], array $condition = [], $params = [])
        {
-               return self::selectView($user_mode ? 'post-user-view' : 'post-view', $selected, $condition, $params);
+               return self::selectView('post-user-view', $selected, $condition, $params);
        }
 
        /**
-        * Select rows from the post table
+        * Select rows from the post-view view
+        *
+        * @param array $selected  Array of selected fields, empty for all
+        * @param array $condition Array of fields for condition
+        * @param array $params    Array of several parameters
+        *
+        * @return boolean|object
+        * @throws \Exception
+        */
+       public static function selectPosts(array $selected = [], array $condition = [], $params = [])
+       {
+               return self::selectView('post-view', $selected, $condition, $params);
+       }
+
+       /**
+        * Select rows from the post-thread-user-view view
         *
         * @param array $selected  Array of selected fields, empty for all
         * @param array $condition Array of fields for condition
@@ -336,7 +394,7 @@ class Post
        }
 
        /**
-        * Select rows from the post view for a given user
+        * Select rows from the post-user-view view for a given user
         *
         * @param integer $uid       User ID
         * @param array   $selected  Array of selected fields, empty for all
@@ -351,8 +409,24 @@ class Post
                return self::selectViewForUser('post-user-view', $uid, $selected, $condition, $params);
        }
 
-               /**
-        * Select rows from the post view for a given user
+       /**
+        * Select rows from the post-view view for a given user
+        *
+        * @param integer $uid       User ID
+        * @param array   $selected  Array of selected fields, empty for all
+        * @param array   $condition Array of fields for condition
+        * @param array   $params    Array of several parameters
+        *
+        * @return boolean|object
+        * @throws \Exception
+        */
+       public static function selectPostsForUser($uid, array $selected = [], array $condition = [], $params = [])
+       {
+               return self::selectViewForUser('post-view', $uid, $selected, $condition, $params);
+       }
+
+       /**
+        * Select rows from the post-thread-user-view view for a given user
         *
         * @param integer $uid       User ID
         * @param array   $selected  Array of selected fields, empty for all
@@ -368,7 +442,7 @@ class Post
        }
 
        /**
-        * Retrieve a single record from the post view for a given user and returns it in an associative array
+        * Retrieve a single record from the post-user-view view for a given user and returns it in an associative array
         *
         * @param integer $uid User ID
         * @param array   $selected
@@ -394,7 +468,7 @@ class Post
        }
 
        /**
-        * Select pinned rows from the item table for a given user
+        * Select pinned rows from the post-thread-user table for a given user
         *
         * @param integer $uid       User ID
         * @param array   $selected  Array of selected fields, empty for all
index 8ac70e75996fbd0ea08bad834fe09138006ceb4c..d54bd85fa12cc49db55158f039b6218bec480d39 100644 (file)
@@ -52,7 +52,7 @@ class Preferences extends BaseApi
                $sensitive = false;
                $language  = $user['language'];
                $media     = DI::pConfig()->get($uid, 'nsfw', 'disable') ? 'show_all' : 'default';
-               $spoilers  = DI::pConfig()->get($uid, 'system', 'disable_cw');
+               $spoilers  = (bool)DI::pConfig()->get($uid, 'system', 'disable_cw');
 
                $preferences = new \Friendica\Object\Api\Mastodon\Preferences($visibility, $sensitive, $language, $media, $spoilers);
 
index cecf0336a551cc8576c16f8ef1eab1a838803c5c..67dc4b67fb6a958970343cdd2532bd2c274d2264 100644 (file)
@@ -49,7 +49,7 @@ class FavouritedBy extends BaseApi
                        DI::mstdnError()->RecordNotFound();
                }
 
-               $activities = Post::select(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE], [], false);
+               $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE]);
 
                $accounts = [];
 
index 9faf034ae74c0bed062ebe745dfc3a5bc5145232..11c15b41e15939b47ee32f330532188363ec6316 100644 (file)
@@ -49,7 +49,7 @@ class RebloggedBy extends BaseApi
                        DI::mstdnError()->RecordNotFound();
                }
 
-               $activities = Post::select(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE], [], false);
+               $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
 
                $accounts = [];
 
index bc617b65a8fde4cfd8f8d484f27989cd9d295a20..a00d51a60570b09441a8fd21a30d32a3ea5531da 100644 (file)
@@ -58,7 +58,7 @@ class PublicTimeline extends BaseApi
                $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
 
                $condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => Item::PUBLIC,
-                       'uid' => 0, 'network' => Protocol::FEDERATED, 'parent-author-blocked' => false, 'parent-author-hidden' => false];
+                       'network' => Protocol::FEDERATED, 'parent-author-blocked' => false, 'parent-author-hidden' => false];
 
                if ($request['local']) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
@@ -95,12 +95,12 @@ class PublicTimeline extends BaseApi
                                ["NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `parent-author-id` AND (`blocked` OR `ignored`))", $uid]);
                }
 
-               $items = Post::selectForUser($uid, ['uri-id', 'uid'], $condition, $params);
+               $items = Post::selectPostsForUser($uid, ['uri-id'], $condition, $params);
 
                $statuses = [];
                while ($item = Post::fetch($items)) {
                        self::setBoundaries($item['uri-id']);
-                       $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']);
+                       $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
                }
                DBA::close($items);
 
index 961321e0fa98b65fb2cbccdb762b66d47f631769..da33e234262f97e7eccc2bfef21a63c6fdd69757 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1421);
+       define('DB_UPDATE_VERSION', 1422);
 }
 
 return [
index 1582890e01169f24315add222f52ca3a381abb12..6dd8cfe3bd5792f707c8a3f0bfccea09470137c0 100644 (file)
                        "parent-author-link" => ["parent-post-author", "url"],
                        "parent-author-name" => ["parent-post-author", "name"],
                        "parent-author-network" => ["parent-post-author", "network"],
+                       "parent-author-blocked" => ["parent-post-author", "blocked"],
+                       "parent-author-hidden" => ["parent-post-author", "hidden"],
                ],
                "query" => "FROM `post-thread-user`
                        INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
                        "target-type" => ["post-content", "target-type"],
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
+                       "contact-id" => ["post", "author-id"],
+                       "contact-link" => ["author", "url"],
+                       "contact-addr" => ["author", "addr"],
+                       "contact-name" => ["author", "name"],
+                       "contact-nick" => ["author", "nick"],
+                       "contact-avatar" => ["author", "thumb"],
+                       "contact-network" => ["author", "network"],
+                       "contact-blocked" => ["author", "blocked"],
+                       "contact-hidden" => ["author", "hidden"],
+                       "contact-readonly" => ["author", "readonly"],
+                       "contact-archive" => ["author", "archive"],
+                       "contact-pending" => ["author", "pending"],
+                       "contact-rel" => ["author", "rel"],
+                       "contact-uid" => ["author", "uid"],
+                       "contact-contact-type" => ["author", "contact-type"],
+                       "writable" => "IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`)",
+                       "self" => "false",
+                       "cid" => ["author", "id"],
+                       "alias" => ["author", "alias"],
+                       "photo" => ["author", "photo"],
+                       "name-date" => ["author", "name-date"],
+                       "uri-date" => ["author", "uri-date"],
+                       "avatar-date" => ["author", "avatar-date"],
+                       "thumb" => ["author", "thumb"],
+                       "dfrn-id" => ["author", "dfrn-id"],
                        "author-id" => ["post", "author-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "parent-author-link" => ["parent-post-author", "url"],
                        "parent-author-name" => ["parent-post-author", "name"],
                        "parent-author-network" => ["parent-post-author", "network"],
+                       "parent-author-blocked" => ["parent-post-author", "blocked"],
+                       "parent-author-hidden" => ["parent-post-author", "hidden"],
                ],
                "query" => "FROM `post`
                        STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
                        "target-type" => ["post-content", "target-type"],
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
+                       "contact-id" => ["post-thread", "author-id"],
+                       "contact-link" => ["author", "url"],
+                       "contact-addr" => ["author", "addr"],
+                       "contact-name" => ["author", "name"],
+                       "contact-nick" => ["author", "nick"],
+                       "contact-avatar" => ["author", "thumb"],
+                       "contact-network" => ["author", "network"],
+                       "contact-blocked" => ["author", "blocked"],
+                       "contact-hidden" => ["author", "hidden"],
+                       "contact-readonly" => ["author", "readonly"],
+                       "contact-archive" => ["author", "archive"],
+                       "contact-pending" => ["author", "pending"],
+                       "contact-rel" => ["author", "rel"],
+                       "contact-uid" => ["author", "uid"],
+                       "contact-contact-type" => ["author", "contact-type"],
+                       "writable" => "IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`)",
+                       "self" => "false",
+                       "cid" => ["author", "id"],
+                       "alias" => ["author", "alias"],
+                       "photo" => ["author", "photo"],
+                       "name-date" => ["author", "name-date"],
+                       "uri-date" => ["author", "uri-date"],
+                       "avatar-date" => ["author", "avatar-date"],
+                       "thumb" => ["author", "thumb"],
+                       "dfrn-id" => ["author", "dfrn-id"],
                        "author-id" => ["post-thread", "author-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "parent-author-link" => ["parent-post-author", "url"],
                        "parent-author-name" => ["parent-post-author", "name"],
                        "parent-author-network" => ["parent-post-author", "network"],
+                       "parent-author-blocked" => ["parent-post-author", "blocked"],
+                       "parent-author-hidden" => ["parent-post-author", "hidden"],
                ],
                "query" => "FROM `post-thread`
                        INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`