From: Michael Date: Mon, 28 Aug 2023 04:05:52 +0000 (+0000) Subject: Store and display the subscribed tags X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f842e7b81395803d4bd914175455d120837da312;p=friendica.git Store and display the subscribed tags --- diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index 710422ee76..57cc6aa50c 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -38,6 +38,7 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Item as ItemModel; use Friendica\Model\Post; +use Friendica\Model\Post\Category; use Friendica\Model\Tag; use Friendica\Model\User; use Friendica\Model\Verb; @@ -743,7 +744,12 @@ class Conversation $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])]; break; case ItemModel::PR_TAG: - $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')]; + $tags = Category::getArrayByURIId($row['uri-id'], $row['uid'], Category::SUBCRIPTION); + if (!empty($tags)) { + $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to %s.', implode(', ', $tags))]; + } else { + $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')]; + } break; case ItemModel::PR_ANNOUNCEMENT: if (!empty($row['causer-id']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'display_resharer')) { diff --git a/src/Model/Item.php b/src/Model/Item.php index a2304056d3..d5e9555268 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -32,6 +32,7 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Model\Post\Category; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityPub; @@ -1509,10 +1510,13 @@ class Item return; } - $uids = Tag::getUIDListByURIId($item['uri-id']); - foreach ($uids as $uid) { + foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) { $stored = self::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => self::PR_TAG]); Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]); + foreach ($tags as $tag) { + $stored = Category::storeFileByURIId($item['uri-id'], $uid, Category::SUBCRIPTION, $tag); + Logger::debug('Stored tag subscription for user', ['uri-id' => $item['uri-id'], 'uid' => $uid, $tag, 'stored' => $stored]); + } } } diff --git a/src/Model/Post/Category.php b/src/Model/Post/Category.php index 2c35a40ad4..dd6171b0f6 100644 --- a/src/Model/Post/Category.php +++ b/src/Model/Post/Category.php @@ -36,6 +36,7 @@ class Category const UNKNOWN = 0; const CATEGORY = 3; const FILE = 5; + const SUBCRIPTION = 10; /** * Delete all categories and files from a given uri-id and user @@ -80,7 +81,7 @@ class Category { $file_text = ''; - $tags = DBA::selectToArray('category-view', ['type', 'name'], ['uri-id' => $uri_id, 'uid' => $uid]); + $tags = DBA::selectToArray('category-view', ['type', 'name'], ['uri-id' => $uri_id, 'uid' => $uid, 'type' => [Category::FILE, Category::CATEGORY]]); foreach ($tags as $tag) { if ($tag['type'] == self::CATEGORY) { $file_text .= '<' . $tag['name'] . '>'; @@ -177,12 +178,7 @@ class Category continue; } - DBA::replace('post-category', [ - 'uri-id' => $uri_id, - 'uid' => $uid, - 'type' => self::FILE, - 'tid' => $tagid - ]); + self::storeByURIId($uri_id, $uid, self::FILE, $tagid); } } @@ -193,13 +189,18 @@ class Category } } - public static function storeFileByURIId(int $uri_id, int $uid, int $type, string $file) + public static function storeFileByURIId(int $uri_id, int $uid, int $type, string $file, string $url = ''): bool { - $tagid = Tag::getID($file); + $tagid = Tag::getID($file, $url); if (empty($tagid)) { return false; } + return self::storeByURIId($uri_id, $uid, $type, $tagid); + } + + private static function storeByURIId(int $uri_id, int $uid, int $type, int $tagid): bool + { return DBA::replace('post-category', [ 'uri-id' => $uri_id, 'uid' => $uid, diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 1645dc1255..04f3f1627e 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -828,12 +828,13 @@ class Tag public static function getUIDListByURIId(int $uriId): array { $uids = []; - $tags = self::getByURIId($uriId, [self::HASHTAG]); - foreach ($tags as $tag) { - $uids = array_merge($uids, self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name'])); + foreach (self::getByURIId($uriId, [self::HASHTAG]) as $tag) { + foreach (self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']) as $uid) { + $uids[$uid][] = $tag['name']; + } } - return array_unique($uids); + return $uids; } }