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 Configuration
Provides theclient configuration
containing theinvalid reference
user agent
invalid reference
DNT
invalid reference
GPC
static final @NonNull URL
TheURL
that should be used if no other URL is specified.private final @NonNull HttpClient
TheHttpClient
that sends the notifications to the UnifiedPush server at theURL
specified.private @NonNull URL
The 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 newUnifiedPushNotifier
with the givenURL
used to send notifications.UnifiedPushNotifier
(@NonNull URL url, @NonNull Configuration configuration) Creates a newUnifiedPushNotifier
with the givenURL
used to send notifications and theclient configuration
. -
Method Summary
Modifier and TypeMethodDescription@NonNull UnifiedPushNotifier
copy()
boolean
Compares thisUnifiedPushNotifier
with the givenObject
.void
sendNotification
(@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.void
setConfiguration
(@NonNull Configuration configuration) Updates theconfiguration
with the newConfiguration
object reference.@NonNull String
toString()
@NonNull String
Methods 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 configuration
containing theinvalid reference
user agent
invalid reference
DNT
invalid reference
GPC
- Implementation Note:
- We use
Configuration
instead ofClient
directly 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
TheHttpClient
that sends the notifications to the UnifiedPush server at theURL
specified.
-
-
Constructor Details
-
UnifiedPushNotifier
Creates a newUnifiedPushNotifier
with the givenURL
used 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 newUnifiedPushNotifier
with the givenURL
used to send notifications and theclient configuration
.- Parameters:
url
- Where the notification should be sent to.configuration
- Itsclient configuration
will be used when sending the notification to specify theinvalid reference
user agent
invalid reference
DNT
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:
sendNotification
in 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 theconfiguration
with the newConfiguration
object reference. -
copy
- Specified by:
copy
in interfaceCopyable<UnifiedPushNotifier>
- Returns:
- A new
UnifiedPushNotifier
with the sameURL
as this one. Does NOT copy theHttpClient
. - See Also:
-
equals
Compares thisUnifiedPushNotifier
with the givenObject
. Does NOT compare theHttpClients
. When comparing theconfigurations
, only theclient configurations
are checked for equality, because these hold the values relevant for this notifier and because callingequals
on the configuration might lead to recursive calls to this method (due to theConfiguration.getNotifications()
reference).- Overrides:
equals
in classObject
- Parameters:
object
- The Object to compare this UnifiedPushNotifier with.- Returns:
-
true
if 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. -
false
if the given object is not a UnifiedPushNotifier or if any of the fields' values differ from their equivalents in this UnifiedPushNotifier.
-
-
toString
- Specified by:
toString
in interfaceRedactable
- Specified by:
toString
in classNotifier
- Returns:
- A string representation of this object including all fields, even sensitive ones.
-
toStringRedacted
Description copied from class:Notifier
- Specified by:
toStringRedacted
in interfaceRedactable
- Specified by:
toStringRedacted
in 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:
-