Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'OCA\\Text\\DirectEditing\\TextDirectEditor' => $baseDir . '/../lib/DirectEditing/TextDirectEditor.php',
'OCA\\Text\\DirectEditing\\TextDocumentCreator' => $baseDir . '/../lib/DirectEditing/TextDocumentCreator.php',
'OCA\\Text\\Event\\LoadEditor' => $baseDir . '/../lib/Event/LoadEditor.php',
'OCA\\Text\\Event\\MentionEvent' => $baseDir . '/../lib/Event/MentionEvent.php',
'OCA\\Text\\Exception\\DocumentHasUnsavedChangesException' => $baseDir . '/../lib/Exception/DocumentHasUnsavedChangesException.php',
'OCA\\Text\\Exception\\DocumentSaveConflictException' => $baseDir . '/../lib/Exception/DocumentSaveConflictException.php',
'OCA\\Text\\Exception\\InvalidDocumentBaseVersionEtagException' => $baseDir . '/../lib/Exception/InvalidDocumentBaseVersionEtagException.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 @@ -44,6 +44,7 @@ class ComposerStaticInitText
'OCA\\Text\\DirectEditing\\TextDirectEditor' => __DIR__ . '/..' . '/../lib/DirectEditing/TextDirectEditor.php',
'OCA\\Text\\DirectEditing\\TextDocumentCreator' => __DIR__ . '/..' . '/../lib/DirectEditing/TextDocumentCreator.php',
'OCA\\Text\\Event\\LoadEditor' => __DIR__ . '/..' . '/../lib/Event/LoadEditor.php',
'OCA\\Text\\Event\\MentionEvent' => __DIR__ . '/..' . '/../lib/Event/MentionEvent.php',
'OCA\\Text\\Exception\\DocumentHasUnsavedChangesException' => __DIR__ . '/..' . '/../lib/Exception/DocumentHasUnsavedChangesException.php',
'OCA\\Text\\Exception\\DocumentSaveConflictException' => __DIR__ . '/..' . '/../lib/Exception/DocumentSaveConflictException.php',
'OCA\\Text\\Exception\\InvalidDocumentBaseVersionEtagException' => __DIR__ . '/..' . '/../lib/Exception/InvalidDocumentBaseVersionEtagException.php',
Expand Down
32 changes: 32 additions & 0 deletions lib/Event/MentionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


namespace OCA\Text\Event;

use OCP\EventDispatcher\Event;
use OCP\Files\File;
use OCP\Notification\INotification;

class MentionEvent extends Event {
public function __construct(
private INotification $notification,
private File $file,
) {
parent::__construct();
}

public function getNotification(): INotification {
return $this->notification;
}

public function getFile(): File {
return $this->file;
}
}
32 changes: 17 additions & 15 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
namespace OCA\Text\Notification;

use OC\User\NoUserException;
use OCA\Text\Event\MentionEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IURLGenerator;
Expand All @@ -24,16 +27,13 @@ class Notifier implements INotifier {
public const SUBJECT_MENTIONED_SOURCE_USER = 'sourceUser';
public const SUBJECT_MENTIONED_TARGET_USER = 'targetUser';

private IFactory $factory;
private IURLGenerator $url;
private IUserManager $userManager;
private IRootFolder $rootFolder;

public function __construct(IFactory $factory, IUserManager $userManager, IURLGenerator $urlGenerator, IRootFolder $rootFolder) {
$this->factory = $factory;
$this->userManager = $userManager;
$this->url = $urlGenerator;
$this->rootFolder = $rootFolder;
public function __construct(
private IFactory $factory,
private IUserManager $userManager,
private IURLGenerator $urlGenerator,
private IRootFolder $rootFolder,
private IEventDispatcher $eventDispatcher,
) {
}

public function getID(): string {
Expand All @@ -50,7 +50,7 @@ public function prepare(INotification $notification, string $languageCode): INot
}

$l = $this->factory->get('text', $languageCode);

$notification->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('text', 'app-dark.svg')));
switch ($notification->getSubject()) {
case self::TYPE_MENTIONED:
$parameters = $notification->getSubjectParameters();
Expand All @@ -70,12 +70,13 @@ public function prepare(INotification $notification, string $languageCode): INot
}
$node = $userFolder->getFirstNodeById($fileId);

if ($node === null) {
if (!$node instanceof File) {
throw new AlreadyProcessedException();
}

$fileLink = $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $node->getId()]);
$fileLink = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $node->getId()]);

$notification->setLink($fileLink);
$notification->setRichSubject($l->t('{user} has mentioned you in the text document {node}'), [
'user' => [
'type' => 'user',
Expand All @@ -90,12 +91,13 @@ public function prepare(INotification $notification, string $languageCode): INot
'link' => $fileLink,
],
]);

$this->eventDispatcher->dispatchTyped(new MentionEvent($notification, $node));
break;
default:
throw new UnknownNotificationException();
}
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('text', 'app-dark.svg')));
$notification->setLink($fileLink);

$this->setParsedSubjectFromRichSubject($notification);
return $notification;
}
Expand Down
Loading