<?php
/**
- * @copyright Copyright (C) 2010-2023, the Friendica project
+ * @copyright Copyright (C) 2010-2024, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
$previous = Post::selectFirst(['edited'], $condition);
}
+ if (!empty($fields['body'])) {
+ $fields['body'] = self::setHashtags($fields['body']);
+ }
+
$rows = Post::update($fields, $condition);
if (is_bool($rows)) {
return $rows;
// locate item to be deleted
$fields = [
'id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri-id', 'origin',
- 'deleted', 'resource-id', 'event-id',
+ 'thr-parent-id', 'deleted', 'resource-id', 'event-id', 'vid', 'body',
'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity'
];
$item = Post::selectFirst($fields, ['id' => $item_id]);
DI::notify()->deleteForItem($item['uri-id']);
DI::notification()->deleteForItem($item['uri-id']);
+ if (in_array($item['gravity'], [self::GRAVITY_ACTIVITY, self::GRAVITY_COMMENT])) {
+ Post\Counts::update($item['thr-parent-id'], $item['parent-uri-id'], $item['vid'], $item['verb'], $item['body']);
+ }
+
Logger::info('Item has been marked for deletion.', ['id' => $item_id]);
return true;
Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$posted_item['uri-id'], (int)$posted_item['uid']);
}
- // Fill the cache with the rendered content.
- if (in_array($posted_item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) && ($posted_item['uid'] == 0)) {
- self::updateDisplayCache($posted_item['uri-id']);
- }
-
if ($inserted) {
- Post\Engagement::storeFromItem($posted_item);
+ // Fill the cache with the rendered content.
+ if (in_array($posted_item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT])) {
+ self::updateDisplayCache($posted_item['uri-id']);
+ }
+
+ if (in_array($posted_item['gravity'], [self::GRAVITY_ACTIVITY, self::GRAVITY_COMMENT])) {
+ Post\Counts::update($posted_item['thr-parent-id'], $posted_item['parent-uri-id'], $posted_item['vid'], $posted_item['verb'], $posted_item['body']);
+ }
+
+ $engagement_uri_id = Post\Engagement::storeFromItem($posted_item);
+ if ($engagement_uri_id) {
+ self::reshareChannelPost($engagement_uri_id);
+ }
}
return $post_user_id;
}
+ private static function reshareChannelPost(int $uri_id)
+ {
+ $item = Post::selectFirst(['id', 'private', 'network', 'language', 'owner-id'], ['uri-id' => $uri_id, 'uid' => 0]);
+ if (empty($item['id'])) {
+ return;
+ }
+
+ if (($item['private'] != self::PUBLIC) || !in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
+ return;
+ }
+
+ $engagement = DBA::selectFirst('post-engagement', ['searchtext', 'media-type'], ['uri-id' => $uri_id]);
+ if (empty($engagement['searchtext'])) {
+ return;
+ }
+
+ $language = !empty($item['language']) ? array_key_first(json_decode($item['language'], true)) : '';
+ $tags = array_column(Tag::getByURIId($uri_id, [Tag::HASHTAG]), 'name');
+
+ foreach (DI::userDefinedChannel()->getMatchingChannelUsers($engagement['searchtext'], $language, $tags, $engagement['media-type'], $item['owner-id']) as $uid) {
+ Logger::debug('Reshare post', ['uid' => $uid, 'uri-id' => $uri_id, 'language' => $language, 'tags' => $tags, 'searchtext' => $engagement['searchtext'], 'media_type' => $engagement['media-type']]);
+ self::performActivity($item['id'], 'announce', $uid);
+ }
+ }
+
/**
* Fetch the post reason for a given item array
*
}
if (empty($searchtext)) {
- return [];
+ return ['un' => 1];
}
$ld = new Language(DI::l10n()->getDetectableLanguages());
}
}
+ if (empty($result)) {
+ return ['un' => 1];
+ }
+
$result = self::compactLanguages($result);
arsort($result);
foreach (json_decode($item['language'], true) as $language => $reliability) {
$code = DI::l10n()->toISO6391($language);
- $native = $iso639->nativeByCode1($code);
- $language = $iso639->languageByCode1($code);
+ if ($code == 'un') {
+ $native = $language = DI::l10n()->t('Undetermined');
+ } else {
+ $native = $iso639->nativeByCode1($code);
+ $language = $iso639->languageByCode1($code);
+ }
+
if ($native != $language) {
$used_languages .= DI::l10n()->t('%s (%s - %s): %s', $native, $language, $code, number_format($reliability, 5)) . '\n';
} else {