1
0
Fork 0

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\Contact;
use Friendica\Model\Item as ItemModel; use Friendica\Model\Item as ItemModel;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Post\Category;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Model\Verb; 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'])]; $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])];
break; break;
case ItemModel::PR_TAG: 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; break;
case ItemModel::PR_ANNOUNCEMENT: case ItemModel::PR_ANNOUNCEMENT:
if (!empty($row['causer-id']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'display_resharer')) { 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\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Post\Category;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
@ -1509,10 +1510,13 @@ class Item
return; return;
} }
$uids = Tag::getUIDListByURIId($item['uri-id']); foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) {
foreach ($uids as $uid) {
$stored = self::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => self::PR_TAG]); $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]); 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 UNKNOWN = 0;
const CATEGORY = 3; const CATEGORY = 3;
const FILE = 5; const FILE = 5;
const SUBCRIPTION = 10;
/** /**
* Delete all categories and files from a given uri-id and user * Delete all categories and files from a given uri-id and user
@ -80,7 +81,7 @@ class Category
{ {
$file_text = ''; $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) { foreach ($tags as $tag) {
if ($tag['type'] == self::CATEGORY) { if ($tag['type'] == self::CATEGORY) {
$file_text .= '<' . $tag['name'] . '>'; $file_text .= '<' . $tag['name'] . '>';
@ -177,12 +178,7 @@ class Category
continue; continue;
} }
DBA::replace('post-category', [ self::storeByURIId($uri_id, $uid, self::FILE, $tagid);
'uri-id' => $uri_id,
'uid' => $uid,
'type' => self::FILE,
'tid' => $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)) { if (empty($tagid)) {
return false; 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', [ return DBA::replace('post-category', [
'uri-id' => $uri_id, 'uri-id' => $uri_id,
'uid' => $uid, 'uid' => $uid,

View file

@ -828,12 +828,13 @@ class Tag
public static function getUIDListByURIId(int $uriId): array public static function getUIDListByURIId(int $uriId): array
{ {
$uids = []; $uids = [];
$tags = self::getByURIId($uriId, [self::HASHTAG]);
foreach ($tags as $tag) { foreach (self::getByURIId($uriId, [self::HASHTAG]) as $tag) {
$uids = array_merge($uids, self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name'])); foreach (self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']) as $uid) {
$uids[$uid][] = $tag['name'];
}
} }
return array_unique($uids); return $uids;
} }
} }