99namespace OCA \Text \Notification ;
1010
1111use OC \User \NoUserException ;
12+ use OCA \Text \Event \MentionEvent ;
13+ use OCP \EventDispatcher \IEventDispatcher ;
14+ use OCP \Files \File ;
1215use OCP \Files \IRootFolder ;
1316use OCP \Files \NotPermittedException ;
1417use OCP \IURLGenerator ;
@@ -24,16 +27,13 @@ class Notifier implements INotifier {
2427 public const SUBJECT_MENTIONED_SOURCE_USER = 'sourceUser ' ;
2528 public const SUBJECT_MENTIONED_TARGET_USER = 'targetUser ' ;
2629
27- private IFactory $ factory ;
28- private IURLGenerator $ url ;
29- private IUserManager $ userManager ;
30- private IRootFolder $ rootFolder ;
31-
32- public function __construct (IFactory $ factory , IUserManager $ userManager , IURLGenerator $ urlGenerator , IRootFolder $ rootFolder ) {
33- $ this ->factory = $ factory ;
34- $ this ->userManager = $ userManager ;
35- $ this ->url = $ urlGenerator ;
36- $ this ->rootFolder = $ rootFolder ;
30+ public function __construct (
31+ private IFactory $ factory ,
32+ private IUserManager $ userManager ,
33+ private IURLGenerator $ urlGenerator ,
34+ private IRootFolder $ rootFolder ,
35+ private IEventDispatcher $ eventDispatcher ,
36+ ) {
3737 }
3838
3939 public function getID (): string {
@@ -50,7 +50,7 @@ public function prepare(INotification $notification, string $languageCode): INot
5050 }
5151
5252 $ l = $ this ->factory ->get ('text ' , $ languageCode );
53-
53+ $ notification -> setIcon ( $ this -> urlGenerator -> getAbsoluteURL ( $ this -> urlGenerator -> imagePath ( ' text ' , ' app-dark.svg ' )));
5454 switch ($ notification ->getSubject ()) {
5555 case self ::TYPE_MENTIONED :
5656 $ parameters = $ notification ->getSubjectParameters ();
@@ -70,12 +70,13 @@ public function prepare(INotification $notification, string $languageCode): INot
7070 }
7171 $ node = $ userFolder ->getFirstNodeById ($ fileId );
7272
73- if ($ node === null ) {
73+ if (! $ node instanceof File ) {
7474 throw new AlreadyProcessedException ();
7575 }
7676
77- $ fileLink = $ this ->url ->linkToRouteAbsolute ('files.viewcontroller.showFile ' , ['fileid ' => $ node ->getId ()]);
77+ $ fileLink = $ this ->urlGenerator ->linkToRouteAbsolute ('files.viewcontroller.showFile ' , ['fileid ' => $ node ->getId ()]);
7878
79+ $ notification ->setLink ($ fileLink );
7980 $ notification ->setRichSubject ($ l ->t ('{user} has mentioned you in the text document {node} ' ), [
8081 'user ' => [
8182 'type ' => 'user ' ,
@@ -90,12 +91,13 @@ public function prepare(INotification $notification, string $languageCode): INot
9091 'link ' => $ fileLink ,
9192 ],
9293 ]);
94+
95+ $ this ->eventDispatcher ->dispatchTyped (new MentionEvent ($ notification , $ node ));
9396 break ;
9497 default :
9598 throw new UnknownNotificationException ();
9699 }
97- $ notification ->setIcon ($ this ->url ->getAbsoluteURL ($ this ->url ->imagePath ('text ' , 'app-dark.svg ' )));
98- $ notification ->setLink ($ fileLink );
100+
99101 $ this ->setParsedSubjectFromRichSubject ($ notification );
100102 return $ notification ;
101103 }
0 commit comments