Bug 462278

Summary: Actions in Notification portal totally broken
Product: [Plasma] xdg-desktop-portal-kde Reporter: Ilya Fedin <fedin-ilja2010>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: aleixpol, butirsky, jgrulich, kdebugs.81do7, nate
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.26.5
Sentry Crash Report:
Attachments: AddNotification
ActionInvoked

Description Ilya Fedin 2022-11-26 16:21:39 UTC
SUMMARY
xdg-desktop-portal-kde doesn't remember action IDs and the target parameter supplied by applications and sends ActionInvoked signal with action ID used with communication to org.freedesktop.Notifications, but the application communicatin to the portal doesn't know anyhing about those IDs and expects the IDs and target parameters it supplied to the portal.

It's also worth mentioning that for compatibility with applications using GNotification, org.freedesktop.Application.ActivateAction should be supported: https://github.com/flatpak/xdg-desktop-portal-gtk/blob/9702bacc1ae8de2f357974ced2bcd6997dfd4e69/src/notification.c#L119-L158

STEPS TO REPRODUCE
1. Get a notification with actions using the portal spec
2. Try to click on a button on the notificiation

OBSERVED RESULT
Nothing happens

EXPECTED RESULT
Application doing the action

SOFTWARE/OS VERSIONS
Operating System: NixOS 22.11
KDE Plasma Version: 5.26.3
KDE Frameworks Version: 5.99.0
Qt Version: 5.15.7
Kernel Version: 6.0.7-zen1 (64-bit)
Graphics Platform: Wayland
Processors: 8 × AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
Memory: 5.7 GB of RAM
Graphics Processor: AMD Radeon Vega 8 Graphics
Comment 1 Aleix Pol 2022-11-28 18:51:35 UTC
I've been looking your report up, but I was unable to reproduce the behaviour you are describing. Would you be able to provide a small test app that exposes the problem?

Regarding the latter case, it indeed is missing but is a separate issue.
Comment 2 Ilya Fedin 2022-11-28 19:09:38 UTC
Created attachment 154117 [details]
AddNotification
Comment 3 Ilya Fedin 2022-11-28 19:10:26 UTC
Created attachment 154118 [details]
ActionInvoked
Comment 4 Ilya Fedin 2022-11-28 19:10:39 UTC
I don't think I'll be able to write a small test app (as GNotification uses ActivateAction, KNotification is written that it avoids this issue and writing new spec implementation wouldn't be small). What I propose instead is to look at d-bus traffic between the portal and any application using GNotification. Even though GNotification doesn't watch from ActionInvoked signal, it's seen that the content of the signal is broken. Here's a screenshot of the action list from Telegram and the ActionInvoked signal produced by the portal implementation. It's seen that Telegram has no numeric actions and has target parameter for every of them, but ActionInvoked content is completely different.
Comment 5 Ilya Fedin 2022-11-28 19:15:51 UTC
It's also pretty obvious from the code: https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/master/src/notification.cpp#L125
It should have some map between the uint id and action name/target parameter supplied by the application, but it just supplies the uint id from KNotification library instead.
Comment 6 Ilya Fedin 2022-11-28 19:16:18 UTC
The application I use to monitor D-Bus traffic is Bustle
Comment 7 Bug Janitor Service 2022-11-28 19:55:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/140
Comment 8 Aleix Pol 2022-12-15 14:47:43 UTC
Git commit c53684f5b6d27b17938982e6333d574636dd4016 by Aleix Pol.
Committed on 15/12/2022 at 00:52.
Pushed by apol into branch 'master'.

notifications: Properly communicate the triggered action

Infer the action name from the originally communicated action name.

M  +34   -10   src/notification.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/commit/c53684f5b6d27b17938982e6333d574636dd4016
Comment 9 Aleix Pol 2022-12-15 14:47:51 UTC
Git commit 77c312560f0d240a553c074d96df438c75e1430a by Aleix Pol Gonzalez, on behalf of Aleix Pol.
Committed on 15/12/2022 at 00:00.
Pushed by apol into branch 'master'.

notification: Trigger org.freedesktop.Application.Activate* as spec'd

For some reason, it was spec'd that these should be called, so we better
follow through.

A  +17   -0    data/org.freedesktop.Application.xml
M  +2    -0    src/CMakeLists.txt
M  +24   -5    src/notification.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/commit/77c312560f0d240a553c074d96df438c75e1430a
Comment 10 Bug Janitor Service 2022-12-15 15:03:50 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/142
Comment 11 Aleix Pol 2022-12-15 15:34:17 UTC
Git commit 4f8df470f8b3b9df1844d606a05b3c83cce88772 by Aleix Pol.
Committed on 15/12/2022 at 15:02.
Pushed by apol into branch 'Plasma/5.26'.

notifications: Properly communicate the triggered action

Infer the action name from the originally communicated action name.
(cherry picked from commit c53684f5b6d27b17938982e6333d574636dd4016)

M  +34   -10   src/notification.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/commit/4f8df470f8b3b9df1844d606a05b3c83cce88772
Comment 12 Aleix Pol 2022-12-15 15:34:26 UTC
Git commit 511bced812cc0615dfa8b827a1c108db4b3e919f by Aleix Pol.
Committed on 15/12/2022 at 15:02.
Pushed by apol into branch 'Plasma/5.26'.

notification: Trigger org.freedesktop.Application.Activate* as spec'd

For some reason, it was spec'd that these should be called, so we better
follow through.
(cherry picked from commit 77c312560f0d240a553c074d96df438c75e1430a)

A  +17   -0    data/org.freedesktop.Application.xml
M  +2    -0    src/CMakeLists.txt
M  +24   -5    src/notification.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/commit/511bced812cc0615dfa8b827a1c108db4b3e919f