mirror of
https://github.com/friendica/friendica
synced 2025-05-04 07:04:10 +02:00
Use channels for non public content
This commit is contained in:
parent
a1f6e6e871
commit
b00c2070d7
9 changed files with 67 additions and 58 deletions
|
@ -1250,7 +1250,7 @@ class Item
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1405,7 +1405,9 @@ class Item
|
|||
self::updateDisplayCache($posted_item['uri-id']);
|
||||
}
|
||||
|
||||
Post\Engagement::storeFromItem($posted_item);
|
||||
if ($inserted) {
|
||||
Post\Engagement::storeFromItem($posted_item);
|
||||
}
|
||||
|
||||
return $post_user_id;
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ class Post
|
|||
*
|
||||
* @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');
|
||||
|
@ -50,11 +50,7 @@ class Post
|
|||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,8 +29,10 @@ use Friendica\DI;
|
|||
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
|
||||
|
@ -45,26 +47,12 @@ class Engagement
|
|||
*/
|
||||
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']]);
|
||||
|
@ -77,6 +65,15 @@ class Engagement
|
|||
$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) {
|
||||
|
@ -90,6 +87,7 @@ class Engagement
|
|||
'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 (?, ?, ?)",
|
||||
|
@ -98,7 +96,7 @@ class Engagement
|
|||
])
|
||||
];
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue