Skip to content

Commit

Permalink
feat: Text processing assistant integration
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Aug 9, 2023
1 parent 1a2e575 commit 017b657
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'OCA\\Text\\Exception\\UploadException' => $baseDir . '/../lib/Exception/UploadException.php',
'OCA\\Text\\Exception\\VersionMismatchException' => $baseDir . '/../lib/Exception/VersionMismatchException.php',
'OCA\\Text\\Listeners\\AddMissingIndicesListener' => $baseDir . '/../lib/Listeners/AddMissingIndicesListener.php',
'OCA\\Text\\Listeners\\BeforeAssistantNotificationListener' => $baseDir . '/../lib/Listeners/BeforeAssistantNotificationListener.php',
'OCA\\Text\\Listeners\\BeforeNodeDeletedListener' => $baseDir . '/../lib/Listeners/BeforeNodeDeletedListener.php',
'OCA\\Text\\Listeners\\BeforeNodeRenamedListener' => $baseDir . '/../lib/Listeners/BeforeNodeRenamedListener.php',
'OCA\\Text\\Listeners\\FilesLoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/FilesLoadAdditionalScriptsListener.php',
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ComposerStaticInitText
'OCA\\Text\\Exception\\UploadException' => __DIR__ . '/..' . '/../lib/Exception/UploadException.php',
'OCA\\Text\\Exception\\VersionMismatchException' => __DIR__ . '/..' . '/../lib/Exception/VersionMismatchException.php',
'OCA\\Text\\Listeners\\AddMissingIndicesListener' => __DIR__ . '/..' . '/../lib/Listeners/AddMissingIndicesListener.php',
'OCA\\Text\\Listeners\\BeforeAssistantNotificationListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeAssistantNotificationListener.php',
'OCA\\Text\\Listeners\\BeforeNodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeNodeDeletedListener.php',
'OCA\\Text\\Listeners\\BeforeNodeRenamedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeNodeRenamedListener.php',
'OCA\\Text\\Listeners\\FilesLoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/FilesLoadAdditionalScriptsListener.php',
Expand Down
4 changes: 4 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Text\Event\LoadEditor;
use OCA\Text\Listeners\AddMissingIndicesListener;
use OCA\Text\Listeners\BeforeAssistantNotificationListener;
use OCA\Text\Listeners\BeforeNodeDeletedListener;
use OCA\Text\Listeners\BeforeNodeRenamedListener;
use OCA\Text\Listeners\FilesLoadAdditionalScriptsListener;
Expand All @@ -39,6 +40,7 @@
use OCA\Text\Listeners\RegisterDirectEditorEventListener;
use OCA\Text\Notification\Notifier;
use OCA\Text\Service\ConfigService;
use OCA\TPAssistant\Event\BeforeAssistantNotificationEvent;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
Expand Down Expand Up @@ -71,6 +73,8 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeNodeRenamedEvent::class, BeforeNodeRenamedListener::class);
$context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class);
$context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class);
$context->registerEventListener(BeforeAssistantNotificationEvent::class, BeforeAssistantNotificationListener::class);

$context->registerNotifierService(Notifier::class);
}

Expand Down
36 changes: 36 additions & 0 deletions lib/Listeners/BeforeAssistantNotificationListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace OCA\Text\Listeners;

use OCA\Text\AppInfo\Application;
use OCA\TPAssistant\Event\BeforeAssistantNotificationEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IURLGenerator;

/** @template-implements IEventListener<BeforeAssistantNotificationEvent|Event> */
class BeforeAssistantNotificationListener implements \OCP\EventDispatcher\IEventListener {

public function __construct(
private IURLGenerator $urlGenerator,
) {
}

/**
* @inheritDoc
*/
public function handle(Event $event): void {
if (!$event instanceof BeforeAssistantNotificationEvent) {
return;
}

$task = $event->getTask();
if ($task->getAppId() !== Application::APP_NAME || $task->getUserId() === null) {
return;
}
$fileId = (int)str_replace('text-file:', '', $task->getIdentifier());
$fileLink = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $fileId]);
$event->setWantsNotification(true);
$event->setNotificationTarget($fileLink);
}
}
3 changes: 1 addition & 2 deletions lib/Service/InitialStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use OCP\AppFramework\Services\IInitialState;
use OCP\TextProcessing\IManager;
use OCP\TextProcessing\IProvider;
use OCP\TextProcessing\ITaskType;
use OCP\Translation\ITranslationManager;

Expand Down Expand Up @@ -51,7 +50,7 @@ public function provideState(): void {

$this->initialState->provideInitialState(
'textprocessing',
array_map(function(string $className) {
array_map(function (string $className) {
/** @var class-string<ITaskType> $className */
$type = \OCP\Server::get($className);
return [
Expand Down
Loading

0 comments on commit 017b657

Please sign in to comment.