feat: add notifications when sharing articles with users#3542
feat: add notifications when sharing articles with users#3542Grotax merged 7 commits intonextcloud:masterfrom
Conversation
892bdfa to
61db68c
Compare
|
Hi @Grotax how are you? |
|
No |
What's wrong? I'd like to contribute so I put the PR for feed-io as well as here... |
|
I review when I have time and energy and your pinging is not helpful. |
There was a problem hiding this comment.
Pull request overview
This PR adds Nextcloud in-app notifications for the News app when an article is shared with another user, by registering a notification Notifier and sending a notification from ShareService::shareItemWithUser().
Changes:
- Register a News
Notifierwith Nextcloud’s notification framework. - Send a “shared article” notification after successfully sharing an item.
- Add unit tests for the Notifier and update ShareService unit tests to assert notification behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
lib/AppInfo/Application.php |
Registers the News notification notifier service. |
lib/Service/ShareService.php |
Injects OCP\Notification\IManager and sends a notification after sharing. |
lib/Notification/Notifier.php |
Implements notification preparation (parsed/rich subject, link, icon). |
tests/Unit/Service/ShareServiceTest.php |
Adds notification manager + notification expectations for sharing tests. |
tests/Unit/Notification/NotifierTest.php |
New unit tests covering notifier behavior and edge cases. |
e89c95f to
70027d3
Compare
Users now receive a notification when someone shares an article with them. The notification includes: - Sharer's display name - Article title (truncated if > 100 chars) - Clickable link to open the News app - News app icon Implementation details: - Added Notifier class implementing INotifier interface - Registered notifier in Application.php - ShareService sends notification after successful share - Notification failures are logged but don't break the share flow Fixes nextcloud#2102 (notification part - focus fix was already implemented) Signed-off-by: eureka928 <meobius123@gmail.com> Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
… add Notifier tests Replace hardcoded 'news' string with Application::NAME in ShareService and use the proper UnknownNotificationException from the Nextcloud notification API instead of \InvalidArgumentException in the Notifier. Add unit tests for the Notifier class. Signed-off-by: eureka928 <meobius123@gmail.com> Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
70027d3 to
4279e10
Compare
| throw new UnknownNotificationException(); | ||
| } | ||
|
|
||
| $l = $this->l10nFactory->get(Application::NAME, $languageCode); |
There was a problem hiding this comment.
Please give variables a descriptive name. L is not enough to know it's an l10n factory
|
|
||
| $l = $this->l10nFactory->get(Application::NAME, $languageCode); | ||
|
|
||
| switch ($notification->getSubject()) { |
There was a problem hiding this comment.
This looks nicer as a match
| private function prepareSharedArticle(INotification $notification, \OCP\IL10N $l): INotification | ||
| { | ||
| $params = $notification->getSubjectParameters(); | ||
| $sharerUserId = $params['sharedBy'] ?? ''; |
There was a problem hiding this comment.
When would this be null?
Changed - Notifications for shared articles - recipients now receive a notification when someone shares an article with them (#3542) Fixed - global starred count not updated when deleting a feed with starred items (#3507) - feed fetcher requests may get stuck (#3528) - feed logo download and `fulltext` scraper don't use configured proxy (#3533) - Dependency scoping incompatible with auto-downloaded composer (#3418) Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Changed - Notifications for shared articles - recipients now receive a notification when someone shares an article with them (#3542) Fixed - global starred count not updated when deleting a feed with starred items (#3507) - feed fetcher requests may get stuck (#3528) - feed logo download and `fulltext` scraper don't use configured proxy (#3533) - Dependency scoping incompatible with auto-downloaded composer (#3418) Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Summary
This PR adds in-app notifications when a user shares an article with another user, addressing the second issue reported in #2102.
Notifierservice in the Nextcloud notification framework to prepare and display share notificationsShareService::shareItemWithUser()with the sharer's name and article titleUnknownNotificationExceptionper the Nextcloud notification API docsApplication::NAMEconstant instead of hardcoded'news'stringNew files
lib/Notification/Notifier.php- INotifier implementation for the News apptests/Unit/Notification/NotifierTest.php- Unit tests for the Notifier classModified files
lib/AppInfo/Application.php- Registers the Notifier servicelib/Service/ShareService.php- Sends notification after sharingtests/Unit/Service/ShareServiceTest.php- Updated with notification expectationsChecklist