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;
$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')) {
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;
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]);
+ }
}
}
const UNKNOWN = 0;
const CATEGORY = 3;
const FILE = 5;
+ const SUBCRIPTION = 10;
/**
* Delete all categories and files from a given uri-id and user
{
$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'] . '>';
continue;
}
- DBA::replace('post-category', [
- 'uri-id' => $uri_id,
- 'uid' => $uid,
- 'type' => self::FILE,
- 'tid' => $tagid
- ]);
+ self::storeByURIId($uri_id, $uid, self::FILE, $tagid);
}
}
}
}
- 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,
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;
}
}