Skip to content

Commit

Permalink
returns resources preview
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Nov 7, 2023
1 parent 7c74f02 commit 1aa8f3c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/IRelatedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function setIcon(string $icon): self;

public function getIcon(): string;

public function setPreview(string $preview): self;

public function getPreview(): string;

public function setUrl(string $url): self;

public function getUrl(): string;
Expand Down
17 changes: 15 additions & 2 deletions lib/Model/RelatedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RelatedResource implements IRelatedResource, IDeserializable, JsonSerializ
private string $subtitle = '';
private string $tooltip = '';
private string $icon = '';
private string $preview = '';
private string $url = '';
private int $range = 0;
private array $virtualGroup = [];
Expand Down Expand Up @@ -141,6 +142,16 @@ public function getIcon(): string {
return $this->icon;
}

public function setPreview(string $preview): self {
$this->preview = $preview;

return $this;
}

public function getPreview(): string {
return $this->preview;
}


public function setUrl(string $url): IRelatedResource {
$this->url = $url;
Expand Down Expand Up @@ -270,6 +281,7 @@ public function import(array $data): IDeserializable {
$this->setSubtitle($this->get('subtitle', $data));
$this->setTooltip($this->get('tooltip', $data));
$this->setIcon($this->get('icon', $data));
$this->setPreview($this->get('preview', $data));
$this->setUrl($this->get('url', $data));
$this->setScore($this->getInt('score', $data));
$this->setAsGroupShared($this->getBool('groupShared', $data));
Expand All @@ -290,6 +302,7 @@ public function jsonSerialize(): array {
'subtitle' => $this->getSubtitle(),
'tooltip' => $this->getTooltip(),
'icon' => $this->getIcon(),
'preview' => $this->getPreview(),
'url' => $this->getUrl(),
'score' => $this->getScore(),
'groupShared' => $this->isGroupShared(),
Expand All @@ -303,8 +316,8 @@ public function jsonSerialize(): array {

public static function cleanData(array $arr): array {
static $acceptedKeys = [
'providerId', 'itemId', 'title', 'subtitle', 'tooltip', 'url', 'icon', 'score',
'improvements'
'providerId', 'itemId', 'title', 'subtitle', 'tooltip', 'url',
'icon', 'preview', 'score', 'improvements'
];

$new = [];
Expand Down
6 changes: 6 additions & 0 deletions lib/RelatedResourceProviders/FilesRelatedResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ private function convertToRelatedResource(FilesShare $share): IRelatedResource {
)
)
);
$related->setPreview(
$this->urlGenerator->linkToRouteAbsolute(
'core.Preview.getPreviewByFileId',
['x' => 64, 'y' => 64, 'fileId' => $share->getFileId()]
)
);

$related->setUrl(
$this->urlGenerator->linkToRouteAbsolute('files.View.showFile', ['fileid' => $share->getFileId()])
Expand Down
8 changes: 7 additions & 1 deletion lib/RelatedResourceProviders/TalkRelatedResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ private function convertToRelatedResource(TalkRoom $share): IRelatedResource {
)
)
)
->setUrl($url);
->setPreview(
$this->urlGenerator->linkToOCSRouteAbsolute(
'spreed.Avatar.getAvatar',
['token' => $share->getToken(), 'apiVersion' => 'v1']
)
)
->setUrl($url);

$keywords = preg_split('/[\/_\-. ]/', ltrim(strtolower($share->getRoomName()), '/'));
if (is_array($keywords)) {
Expand Down

0 comments on commit 1aa8f3c

Please sign in to comment.