Package org.moera.lib.pushrelay
Class PushRelay
java.lang.Object
org.moera.lib.jsonrpc.JsonRpcClient
org.moera.lib.pushrelay.PushRelay
- All Implemented Interfaces:
PushRelayApi
The
PushRelay
class provides an implementation of the PushRelayApi
interface
to interact with the Moera Push Relay API. It extends the JsonRpcClient
class to
handle JSON-RPC interactions with relays and sending push notifications.-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newPushRelay
instance and initializes it with the specified Push Relay server URL.PushRelay
(Function<JsonRpcRequest, JsonRpcResponse> fetcher) Constructs a newPushRelay
instance using a custom fetcher function to handle JSON-RPC requests and responses. -
Method Summary
Modifier and TypeMethodDescriptionvoid
feedStatus
(String feedName, int notViewed, long notViewedMoment, String nodeName, long signedAt, byte[] signature) Send a message to node's clients about number of new stories in a feed.protected <T> T
Performs a JSON-RPC call to invoke a method on a remote server.void
Register a client to receive messages from the specified node.void
storyAdded
(StoryInfo story, String nodeName, long signedAt, byte[] signature) Send a message to node's clients about a new story.void
storyDeleted
(String storyId, String nodeName, long signedAt, byte[] signature) Send a message to node's clients about deleting a story.
-
Constructor Details
-
PushRelay
Constructs a newPushRelay
instance and initializes it with the specified Push Relay server URL.- Parameters:
url
- the URL of the Push Relay server to connect to. It must be a valid HTTP or HTTPS URL.
-
PushRelay
Constructs a newPushRelay
instance using a custom fetcher function to handle JSON-RPC requests and responses.- Parameters:
fetcher
- aFunction
that takes aJsonRpcRequest
and returns aJsonRpcResponse
. This function serves as a custom handler for executing JSON-RPC interactions.
-
-
Method Details
-
fetch
Description copied from class:JsonRpcClient
Performs a JSON-RPC call to invoke a method on a remote server. Constructs a JSON-RPC request, sends it using the pre-configured fetcher, and processes the response. If the response contains an error, it throws aJsonRpcApiException
. If the response is successful, the result is converted to the specified type and returned.- Overrides:
fetch
in classJsonRpcClient
- Type Parameters:
T
- the type of the result object expected from the remote method- Parameters:
result
- the class type of the result object. If the expected result isnull
or the remote method does not return a value, the method will returnnull
.method
- the name of the remote method to invokeparameters
- the parameters to pass to the remote method- Returns:
- the result of the remote method call, converted to the specified type, or
null
if the remote method does not return a value
-
register
public void register(String clientId, String nodeName, String lang, long signedAt, byte[] signature) Description copied from interface:PushRelayApi
Register a client to receive messages from the specified node. The client will be unregistered automatically if the relay gets an error from the push service indicating that the client cannot receive messages anymore.- Specified by:
register
in interfacePushRelayApi
- Parameters:
clientId
- ID/token of the target client to receive messagesnodeName
- name of the node that will send messageslang
- language of the messages (use standard language codes, like "en_US" or "uk")signedAt
- timestamp of the signature, the signature will be valid 2 minutes after the time specifiedsignature
- the signature (useFingerprints.pushRelayRegister(java.lang.String, java.lang.String, java.sql.Timestamp)
fingerprint)
-
feedStatus
public void feedStatus(String feedName, int notViewed, long notViewedMoment, String nodeName, long signedAt, byte[] signature) Description copied from interface:PushRelayApi
Send a message to node's clients about number of new stories in a feed.- Specified by:
feedStatus
in interfacePushRelayApi
- Parameters:
feedName
- name of the feednotViewed
- number of stories that have not been viewed yetnotViewedMoment
- moment of the oldest non-viewed storynodeName
- name of the node that is sending the messagesignedAt
- timestamp of the signature, the signature will be valid 2 minutes after the time specifiedsignature
- the signature (useFingerprints.pushRelayMessage(java.sql.Timestamp)
fingerprint)
-
storyAdded
Description copied from interface:PushRelayApi
Send a message to node's clients about a new story.- Specified by:
storyAdded
in interfacePushRelayApi
- Parameters:
story
- the storynodeName
- name of the node that is sending the messagesignedAt
- timestamp of the signature, the signature will be valid 2 minutes after the time specifiedsignature
- the signature (useFingerprints.pushRelayMessage(java.sql.Timestamp)
fingerprint)
-
storyDeleted
Description copied from interface:PushRelayApi
Send a message to node's clients about deleting a story.- Specified by:
storyDeleted
in interfacePushRelayApi
- Parameters:
storyId
- ID of the storynodeName
- name of the node that is sending the messagesignedAt
- timestamp of the signature, the signature will be valid 2 minutes after the time specifiedsignature
- the signature (useFingerprints.pushRelayMessage(java.sql.Timestamp)
fingerprint)
-