|
12 | 12 | use OCP\AppFramework\Http\JSONResponse;
|
13 | 13 | use OCP\AppFramework\Http\StreamResponse;
|
14 | 14 | use OCP\Files\IMimeTypeDetector;
|
| 15 | +use OCP\Files\Lock\ILock; |
| 16 | +use OCP\Files\Lock\ILockManager; |
| 17 | +use OCP\Files\Lock\LockContext; |
15 | 18 | use OCP\IConfig;
|
16 | 19 | use OCP\IL10N;
|
17 | 20 | use OCP\IRequest;
|
18 | 21 |
|
19 | 22 | class NotesController extends Controller {
|
20 | 23 | private NotesService $notesService;
|
21 | 24 | private SettingsService $settingsService;
|
| 25 | + private ILockManager $lockManager; |
22 | 26 | private Helper $helper;
|
23 | 27 | private IConfig $settings;
|
24 | 28 | private IL10N $l10n;
|
25 | 29 | private IMimeTypeDetector $mimeTypeDetector;
|
| 30 | + private string $userId; |
26 | 31 |
|
27 | 32 | public function __construct(
|
28 | 33 | string $AppName,
|
29 | 34 | IRequest $request,
|
30 | 35 | NotesService $notesService,
|
| 36 | + ILockManager $lockManager, |
31 | 37 | SettingsService $settingsService,
|
32 | 38 | Helper $helper,
|
33 | 39 | IConfig $settings,
|
34 | 40 | IL10N $l10n,
|
35 |
| - IMimeTypeDetector $mimeTypeDetector |
| 41 | + IMimeTypeDetector $mimeTypeDetector, |
| 42 | + string $userId |
36 | 43 | ) {
|
37 | 44 | parent::__construct($AppName, $request);
|
38 | 45 | $this->notesService = $notesService;
|
39 | 46 | $this->settingsService = $settingsService;
|
| 47 | + $this->lockManager = $lockManager; |
40 | 48 | $this->helper = $helper;
|
41 | 49 | $this->settings = $settings;
|
42 | 50 | $this->l10n = $l10n;
|
43 | 51 | $this->mimeTypeDetector = $mimeTypeDetector;
|
| 52 | + $this->userId = $userId; |
44 | 53 | }
|
45 | 54 |
|
46 | 55 | /**
|
@@ -208,7 +217,15 @@ public function autotitle(int $id) : JSONResponse {
|
208 | 217 | $oldTitle = $note->getTitle();
|
209 | 218 | $newTitle = $this->notesService->getTitleFromContent($note->getContent());
|
210 | 219 | if ($oldTitle !== $newTitle) {
|
211 |
| - $note->setTitle($newTitle); |
| 220 | + $isRichText = $this->settingsService->get($this->userId, 'noteMode') === 'rich'; |
| 221 | + $lockContext = new LockContext( |
| 222 | + $note->getFile(), |
| 223 | + $isRichText ? ILock::TYPE_APP : ILock::TYPE_USER, |
| 224 | + $isRichText ? 'text' : $this->userId |
| 225 | + ); |
| 226 | + $this->lockManager->runInScope($lockContext, function () use ($note, $newTitle) { |
| 227 | + $note->setTitle($newTitle); |
| 228 | + }); |
212 | 229 | }
|
213 | 230 | return $note->getTitle();
|
214 | 231 | });
|
|
0 commit comments