kopia lustrzana https://github.com/nextcloud/social
Merge pull request #1657 from nextcloud/enh/noid/status-mention
add mentions to statuspull/1662/head
commit
804ddccb65
|
|
@ -31,8 +31,11 @@ declare(strict_types=1);
|
||||||
namespace OCA\Social\Model\ActivityPub\Object;
|
namespace OCA\Social\Model\ActivityPub\Object;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
use OCA\Social\AP;
|
||||||
use OCA\Social\Exceptions\ItemAlreadyExistsException;
|
use OCA\Social\Exceptions\ItemAlreadyExistsException;
|
||||||
|
use OCA\Social\Exceptions\ItemNotFoundException;
|
||||||
use OCA\Social\Model\ActivityPub\ACore;
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
|
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||||
use OCA\Social\Model\ActivityPub\Stream;
|
use OCA\Social\Model\ActivityPub\Stream;
|
||||||
|
|
||||||
class Note extends Stream implements JsonSerializable {
|
class Note extends Stream implements JsonSerializable {
|
||||||
|
|
@ -56,6 +59,35 @@ class Note extends Stream implements JsonSerializable {
|
||||||
return $this;
|
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 {
|
public function fillHashtags(): void {
|
||||||
$tags = $this->getTags('Hashtag');
|
$tags = $this->getTags('Hashtag');
|
||||||
$hashtags = [];
|
$hashtags = [];
|
||||||
|
|
@ -78,6 +110,7 @@ class Note extends Stream implements JsonSerializable {
|
||||||
parent::import($data);
|
parent::import($data);
|
||||||
|
|
||||||
$this->fillHashtags();
|
$this->fillHashtags();
|
||||||
|
$this->fillMentions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
||||||
private string $attributedTo = '';
|
private string $attributedTo = '';
|
||||||
private string $inReplyTo = '';
|
private string $inReplyTo = '';
|
||||||
private array $attachments = [];
|
private array $attachments = [];
|
||||||
|
private array $mentions = [];
|
||||||
private bool $sensitive = false;
|
private bool $sensitive = false;
|
||||||
private string $conversation = '';
|
private string $conversation = '';
|
||||||
private ?Cache $cache = null;
|
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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
@ -495,6 +507,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
||||||
$this->setDetailsAll($this->getArray('details', $data, []));
|
$this->setDetailsAll($this->getArray('details', $data, []));
|
||||||
$this->setFilterDuplicate($this->getBool('filter_duplicate', $data, false));
|
$this->setFilterDuplicate($this->getBool('filter_duplicate', $data, false));
|
||||||
$this->setAttachments($this->getArray('attachments', $data, []));
|
$this->setAttachments($this->getArray('attachments', $data, []));
|
||||||
|
$this->setMentions($this->getDetails('mentions'));
|
||||||
$this->setVisibility($this->get('visibility', $data));
|
$this->setVisibility($this->get('visibility', $data));
|
||||||
|
|
||||||
$cache = new Cache();
|
$cache = new Cache();
|
||||||
|
|
@ -547,6 +560,8 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
||||||
}
|
}
|
||||||
$this->setAttachments($attachments);
|
$this->setAttachments($attachments);
|
||||||
|
|
||||||
|
$this->setMentions($this->getArray('mentions', $data));
|
||||||
|
|
||||||
// import from cache with new format !
|
// import from cache with new format !
|
||||||
$actor = new Person();
|
$actor = new Person();
|
||||||
$actor->importFromLocal($this->getArray('account', $data));
|
$actor->importFromLocal($this->getArray('account', $data));
|
||||||
|
|
@ -619,6 +634,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
||||||
"language" => $this->getLanguage(),
|
"language" => $this->getLanguage(),
|
||||||
"in_reply_to_id" => null,
|
"in_reply_to_id" => null,
|
||||||
"in_reply_to_account_id" => null,
|
"in_reply_to_account_id" => null,
|
||||||
|
'mentions' => $this->getMentions(),
|
||||||
'replies_count' => 0,
|
'replies_count' => 0,
|
||||||
'reblogs_count' => 0,
|
'reblogs_count' => 0,
|
||||||
'favourites_count' => 0,
|
'favourites_count' => 0,
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue