99namespace OCA \Bookmarks \ContextChat ;
1010
1111use OCA \Bookmarks \AppInfo \Application ;
12+ use OCA \Bookmarks \BackgroundJobs \ContextChatIndexJob ;
1213use OCA \Bookmarks \Db \TreeMapper ;
1314use OCA \Bookmarks \Events \BeforeDeleteEvent ;
1415use OCA \Bookmarks \Events \InsertEvent ;
1819use OCA \ContextChat \Public \ContentItem ;
1920use OCA \ContextChat \Public \ContentManager ;
2021use OCA \ContextChat \Public \IContentProvider ;
22+ use OCP \BackgroundJob \IJobList ;
2123use OCP \EventDispatcher \Event ;
22- use OCP \EventDispatcher \IEventDispatcher ;
2324use OCP \EventDispatcher \IEventListener ;
2425use OCP \IUser ;
2526use OCP \IUserManager ;
@@ -32,12 +33,15 @@ class ContextChatProvider implements IContentProvider, IEventListener {
3233 public function __construct (
3334 private BookmarkService $ bookmarkService ,
3435 private IUserManager $ userManager ,
35- private ContentManager $ contentManager ,
36- private IEventDispatcher $ eventDispatcher ,
36+ private ? ContentManager $ contentManager ,
37+ private IJobList $ jobList ,
3738 ) {
3839 }
3940
4041 public function handle (Event $ event ): void {
42+ if ($ this ->contentManager === null ) {
43+ return ;
44+ }
4145 if ($ event instanceof ContentProviderRegisterEvent) {
4246 $ this ->register ();
4347 return ;
@@ -47,6 +51,9 @@ public function handle(Event $event): void {
4751 return ;
4852 }
4953 $ bookmark = $ this ->bookmarkService ->findById ($ event ->getId ());
54+ if ($ bookmark === null ) {
55+ return ;
56+ }
5057 $ item = new ContentItem (
5158 (string )$ event ->getId (),
5259 $ this ->getId (),
@@ -76,17 +83,15 @@ public function register(): void {
7683 * The ID of the provider
7784 *
7885 * @return string
79- * @since 1.1.0
8086 */
8187 public function getId (): string {
8288 return 'bookmarks ' ;
8389 }
8490
8591 /**
86- * The ID of the app making the provider avaialble
92+ * The ID of the app making the provider available
8793 *
8894 * @return string
89- * @since 1.1.0
9095 */
9196 public function getAppId (): string {
9297 return Application::APP_ID ;
@@ -97,7 +102,6 @@ public function getAppId(): string {
97102 *
98103 * @param string $id
99104 * @return string
100- * @since 1.1.0
101105 */
102106 public function getItemUrl (string $ id ): string {
103107 return $ this ->bookmarkService ->findById (intval ($ id ))?->getUrl() ?? '' ;
@@ -107,26 +111,10 @@ public function getItemUrl(string $id): string {
107111 * Starts the initial import of content items into content chat
108112 *
109113 * @return void
110- * @since 1.1.0
111114 */
112115 public function triggerInitialImport (): void {
113116 $ this ->userManager ->callForAllUsers (function (IUser $ user ) {
114- $ items = [];
115- foreach ($ this ->bookmarkService ->getIterator ($ user ->getUID ()) as $ bookmark ) {
116- $ items [] = new ContentItem (
117- (string )$ bookmark ->getId (),
118- $ this ->getId (),
119- $ bookmark ->getTitle (),
120- $ bookmark ->getTextContent (),
121- 'Website ' ,
122- new \DateTime ('@ ' . $ bookmark ->getLastmodified ()),
123- [$ user ->getUID ()]
124- );
125- if (count ($ items ) < 25 ) {
126- continue ;
127- }
128- $ this ->contentManager ->submitContent ($ this ->getAppId (), $ items );
129- }
117+ $ this ->jobList ->add (ContextChatIndexJob::class, [$ user ->getUID ()]);
130118 });
131119 }
132120}
0 commit comments