Can view attachts in shared notes as long also share the files.

This commit is contained in:
Matias De lellis
2020-06-16 11:58:47 -03:00
parent 8f88f88dcb
commit f46b5ca651
5 changed files with 32 additions and 16 deletions

View File

@@ -73,8 +73,7 @@ class AttachMapper extends QBMapper {
* @param string $userId
* @param int $noteId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Note[]
* @return Attach[]
*/
public function findFromNote($userId, $noteId) {
$qb = $this->db->getQueryBuilder();
@@ -86,4 +85,5 @@ class AttachMapper extends QBMapper {
);
return $this->findEntities($qb);
}
}

View File

@@ -57,13 +57,16 @@ class FileService {
* @param int $fileId file id to show
* @param int $sideSize side lenght to show
*/
public function getPreviewUrl(int $fileId, int $sideSize): string {
public function getPreviewUrl(int $fileId, int $sideSize): ?string {
$userFolder = $this->rootFolder->getUserFolder($this->userId);
$node = current($userFolder->getById($fileId));
$path = $userFolder->getRelativePath($node->getPath());
$file = current($userFolder->getById($fileId));
if (!($file instanceof File)) {
return null;
}
return $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreview', [
'file' => $path,
'file' => $userFolder->getRelativePath($file->getPath()),
'x' => $sideSize,
'y' => $sideSize
]);
@@ -78,7 +81,7 @@ class FileService {
$userFolder = $this->rootFolder->getUserFolder($this->userId);
$file = current($userFolder->getById($fileId));
if(!($file instanceof File)) {
if (!($file instanceof File)) {
return null;
}

View File

@@ -114,12 +114,23 @@ class NoteService {
// Insert attachts to response.
foreach ($notes as $note) {
$attachts = $this->attachMapper->findFromNote($userId, $note->getId());
$rAttachts = [];
$attachts = $this->attachMapper->findFromNote($note->getUserId(), $note->getId());
foreach ($attachts as $attach) {
$attach->setPreviewUrl($this->fileService->getPreviewUrl($attach->getFileId(), 512));
$attach->setRedirectUrl($this->fileService->getRedirectToFileUrl($attach->getFileId()));
$previewUrl = $this->fileService->getPreviewUrl($attach->getFileId(), 512);
if (is_null($previewUrl))
continue;
$redirectUrl = $this->fileService->getRedirectToFileUrl($attach->getFileId());
if (is_null($redirectUrl))
continue;
$attach->setPreviewUrl($previewUrl);
$attach->setRedirectUrl($redirectUrl);
$rAttachts[] = $attach;
}
$note->setAttachts($attachts);
$note->setAttachts($rAttachts);
}
return $notes;