Skip to content

Commit

Permalink
initialize settings when using API or starting app
Browse files Browse the repository at this point in the history
  • Loading branch information
korelstar committed Aug 14, 2022
1 parent bab1e77 commit 67edbc1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getNotesAndCategories(
$userId = $this->getUID();
$chunkCursor = $chunkCursorStr ? ChunkCursor::fromString($chunkCursorStr) : null;
$lastUpdate = $chunkCursor->timeStart ?? new \DateTime();
$data = $this->notesService->getAll($userId, true);
$data = $this->notesService->getAll($userId, true); // auto-create notes folder if not exists
$metaNotes = $this->metaService->getAll($userId, $data['notes']);

// if a category is requested, then ignore all other notes
Expand Down
4 changes: 4 additions & 0 deletions lib/Controller/NotesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function index(
$chunkSize,
$chunkCursor
) {
// initialize settings
$userId = $this->helper->getUID();
$this->settingsService->getAll($userId, true);
// load notes and categories
$exclude = explode(',', $exclude);
$data = $this->helper->getNotesAndCategories($pruneBefore, $exclude, $category, $chunkSize, $chunkCursor);
$notesData = $data['notesData'];
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/NotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct(
public function index(int $pruneBefore = 0) : JSONResponse {
return $this->helper->handleErrorResponse(function () use ($pruneBefore) {
$userId = $this->helper->getUID();
// initialize and load settings
$settings = $this->settingsService->getAll($userId, true);

$lastViewedNote = (int) $this->settings->getUserValue(
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ public function get(string $uid, string $name) : string {
}

public function getPublic(string $uid) : \stdClass {
$settings = $this->getAll($uid);
// initialize and load settings
$settings = $this->getAll($uid, true);
// translate internal settings to public settings
if ($settings->fileSuffix === 'custom') {
$settings->fileSuffix = $settings->customSuffix;
}
Expand Down

0 comments on commit 67edbc1

Please sign in to comment.