-- ------------------------------------------
-- Friendica 2023.09-dev (Giant Rhubarb)
--- DB_UPDATE_VERSION 1533
+-- DB_UPDATE_VERSION 1534
-- ------------------------------------------
`media-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Type of media in a bit array (1 = image, 2 = video, 4 = audio',
`language` varbinary(128) COMMENT 'Language information about this post',
`created` datetime COMMENT '',
+ `restricted` boolean NOT NULL DEFAULT '0' COMMENT 'If true, this post is either unlisted or not from a federated network',
`comments` mediumint unsigned COMMENT 'Number of comments',
`activities` mediumint unsigned COMMENT 'Number of activities (like, dislike, ...)',
PRIMARY KEY(`uri-id`),
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 | |
-| owner-id | Item owner | int unsigned | NO | | 0 | |
-| contact-type | Person, organisation, news, community, relay | tinyint | NO | | 0 | |
-| media-type | Type of media in a bit array (1 = image, 2 = video, 4 = audio | tinyint | NO | | 0 | |
-| language | Language information about this post | varbinary(128) | YES | | NULL | |
-| 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 | |
+| media-type | Type of media in a bit array (1 = image, 2 = video, 4 = audio | tinyint | NO | | 0 | |
+| language | Language information about this post | varbinary(128) | YES | | NULL | |
+| created | | datetime | YES | | NULL | |
+| restricted | If true, this post is either unlisted or not from a federated network | boolean | NO | | 0 | |
+| comments | Number of comments | mediumint unsigned | YES | | NULL | |
+| activities | Number of activities (like, dislike, ...) | mediumint unsigned | YES | | NULL | |
Indexes
------------
}
}
- Post::insert($item['uri-id'], $item);
+ $inserted = Post::insert($item['uri-id'], $item);
if ($item['gravity'] == self::GRAVITY_PARENT) {
Post\Thread::insert($item['uri-id'], $item);
self::updateDisplayCache($posted_item['uri-id']);
}
- Post\Engagement::storeFromItem($posted_item);
+ if ($inserted) {
+ Post\Engagement::storeFromItem($posted_item);
+ }
return $post_user_id;
}
*
* @param integer $uri_id
* @param array $fields
- * @return int ID of inserted post
+ * @return bool Success of the insert process
* @throws \Exception
*/
- public static function insert(int $uri_id, array $data = []): int
+ public static function insert(int $uri_id, array $data = []): bool
{
if (empty($uri_id)) {
throw new BadMethodCallException('Empty URI_id');
// Additionally assign the key fields
$fields['uri-id'] = $uri_id;
- if (!DBA::insert('post', $fields, Database::INSERT_IGNORE)) {
- return 0;
- }
-
- return DBA::lastInsertId();
+ return DBA::insert('post', $fields, Database::INSERT_IGNORE);
}
/**
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post;
+use Friendica\Model\Tag;
use Friendica\Model\Verb;
use Friendica\Protocol\Activity;
+use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
// Channel
*/
public static function storeFromItem(array $item)
{
- if (!in_array($item['network'], Protocol::FEDERATED)) {
- Logger::debug('No federated network', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'network' => $item['network']]);
- return;
- }
-
- if (($item['uid'] != 0) && ($item['gravity'] == Item::GRAVITY_COMMENT)) {
- Logger::debug('Non public comments are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
- return;
- }
-
if (in_array($item['verb'], [Activity::FOLLOW, Activity::VIEW, Activity::READ])) {
Logger::debug('Technical activities are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'verb' => $item['verb']]);
return;
}
$parent = Post::selectFirst(['created', 'owner-id', 'uid', 'private', 'contact-contact-type', 'language'], ['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;
- }
if ($parent['created'] < DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')) {
Logger::debug('Post is too old', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'created' => $parent['created']]);
$store = Contact::hasFollowers($parent['owner-id']);
}
+ if (!$store) {
+ $tagList = Relay::getSubscribedTags();
+ foreach (array_column(Tag::getByURIId($item['parent-uri-id'], [Tag::HASHTAG]), 'name') as $tag) {
+ if (in_array($tag, $tagList)) {
+ $store = true;
+ }
+ }
+ }
+
$mediatype = self::getMediaType($item['parent-uri-id']);
if (!$store) {
'media-type' => $mediatype,
'language' => $parent['language'],
'created' => $parent['created'],
+ 'restricted' => !in_array($item['network'], Protocol::FEDERATED) || ($parent['private'] != Item::PUBLIC),
'comments' => DBA::count('post', ['parent-uri-id' => $item['parent-uri-id'], 'gravity' => Item::GRAVITY_COMMENT]),
'activities' => DBA::count('post', [
"`parent-uri-id` = ? AND `gravity` = ? AND NOT `vid` IN (?, ?, ?)",
])
];
if (!$store && ($engagement['comments'] == 0) && ($engagement['activities'] == 0)) {
- Logger::debug('No media, follower, comments or activities. Engagement not stored', ['fields' => $engagement]);
+ Logger::debug('No media, follower, subscribed tags, comments or activities. Engagement not stored', ['fields' => $engagement]);
return;
}
$ret = DBA::insert('post-engagement', $engagement, Database::INSERT_UPDATE);
];
}
- if (in_array($contact['network'], Protocol::FEDERATED)) {
- $channel_settings_label = $this->t('Channel Settings');
- $channel_frequency = Contact\User::getChannelFrequency($contact['id'], $this->session->getLocalUserId());
- } else {
- $channel_settings_label = null;
- $channel_frequency = null;
- }
+ $channel_settings_label = $this->t('Channel Settings');
+ $channel_frequency = Contact\User::getChannelFrequency($contact['id'], $this->session->getLocalUserId());
$poll_interval = null;
if ((($contact['network'] == Protocol::FEED) && !$this->config->get('system', 'adjust_poll_frequency')) || ($contact['network'] == Protocol::MAIL)) {
$condition = $this->addLanguageCondition($uid, $condition);
}
+ $condition = DBA::mergeConditions($condition, ["(NOT `restricted` OR EXISTS(SELECT `id` FROM `post-user` WHERE `uid` = ? AND `uri-id` = `post-engagement`.`uri-id`))", $uid]);
+
$condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed` OR `is-blocked` OR `channel-frequency` = ?))", $uid, Contact\User::FREQUENCY_NEVER]);
if (($this->selectedTab != TimelineEntity::WHATSHOT) && !is_null($this->accountType)) {
return $comments;
}
- $condition = ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0];
+ $condition = ["`contact-type` != ? AND `comments` > ? AND NOT `restricted`", Contact::TYPE_COMMUNITY, 0];
$condition = $this->addLanguageCondition($uid, $condition);
$limit = $this->database->count('post-engagement', $condition) / $divider;
return $activities;
}
- $condition = ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0];
+ $condition = ["`contact-type` != ? AND `activities` > ? AND NOT `restricted`", Contact::TYPE_COMMUNITY, 0];
$condition = $this->addLanguageCondition($uid, $condition);
$limit = $this->database->count('post-engagement', $condition) / $divider;
$body = ActivityPub\Processor::normalizeMentionLinks($body);
- $systemTags = [];
- $userTags = [];
$denyTags = [];
if ($scope == self::SCOPE_TAGS) {
- $server_tags = $config->get('system', 'relay_server_tags');
- $tagitems = explode(',', mb_strtolower($server_tags));
- foreach ($tagitems as $tag) {
- $systemTags[] = trim($tag, '# ');
- }
-
- if ($config->get('system', 'relay_user_tags')) {
- $userTags = Search::getUserTags();
- }
+ $tagList = self::getSubscribedTags();
+ } else {
+ $tagList = [];
}
- $tagList = array_unique(array_merge($systemTags, $userTags));
-
$deny_tags = $config->get('system', 'relay_deny_tags');
$tagitems = explode(',', mb_strtolower($deny_tags));
foreach ($tagitems as $tag) {
return false;
}
+ /**
+ * Get a list of subscribed tags by both the users and the tags that are defined by the admin
+ *
+ * @return array
+ */
+ public static function getSubscribedTags(): array
+ {
+ $systemTags = [];
+ $server_tags = DI::config()->get('system', 'relay_server_tags');
+
+ foreach (explode(',', mb_strtolower($server_tags)) as $tag) {
+ $systemTags[] = trim($tag, '# ');
+ }
+
+ if (DI::config()->get('system', 'relay_user_tags')) {
+ $userTags = Search::getUserTags();
+ } else {
+ $userTags = [];
+ }
+
+ return array_unique(array_merge($systemTags, $userTags));
+ }
+
/**
* Detect the language of a post and decide if the post should be accepted
*
// This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1533);
+ define('DB_UPDATE_VERSION', 1534);
}
return [
"media-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Type of media in a bit array (1 = image, 2 = video, 4 = audio"],
"language" => ["type" => "varbinary(128)", "comment" => "Language information about this post"],
"created" => ["type" => "datetime", "comment" => ""],
+ "restricted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "If true, this post is either unlisted or not from a federated network"],
"comments" => ["type" => "mediumint unsigned", "comment" => "Number of comments"],
"activities" => ["type" => "mediumint unsigned", "comment" => "Number of activities (like, dislike, ...)"],
],