Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update documentation to the new way #891
Update documentation to the new way #891
Changes from all commits
8bb67d7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Notification Workflow for an App that sends Notifications
Example story
Let's assume the following example scenario. Our app is the files_sharing app. We want to notify the user when a remote share has to be accepted/declined. If the user has dealt with it, we want to remove the notification again.
Creating a new Notification
\OCP\Notification\INotification
) from the manager (\OCP\Notification\IManager
):Setting app, user, timestamp, object and subject are mandatory. You should not use a translated subject, message or action label. Use something like a "language key", to avoid length problems with translations in the storage of a notification app. Translation is done via invocation of your notifier by the manager when the notification is prepared for display.
You should also try to avoid setting links and image paths here already, use keys again instead. This allows you to change the image/url of your application and also the admin can move the instance to another domain later, without breaking pending notifications. Also make sure, all your URLs are absolute URLs, so the notification icon and link also work from the desktop and mobile clients.
Preparing a notification for display
app.php
register your Notifier (\OCP\Notification\INotifier
) interface to the manager, using a\Closure
returning the Notifier and a\Closure
returning an array of the id and name:prepare()
method on your notifier. If the notification is not known by your app, just throw an\InvalidArgumentException
, but if it is actually from your app, you must set the parsed subject, message and action labels:Marking a notification as read/deleted/processed/obsoleted
If the user accepted the share or the share was removed/unshared, we want to remove the notification, because no user action is needed anymore. To do this, we simply have to call the
markProcessed()
method on the manager with theneccessarynecessary information on a notification object:Only the app name is mandatory: so if you don't set the user, the notification will be marked as processed for all users that have it. So the following example will remove all notifications for the app files_sharing on the object "remote #1337":
Defer and flush
Sometimes you might send multiple notifications in one request. In that case it makes sense to defer the sending, so in the end only one connection is done to the push server instead of 1 per notification.