Skip to content

Commit e73ded9

Browse files
committed
feat(files): Provide folder tree folders state
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 739106c commit e73ded9

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

apps/files/lib/Controller/ViewController.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace OCA\Files\Controller;
99

1010
use OC\Files\FilenameValidator;
11+
use OC\Files\Search\SearchComparison;
12+
use OC\Files\Search\SearchQuery;
1113
use OCA\Files\Activity\Helper;
1214
use OCA\Files\AppInfo\Application;
1315
use OCA\Files\Event\LoadAdditionalScriptsEvent;
@@ -26,9 +28,11 @@
2628
use OCP\AppFramework\Services\IInitialState;
2729
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
2830
use OCP\EventDispatcher\IEventDispatcher;
31+
use OCP\Files\Cache\ICacheEntry;
2932
use OCP\Files\Folder;
3033
use OCP\Files\IRootFolder;
3134
use OCP\Files\NotFoundException;
35+
use OCP\Files\Search\ISearchComparison;
3236
use OCP\Files\Template\ITemplateManager;
3337
use OCP\IConfig;
3438
use OCP\IL10N;
@@ -160,6 +164,35 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
160164
$favElements = [];
161165
}
162166

167+
try {
168+
$userFolder = $this->rootFolder->getUserFolder($userId);
169+
$searchQuery = new SearchQuery(
170+
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE),
171+
0,
172+
0,
173+
[],
174+
$this->userSession->getUser(),
175+
false,
176+
);
177+
/** @var Folder[] $folders */
178+
$folders = $userFolder->search($searchQuery);
179+
$folderTreeFolders = array_values(array_map(fn (Folder $folder) => [
180+
'fileid' => $folder->getId(),
181+
'displayname' => $folder->getName(),
182+
'owner' => $folder->getOwner()?->getUID(),
183+
'path' => $userFolder->getRelativePath($folder->getPath()),
184+
'parentid' => $folder->getParentId(),
185+
'mountType' => $folder->getMountPoint()->getMountType(),
186+
'mime' => $folder->getMimetype(),
187+
'size' => $folder->getSize(),
188+
'mtime' => $folder->getMTime(),
189+
'crtime' => $folder->getCreationTime(),
190+
'permissions' => $folder->getPermissions(),
191+
], $folders));
192+
} catch (\RuntimeException $e) {
193+
$folderTreeFolders = [];
194+
}
195+
163196
// If the file doesn't exists in the folder and
164197
// exists in only one occurrence, redirect to that file
165198
// in the correct folder
@@ -190,6 +223,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
190223
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
191224
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
192225
$this->initialState->provideInitialState('favoriteFolders', $favElements);
226+
$this->initialState->provideInitialState('folderTreeFolders', $folderTreeFolders);
193227

194228
// File sorting user config
195229
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);

0 commit comments

Comments
 (0)