summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Model/ActivityPub/Object/Note.php33
-rw-r--r--lib/Model/ActivityPub/Stream.php18
2 files changed, 50 insertions, 1 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();
}
diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php
index ad55eee1..5a19deb3 100644
--- a/lib/Model/ActivityPub/Stream.php
+++ b/lib/Model/ActivityPub/Stream.php
@@ -78,6 +78,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
private string $attributedTo = '';
private string $inReplyTo = '';
private array $attachments = [];
+ private array $mentions = [];
private bool $sensitive = false;
private string $conversation = '';
private ?Cache $cache = null;
@@ -247,6 +248,17 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
}
+ public function getMentions(): array {
+ return $this->mentions;
+ }
+
+ public function setMentions(array $mentions): self {
+ $this->mentions = $mentions;
+
+ return $this;
+ }
+
+
/**
* @return bool
*/
@@ -434,7 +446,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
*/
public function importAttachments(array $list): void {
$urlGenerator = Server::get(IURLGenerator::class);
-
+
$new = [];
foreach ($list as $item) {
try {
@@ -495,6 +507,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
$this->setDetailsAll($this->getArray('details', $data, []));
$this->setFilterDuplicate($this->getBool('filter_duplicate', $data, false));
$this->setAttachments($this->getArray('attachments', $data, []));
+ $this->setMentions($this->getDetails('mentions'));
$this->setVisibility($this->get('visibility', $data));
$cache = new Cache();
@@ -547,6 +560,8 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
}
$this->setAttachments($attachments);
+ $this->setMentions($this->getArray('mentions', $data));
+
// import from cache with new format !
$actor = new Person();
$actor->importFromLocal($this->getArray('account', $data));
@@ -619,6 +634,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
"language" => $this->getLanguage(),
"in_reply_to_id" => null,
"in_reply_to_account_id" => null,
+ 'mentions' => $this->getMentions(),
'replies_count' => 0,
'reblogs_count' => 0,
'favourites_count' => 0,