]> git.mxchange.org Git - friendica.git/commitdiff
Store and display the subscribed tags
authorMichael <heluecht@pirati.ca>
Mon, 28 Aug 2023 04:05:52 +0000 (04:05 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 28 Aug 2023 04:05:52 +0000 (04:05 +0000)
src/Content/Conversation.php
src/Model/Item.php
src/Model/Post/Category.php
src/Model/Tag.php

index 710422ee762cc162e411b8dd496a4c8e751fb2c3..57cc6aa50c1f8d6bd66a4c7fc1553b9bb075335d 100644 (file)
@@ -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')) {
index a2304056d373096b4ae90e393ae355bb39c752b5..d5e9555268900e59dda42fc2bb7566b4efd8729c 100644 (file)
@@ -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]);
+                       }
                }
        }
 
index 2c35a40ad4b8756adc990ecfe01bce85982ed371..dd6171b0f6b05d35c6b7836bdb5db0c47d8df242 100644 (file)
@@ -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,
index 1645dc1255b540a9f66742b3c987f6a7bd93e78b..04f3f1627eae8249706192bce0b3f44e1ec34780 100644 (file)
@@ -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;
        }
 }