z4k
September 14, 2022, 3:22pm
1
Hi everyone
I’m a beginner in the operation of a Listener and a Notification.
So, I followed this documentation notifications/notification-workflow.md at master · nextcloud/notifications · GitHub
I wrote this code in my Application.php file workspace/Application.php at 5e04c19b8c220ada8425595072233cbe90707b02 · arawa/workspace · GitHub
In my GroupController.php file workspace/GroupController.php at 848ad17ac58bc8a09534bfb3bec9e1d2bd883627 · arawa/workspace · GitHub
And I created the Notifier.php file which implements the OCP\Notification\INotifier interface workspace/Notifier.php at experiment/create-notification · arawa/workspace · GitHub
But, when I have added a user to a group, I don’t get a notification here
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’t understand how the Notification system works.
Can someone help me understand, please ?
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’s 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?
z4k
September 15, 2022, 7:23am
3
I don’t know… I don’t know if I’m using the Notifier.php correctly
I also don’t know if the code written in the GroupController.php file should be used
Hmmm… What is it replaced by ?
It’s right !
No notification is shown in the web UI and I don’t understand why ><
I don’t know if the throw errors are in the logs file or elsewhere ?
But, no, I don’t set-debug yet ^^’
I think it’s this line code is not correct : workspace/lib/Notification/Notifier.php at 5e04c19b8c220ada8425595072233cbe90707b02 · arawa/workspace · GitHub
Because, the function doesn’t not exist…
One more, I think that these lines could cause errors :
In general, I’d 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);
z4k:
I don’t know if the throw errors are in the logs file or elsewhere ?
But, no, I don’t set-debug yet ^^’
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?
z4k
September 15, 2022, 2:14pm
5
christianlupus:
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);
Yes, I replaced $manager =\OC:: $server->get(IManager::class);
by $manager = $server->get(IManager::class);
.
christianlupus:
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.
I don’t 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 172.19.0.3. 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’t 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
kesselb
September 16, 2022, 9:05pm
6
Hi,
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 boot
is 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)
Notifier.prepare
.
It’s 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
2 Likes
z4k
September 19, 2022, 10:28am
7
Thanks @kesselb
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
But, I don’t understand the what this has to do with the Listener ?
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?