[PLUGIN][ActivityPub] Support tags in notes
This commit is contained in:
parent
36483a6ecd
commit
9d0b39e680
@ -74,11 +74,12 @@ class Tag extends Component
|
||||
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $extra_args): bool
|
||||
{
|
||||
$matched_tags = [];
|
||||
preg_match_all(self::TAG_REGEX, $content, $matched_tags, \PREG_SET_ORDER);
|
||||
// XXX: We remove <span> because when content is in html the tag comes as #<span>hashtag</span>
|
||||
preg_match_all(self::TAG_REGEX, str_replace('<span>', '', $content), $matched_tags, \PREG_SET_ORDER);
|
||||
$matched_tags = array_unique(F\map($matched_tags, fn ($m) => $m[2]));
|
||||
foreach ($matched_tags as $match) {
|
||||
$tag = self::ensureValid($match);
|
||||
$canonical_tag = self::canonicalTag($tag, Language::getById($note->getLanguageId())->getLocale());
|
||||
$canonical_tag = self::canonicalTag($tag, \is_null($lang_id = $note->getLanguageId()) ? null : Language::getById($lang_id)->getLocale());
|
||||
DB::persist(NoteTag::create([
|
||||
'tag' => $tag,
|
||||
'canonical' => $canonical_tag,
|
||||
|
@ -251,7 +251,7 @@ class Note extends Model
|
||||
'content' => $object->getRendered(),
|
||||
'attachment' => [],
|
||||
'tag' => [],
|
||||
'conversation' => $object->getConversationUri(),
|
||||
'inConversation' => $object->getConversationUri(),
|
||||
'directMessage' => false, // TODO: implement proper scope address
|
||||
];
|
||||
|
||||
@ -265,6 +265,15 @@ class Note extends Model
|
||||
$attr['cc'][] = $href;
|
||||
}
|
||||
|
||||
// Hashtags
|
||||
foreach ($object->getTags() as $hashtag) {
|
||||
$attr['tag'][] = [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->getUrl(type: Router::ABSOLUTE_URL),
|
||||
'name' => "#{$hashtag->getTag()}",
|
||||
];
|
||||
}
|
||||
|
||||
// Attachments
|
||||
foreach ($object->getAttachments() as $attachment) {
|
||||
$attr['attachment'][] = [
|
||||
|
@ -324,6 +324,11 @@ class Note extends Entity
|
||||
});
|
||||
}
|
||||
|
||||
public function getTags(): array
|
||||
{
|
||||
return Cache::get('note-tags-' . $this->getId(), fn () => DB::findBy('note_tag', ['note_id' => $this->getId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this Note's reply_to/parent.
|
||||
*
|
||||
|
@ -123,13 +123,13 @@ class NoteTag extends Entity
|
||||
return Cache::getList(self::cacheKey($note_id), fn () => DB::dql('select nt from note_tag nt join note n with n.id = nt.note_id where n.id = :id', ['id' => $note_id]));
|
||||
}
|
||||
|
||||
public function getUrl(?Actor $actor = null): string
|
||||
public function getUrl(?Actor $actor = null, int $type = Router::ABSOLUTE_PATH): string
|
||||
{
|
||||
$params = ['canon' => $this->getCanonical(), 'tag' => $this->getTag()];
|
||||
if (!\is_null($actor)) {
|
||||
$params['lang'] = $actor->getTopLanguage()->getLocale();
|
||||
}
|
||||
return Router::url('single_note_tag', $params);
|
||||
return Router::url(id: 'single_note_tag', args: $params, type: $type);
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
|
Loading…
Reference in New Issue
Block a user