-
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathContextChatIndexJob.php
More file actions
70 lines (64 loc) · 1.87 KB
/
Copy pathContextChatIndexJob.php
File metadata and controls
70 lines (64 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* Copyright (c) 2020-2025. The Nextcloud Bookmarks contributors.
*
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
namespace OCA\Bookmarks\BackgroundJobs;
use OCA\Bookmarks\AppInfo\Application;
use OCA\Bookmarks\ContextChat\ContextChatProvider;
use OCA\Bookmarks\Service\BookmarkService;
use OCA\Bookmarks\Service\UserSettingsService;
use OCA\ContextChat\Public\ContentItem;
use OCA\ContextChat\Public\ContentManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\IUserManager;
class ContextChatIndexJob extends QueuedJob {
public function __construct(
ITimeFactory $timeFactory,
private BookmarkService $bookmarkService,
private ?ContentManager $contentManager,
private IUserManager $userManager,
private ContextChatProvider $provider,
private UserSettingsService $userSettings,
) {
parent::__construct($timeFactory);
}
protected function run($argument) {
if ($this->contentManager === null) {
return;
}
if (!isset($argument['user'])) {
return;
}
$user = $this->userManager->get($argument['user']);
if ($user === null) {
return;
}
$this->userSettings->setUserId($user->getUID());
if ($this->userSettings->get('contextchat.enabled') !== 'true') {
return;
}
$items = [];
foreach ($this->bookmarkService->getIterator($user->getUID()) as $bookmark) {
$items[] = new ContentItem(
(string)$bookmark->getId(),
$this->provider->getId(),
$bookmark->getTitle(),
$bookmark->getTextContent(),
'Website',
new \DateTime('@' . $bookmark->getLastmodified()),
[$user->getUID()]
);
if (count($items) < 25) {
continue;
}
$this->contentManager->submitContent(Application::APP_ID, $items);
$items = [];
}
if (count($items) > 0) {
$this->contentManager->submitContent(Application::APP_ID, $items);
}
}
}