diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2023-03-15 14:23:05 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-15 14:23:05 -0100 |
commit | 804ddccb654bb827180e89ef67472496be9e8d55 (patch) | |
tree | b986be99873455f0c35f654b0c39ec701d6fe1b4 /lib/Model/ActivityPub/Object/Note.php | |
parent | 33af3cb7838c79551ecdf57903b52f439985840c (diff) | |
parent | ccc814521fafeb1f8f65a84f533bd79504c1937b (diff) |
Merge pull request #1657 from nextcloud/enh/noid/status-mention
add mentions to status
Diffstat (limited to 'lib/Model/ActivityPub/Object/Note.php')
-rw-r--r-- | lib/Model/ActivityPub/Object/Note.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Model/ActivityPub/Object/Note.php b/lib/Model/ActivityPub/Object/Note.php index 36fb1e8c..c50b7189 100644 --- a/lib/Model/ActivityPub/Object/Note.php +++ b/lib/Model/ActivityPub/Object/Note.php @@ -31,8 +31,11 @@ declare(strict_types=1); namespace OCA\Social\Model\ActivityPub\Object; use JsonSerializable; +use OCA\Social\AP; use OCA\Social\Exceptions\ItemAlreadyExistsException; +use OCA\Social\Exceptions\ItemNotFoundException; use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Stream; class Note extends Stream implements JsonSerializable { @@ -56,6 +59,35 @@ class Note extends Stream implements JsonSerializable { return $this; } + public function fillMentions(): void { + $personInterface = AP::$activityPub->getInterfaceFromType(Person::TYPE); + $mentions = []; + + foreach ($this->getTags('Mention') as $item) { + $username = ltrim($this->get('name', $item), '@'); + $mention = [ + 'id' => 0, + 'username' => $username, + 'url' => $this->get('href', $item), + 'acct' => $username, + ]; + + try { + /** @var Person $actor */ + $actor = $personInterface->getItemById($mention['url']); + $mention['id'] = (string)$actor->getNid(); + $mention['username'] = $actor->getPreferredUsername(); + $mention['acct'] = $actor->getAccount(); + } catch (ItemNotFoundException $e) { + } + + $mentions[] = $mention; + } + + $this->setDetailArray('mentions', $mentions); + } + + public function fillHashtags(): void { $tags = $this->getTags('Hashtag'); $hashtags = []; @@ -78,6 +110,7 @@ class Note extends Stream implements JsonSerializable { parent::import($data); $this->fillHashtags(); + $this->fillMentions(); } |