Class UnifiedPushNotifier
java.lang.Object
page.codeberg.friedolyn.notifications.Notifier
page.codeberg.friedolyn.notifications.UnifiedPushNotifier
- All Implemented Interfaces:
Copyable<UnifiedPushNotifier>,Redactable
public class UnifiedPushNotifier
extends Notifier
implements Redactable, Copyable<UnifiedPushNotifier>
A
Notifier that sends notifications via the
UnifiedPush
protocol to a UP server that then forwards the notification to the user's device. This requires the user to have a
client app like Ntfy or
NextPush
installed on their device and to have enabled listening on a certain URL for notifications.-
Nested Class Summary
Nested classes/interfaces inherited from class page.codeberg.friedolyn.notifications.Notifier
Notifier.Mood -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ConfigurationProvides theclient configurationcontaining theandinvalid reference
user agent/invalid reference
DNTsettings that will be used when sending the notification.invalid reference
GPCstatic final @NonNull URLTheURLthat should be used if no other URL is specified.private final @NonNull HttpClientTheHttpClientthat sends the notifications to the UnifiedPush server at theURLspecified.private @NonNull URLThe URL that the user's UnifiedPush client is listening on for notifications and where the notification should be sent to. -
Constructor Summary
ConstructorsConstructorDescriptionUnifiedPushNotifier(@NonNull URL url) Creates a newUnifiedPushNotifierwith the givenURLused to send notifications.UnifiedPushNotifier(@NonNull URL url, @NonNull Configuration configuration) Creates a newUnifiedPushNotifierwith the givenURLused to send notifications and theclient configuration. -
Method Summary
Modifier and TypeMethodDescription@NonNull UnifiedPushNotifiercopy()booleanCompares thisUnifiedPushNotifierwith the givenObject.voidsendNotification(@NonNull String subject, @NonNull String summary, @NonNull String message, @NonNull Notifier.Mood mood) Sends a notification with the given subject, summary and message to the user.voidsetConfiguration(@NonNull Configuration configuration) Updates theconfigurationwith the newConfigurationobject reference.@NonNull StringtoString()@NonNull StringMethods inherited from class page.codeberg.friedolyn.notifications.Notifier
sendNotification
-
Field Details
-
url
The URL that the user's UnifiedPush client is listening on for notifications and where the notification should be sent to. -
configuration
Provides theclient configurationcontaining theandinvalid reference
user agent/invalid reference
DNTsettings that will be used when sending the notification.invalid reference
GPC- Implementation Note:
- We use
Configurationinstead ofClientdirectly in order not to miss out on any future changes to the settings if the entire Client object isreplaced. This may be quite a clumsy approach, and it might need to be refactored in the future.
-
DEFAULT_URL
-
httpClient
TheHttpClientthat sends the notifications to the UnifiedPush server at theURLspecified.
-
-
Constructor Details
-
UnifiedPushNotifier
Creates a newUnifiedPushNotifierwith the givenURLused to send notifications.- Parameters:
url- Where the notification should be sent to.
-
UnifiedPushNotifier
public UnifiedPushNotifier(@NonNull @NonNull URL url, @NonNull @NonNull Configuration configuration) Creates a newUnifiedPushNotifierwith the givenURLused to send notifications and theclient configuration.- Parameters:
url- Where the notification should be sent to.configuration- Itsclient configurationwill be used when sending the notification to specify theand theinvalid reference
user agent/invalid reference
DNTsettings.invalid reference
GPC
-
-
Method Details
-
sendNotification
public void sendNotification(@NonNull @NonNull String subject, @NonNull @NonNull String summary, @NonNull @NonNull String message, @NonNull @NonNull Notifier.Mood mood) throws RuntimeException Sends a notification with the given subject, summary and message to the user.- Specified by:
sendNotificationin classNotifier- Parameters:
subject- What the notification is about. Must not be blank.summary- A short version of the message. Should be a one-liner that summarises the full message. Must not be blank.message- Since the character count in Android notifications is limited, the full message is ignored.mood- Whether the content of the message contains news that the user will likely perceive as positive, or negative (or neither – in which case the mood is neutral).- Throws:
RuntimeException- If the notification could not be sent or if the subject or summary is blank.- See Also:
-
setConfiguration
Updates theconfigurationwith the newConfigurationobject reference. -
copy
- Specified by:
copyin interfaceCopyable<UnifiedPushNotifier>- Returns:
- A new
UnifiedPushNotifierwith the sameURLas this one. Does NOT copy theHttpClient. - See Also:
-
equals
Compares thisUnifiedPushNotifierwith the givenObject. Does NOT compare theHttpClients. When comparing theconfigurations, only theclient configurationsare checked for equality, because these hold the values relevant for this notifier and because callingequalson the configuration might lead to recursive calls to this method (due to theConfiguration.getNotifications()reference).- Overrides:
equalsin classObject- Parameters:
object- The Object to compare this UnifiedPushNotifier with.- Returns:
-
trueif the given object is an UnifiedPushNotifier whose fields' values (deeply) match their equivalents in this UnifiedPushNotifier}, especially (but not exclusively) if the given UnifiedPushNotifier is the exact same reference as this UnifiedPushNotifier. -
falseif the given object is not a UnifiedPushNotifier or if any of the fields' values differ from their equivalents in this UnifiedPushNotifier.
-
-
toString
- Specified by:
toStringin interfaceRedactable- Specified by:
toStringin classNotifier- Returns:
- A string representation of this object including all fields, even sensitive ones.
-
toStringRedacted
Description copied from class:Notifier- Specified by:
toStringRedactedin interfaceRedactable- Specified by:
toStringRedactedin classNotifier- Returns:
- A string representation of this object including all fields. However, sensitive fields will be removed or replaced with a placeholder. The exact behaviour is implementation-specific and may depend on the debug level currently in effect.
- See Also:
-