How to work the Notification and Listener system?

Hi everyone :slight_smile:

I鈥檓 a beginner in the operation of a Listener and a Notification.
So, I followed this documentation :point_right: notifications/ at master 路 nextcloud/notifications 路 GitHub

I wrote this code in my Application.php file :point_right: workspace/Application.php at 5e04c19b8c220ada8425595072233cbe90707b02 路 arawa/workspace 路 GitHub

In my GroupController.php file :point_right: workspace/GroupController.php at 848ad17ac58bc8a09534bfb3bec9e1d2bd883627 路 arawa/workspace 路 GitHub

And I created the Notifier.php file which implements the OCP\Notification\INotifier interface :point_right: workspace/Notifier.php at experiment/create-notification 路 arawa/workspace 路 GitHub

But, when I have added a user to a group, I don鈥檛 get a notification here :point_down:

In my oc_notifications I have notifications that are recorded :

MariaDB [nextcloud]> select * from oc_notifications where app="workspace";
| notification_id | app       | user   | timestamp  | object_type | object_id | subject        | subject_parameters         | message | message_parameters | link | icon | actions                                                                                                                                      |
|              14 | workspace | bstark | 1663160845 | add         | 1337      | add_user_group | {"groupname":"SPACE-U-24"} |         | []                 |      |      | [{"label":"accept","link":"workspace","type":"POST","primary":false},{"label":"decline","link":"workspace","type":"DELETE","primary":false}] |
|              16 | workspace | bstark | 1663167584 | add         | 1337      | add_user_group | {"groupname":"SPACE-U-24"} |         | []                 |      |      | [{"label":"accept","link":"workspace","type":"POST","primary":false},{"label":"decline","link":"workspace","type":"DELETE","primary":false}] |
2 rows in set (0.006 sec)

So, I don鈥檛 understand how the Notification system works.

Can someone help me understand, please ? :pray:

Honestly, I do not see any obvious error in your code. I have however never worked with notifications and my impression is that the documentation is a bit dated (It鈥檚 usage of \OC:$server is deprecated). But it should still work, theoretically.

As far as I understand your code, the notifications are stored in the database correctly but only no notification entry is shown in the web UI, right?

Could it be that there is an exception thrown for some reason? Have you tried to step-debug things?

I don鈥檛 know鈥 I don鈥檛 know if I鈥檓 using the Notifier.php correctly :thinking:

I also don鈥檛 know if the code written in the GroupController.php file should be used :no_mouth:

Hmmm鈥 What is it replaced by ?

It鈥檚 right ! :+1:
No notification is shown in the web UI and I don鈥檛 understand why ><

I don鈥檛 know if the throw errors are in the logs file or elsewhere ?

But, no, I don鈥檛 set-debug yet ^^鈥

I think it鈥檚 this line code is not correct : workspace/Notifier.php at 5e04c19b8c220ada8425595072233cbe90707b02 路 arawa/workspace 路 GitHub

Because, the function doesn鈥檛 not exist鈥

One more, I think that these lines could cause errors :

In general, I鈥檇 say, you are doing it correctly. At least, some data is written to the DB. There might be bugs still present but these can be solved later on.

Everything in \OC should be avoided. Only use \OCP if possible. Everything in \OC might change without prior deprecation.

Normally, the constructor arguments and the method parameters are to be used to allow for dependency injection. For example, you should be able to do instead of querying

$manager = $server->get(IManager::class);

Enable all debug logs you can on your dev environment.

Not all exceptions are handled as a logged message. Many are watched. For example, this line will most probably be caught.

Maybe using step-debugging might shade some light on the problem. Then you can see if the Notifier is triggered and if the Notifier is getting the information as expected.

What are you missing? The $this->shareManager is not a function. Which function are you referring to?

Yes, I replaced $manager =\OC:: $server->get(IManager::class); by $manager = $server->get(IManager::class);.

I don鈥檛 understand鈥 However I enabled the debug mode and no log is displayed even in the errors for the moment鈥

# No log
zak@strange:~/Documents/arawa/codes/docker-nextcloud-dev/logs/apache2$ tail -f error.log 
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
[Thu Sep 15 13:58:33.200474 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.53 (Debian) PHP/8.0.18 configured -- resuming normal operations
[Thu Sep 15 13:58:33.200538 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

Yes, I wrote very fast ^^鈥
I meant to say, I don鈥檛 have the shareManager object in my constructor.

I commented on all the lines with this object. But, I still have the same problem for the moment


had a quick look at your latest version (commit draft(): Testing to push a notificaition 路 arawa/workspace@15d13b7 路 GitHub).

Topic 1)

Application.boot is used to register the notifier. However bootis only called when your Application class implements the IBootstrap interface. Please have a look at our documentation at Bootstrapping 鈥 Nextcloud latest Developer Manual latest documentation and migrate your app as soon as possible.

As workaround, until you migrated to IBootstrap, move registerNotifierService to the constructor.


Topic 2)



It鈥檚 mandatory to call setParsedSubject in the notifier.
In addition I changed the type to highlight.

When I add myself to a worksapce the following notfication is generated


Happy hacking :robot:


Thanks @kesselb :slight_smile:

I think to understand 50% of the Notification system !
I think I have implemented the IBootstrap interface correctly : workspace/Application.php at experiment/create-notification 路 arawa/workspace 路 GitHub ?

I tried to add my middlewares with the registerMiddleware method and I think it is working ?

And yes, I received my notification correctly :slight_smile:

But, I don鈥檛 understand the what this has to do with the Listener ? :thinking:

1 Like

Where are you referring to a listener? I do not see anywhere a reference and in your code there is no text listener present. Can you please direct us in the right direction?