Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1669/head
Maxence Lange 2023-04-06 12:39:25 -01:00
rodzic f4f7e5d305
commit 050983a2a6
4 zmienionych plików z 45 dodań i 21 usunięć

Wyświetl plik

@ -146,17 +146,17 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
*/ */
public function parseCacheActorsSelectSql(array $data, SocialQueryBuilder $qb): Person { public function parseCacheActorsSelectSql(array $data, SocialQueryBuilder $qb): Person {
$actor = new Person(); $actor = new Person();
$actor->importFromDatabase($data);
$actor->setExportFormat($qb->getFormat()); $actor->setExportFormat($qb->getFormat());
$this->assignViewerLink($qb, $actor);
try { try {
$icon = $qb->parseLeftJoinCacheDocuments($data); $icon = $qb->parseLeftJoinCacheDocuments($data);
$actor->setIcon($icon); $actor->setIcon($icon);
} catch (InvalidResourceException $e) { } catch (InvalidResourceException $e) {
} }
$actor->importFromDatabase($data);
$this->assignViewerLink($qb, $actor);
$this->assignDetails($actor, $data); $this->assignDetails($actor, $data);
return $actor; return $actor;

Wyświetl plik

@ -225,6 +225,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
->selectAlias($alias . '.media_type', $prefix . 'media_type') ->selectAlias($alias . '.media_type', $prefix . 'media_type')
->selectAlias($alias . '.url', $prefix . 'url') ->selectAlias($alias . '.url', $prefix . 'url')
->selectAlias($alias . '.local_copy', $prefix . 'local_copy') ->selectAlias($alias . '.local_copy', $prefix . 'local_copy')
->selectAlias($alias . '.resized_copy', $prefix . 'resized_copy')
->selectAlias($alias . '.caching', $prefix . 'caching') ->selectAlias($alias . '.caching', $prefix . 'caching')
->selectAlias($alias . '.public', $prefix . 'public') ->selectAlias($alias . '.public', $prefix . 'public')
->selectAlias($alias . '.error', $prefix . 'error') ->selectAlias($alias . '.error', $prefix . 'error')

Wyświetl plik

@ -43,6 +43,8 @@ use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Image; use OCA\Social\Model\ActivityPub\Object\Image;
use OCA\Social\Tools\IQueryRow; use OCA\Social\Tools\IQueryRow;
use OCA\Social\Traits\TDetails; use OCA\Social\Traits\TDetails;
use OCP\IURLGenerator;
use OCP\Server;
/** /**
* Class Actor * Class Actor
@ -184,6 +186,11 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
* @return string * @return string
*/ */
public function getAvatar(): string { public function getAvatar(): string {
if ($this->hasIcon()) {
return $this->getIcon()
->getUrl();
}
return $this->avatar; return $this->avatar;
} }
@ -769,6 +776,10 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
* @return array * @return array
*/ */
public function exportAsLocal(): array { public function exportAsLocal(): array {
if ($this->hasIcon()) {
$avatar = $this->getIcon()->getMediaUrl(Server::get(IURLGenerator::class));
}
$details = $this->getDetailsAll(); $details = $this->getDetailsAll();
$result = $result =
[ [
@ -783,10 +794,10 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
'created_at' => date('Y-m-d\TH:i:s', $this->getCreation()) . '.000Z', 'created_at' => date('Y-m-d\TH:i:s', $this->getCreation()) . '.000Z',
'note' => $this->getDescription(), 'note' => $this->getDescription(),
'url' => $this->getId(), 'url' => $this->getId(),
'avatar' => $this->getAvatar(), 'avatar' => $avatar ?? $this->getAvatar(),
'avatar_static' => $this->getAvatar(), 'avatar_static' => $avatar ?? $this->getAvatar(),
'header' => $this->getHeader(), 'header' => $avatar ?? $this->getHeader(),
'header_static' => $this->getHeader(), 'header_static' => $avatar ?? $this->getHeader(),
'followers_count' => $this->getInt('count.followers', $details), 'followers_count' => $this->getInt('count.followers', $details),
'following_count' => $this->getInt('count.following', $details), 'following_count' => $this->getInt('count.following', $details),
'statuses_count' => $this->getInt('count.post', $details), 'statuses_count' => $this->getInt('count.post', $details),

Wyświetl plik

@ -366,7 +366,29 @@ class Document extends ACore implements JsonSerializable {
return $result; return $result;
} }
public function getMediaUrl(IURLGenerator $urlGenerator, string $mime = ''): string {
$mime = ($mime === '') ? '' : '.' . $mime;
return $urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getLocalCopy() . $mime]
);
}
public function getResizedMediaUrl(IURLGenerator $urlGenerator, string $mime = ''): string {
$mime = ($mime === '') ? '' : '.' . $mime;
return $urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getResizedCopy() . $mime]
);
}
/** /**
* @param IURLGenerator|null $urlGenerator
*
* @return MediaAttachment * @return MediaAttachment
*/ */
public function convertToMediaAttachment( public function convertToMediaAttachment(
@ -381,25 +403,15 @@ class Document extends ACore implements JsonSerializable {
if (strpos($this->getMediaType(), '/')) { if (strpos($this->getMediaType(), '/')) {
[$type, $mime] = explode('/', $this->getMediaType(), 2); [$type, $mime] = explode('/', $this->getMediaType(), 2);
$media->setType($type); $media->setType($type);
$mime = (strlen($mime) < 7) ? '.' . $mime : ''; // mime is ignored if too long.
} }
if (!is_null($urlGenerator)) { if (!is_null($urlGenerator)) {
$media->setUrl( $media->setUrl($this->getMediaUrl($urlGenerator, $mime));
$urlGenerator->linkToRouteAbsolute( $media->setPreviewUrl($this->getResizedMediaUrl($urlGenerator, $mime));
'social.Api.mediaOpen',
['uuid' => $this->getLocalCopy() . $mime]
)
);
$media->setPreviewUrl(
$urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getResizedCopy() . $mime]
)
);
$media->setRemoteUrl($this->getUrl());
} }
$media->setRemoteUrl($this->getUrl());
if ($this->getMeta() === null) { if ($this->getMeta() === null) {
$meta = new AttachmentMeta(); $meta = new AttachmentMeta();
$meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize())) $meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize()))