From fdaff4303952427f222ee21f6b501d5087e25932 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 2 Sep 2023 14:19:52 +0000 Subject: [PATCH] Use the owner, not the author --- database.sql | 6 +++--- doc/database/db_post-engagement.md | 28 ++++++++++++++-------------- src/Model/Post/Engagement.php | 4 ++-- src/Module/Conversation/Channel.php | 8 ++++---- static/dbstructure.config.php | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/database.sql b/database.sql index 6bad8340a6..d5bc05faa6 100644 --- a/database.sql +++ b/database.sql @@ -1305,16 +1305,16 @@ CREATE TABLE IF NOT EXISTS `post-delivery-data` ( -- CREATE TABLE IF NOT EXISTS `post-engagement` ( `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri', - `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item', + `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner', `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Person, organisation, news, community, relay', `created` datetime COMMENT '', `comments` mediumint unsigned COMMENT 'Number of comments', `activities` mediumint unsigned COMMENT 'Number of activities (like, dislike, ...)', PRIMARY KEY(`uri-id`), - INDEX `author-id` (`author-id`), + INDEX `owner-id` (`owner-id`), INDEX `created` (`created`), FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, - FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT + FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Engagement data per post'; -- diff --git a/doc/database/db_post-engagement.md b/doc/database/db_post-engagement.md index e49881502c..8c4a2ae006 100644 --- a/doc/database/db_post-engagement.md +++ b/doc/database/db_post-engagement.md @@ -6,23 +6,23 @@ Engagement data per post 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 | | -| author-id | Link to the contact table with uid=0 of the author of this item | int unsigned | NO | | 0 | | -| contact-type | Person, organisation, news, community, relay | tinyint | NO | | 0 | | -| created | | datetime | YES | | NULL | | -| comments | Number of comments | mediumint unsigned | YES | | NULL | | -| activities | Number of activities (like, dislike, ...) | mediumint unsigned | YES | | NULL | | +| 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 | | +| owner-id | Item owner | int unsigned | NO | | 0 | | +| contact-type | Person, organisation, news, community, relay | tinyint | NO | | 0 | | +| created | | datetime | YES | | NULL | | +| comments | Number of comments | mediumint unsigned | YES | | NULL | | +| activities | Number of activities (like, dislike, ...) | mediumint unsigned | YES | | NULL | | Indexes ------------ -| Name | Fields | -| --------- | --------- | -| PRIMARY | uri-id | -| author-id | author-id | -| created | created | +| Name | Fields | +| -------- | -------- | +| PRIMARY | uri-id | +| owner-id | owner-id | +| created | created | Foreign Keys ------------ @@ -30,6 +30,6 @@ Foreign Keys | Field | Target Table | Target Field | |-------|--------------|--------------| | uri-id | [item-uri](help/database/db_item-uri) | id | -| author-id | [contact](help/database/db_contact) | id | +| owner-id | [contact](help/database/db_contact) | id | Return to [database documentation](help/database) diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index 040ba2f944..81ba625023 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -64,7 +64,7 @@ class Engagement return; } - $parent = Post::selectFirst(['created', 'author-id', 'uid', 'private', 'contact-contact-type'], ['uri-id' => $item['parent-uri-id']]); + $parent = Post::selectFirst(['created', 'owner-id', 'uid', 'private', 'contact-contact-type'], ['uri-id' => $item['parent-uri-id']]); if ($parent['private'] != Item::PUBLIC) { Logger::debug('Non public posts are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $parent['uid'], 'private' => $parent['private']]); return; @@ -77,7 +77,7 @@ class Engagement $engagement = [ 'uri-id' => $item['parent-uri-id'], - 'author-id' => $parent['author-id'], + 'owner-id' => $parent['owner-id'], 'contact-type' => $parent['contact-contact-type'], 'created' => $parent['created'], 'comments' => DBA::count('post', ['parent-uri-id' => $item['parent-uri-id'], 'gravity' => Item::GRAVITY_COMMENT]), diff --git a/src/Module/Conversation/Channel.php b/src/Module/Conversation/Channel.php index 42ca508be5..60488a2d4c 100644 --- a/src/Module/Conversation/Channel.php +++ b/src/Module/Conversation/Channel.php @@ -245,13 +245,13 @@ class Channel extends BaseModule } elseif (self::$content == self::FORYOU) { $cid = Contact::getPublicIdByUserId(DI::userSession()->getLocalUserId()); - $condition = ["(`author-id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `thread-score` > ?) OR - ((`comments` >= ? OR `activities` >= ?) AND `author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))) OR - ( `author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))", + $condition = ["(`owner-id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `thread-score` > ?) OR + ((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))) OR + ( `owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))", $cid, self::getMedianThreadScore($cid, 4), self::getMedianComments(4), self::getMedianActivities(4), DI::userSession()->getLocalUserId(), Contact::FRIEND, Contact::SHARING, DI::userSession()->getLocalUserId(), Contact::FRIEND, Contact::SHARING]; } elseif (self::$content == self::FOLLOWERS) { - $condition = ["`author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", DI::userSession()->getLocalUserId(), Contact::FOLLOWER]; + $condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", DI::userSession()->getLocalUserId(), Contact::FOLLOWER]; } if ((self::$content != self::WHATSHOT) && !is_null(self::$accountType)) { diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 8912e4982d..3403a74692 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1327,7 +1327,7 @@ return [ "comment" => "Engagement data per post", "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"], - "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"], + "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"], "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Person, organisation, news, community, relay"], "created" => ["type" => "datetime", "comment" => ""], "comments" => ["type" => "mediumint unsigned", "comment" => "Number of comments"], @@ -1335,7 +1335,7 @@ return [ ], "indexes" => [ "PRIMARY" => ["uri-id"], - "author-id" => ["author-id"], + "owner-id" => ["owner-id"], "created" => ["created"], ] ], -- 2.39.5