Store and display the subscribed tags

This commit is contained in:
Michael 2023-08-28 04:05:52 +00:00
parent b218a7f218
commit f842e7b813
4 changed files with 28 additions and 16 deletions

View 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')) {

View 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]);
}
}
}

View 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,

View 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;
}
}