Skip to content
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

fix: mark notifications as read should notify subscription watchers #564

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use {
rpc::{decode_key, AuthMessage, JsonRpcRequest, JsonRpcResponse, JsonRpcResponseError},
services::public_http_server::handlers::relay_webhook::{
error::{RelayMessageClientError, RelayMessageError, RelayMessageServerError},
handlers::decrypt_message,
handlers::{decrypt_message, notify_watch_subscriptions::send_to_subscription_watchers},
RelayIncomingMessage,
},
spec::{
Expand Down Expand Up @@ -214,26 +214,46 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
.map_err(RelayMessageServerError::JsonRpcResponseErrorSerialization)?,
};

let envelope = Envelope::<EnvelopeType0>::new(&sym_key, response)
.map_err(RelayMessageServerError::EnvelopeEncryption)?;
let response_fut = async {
let envelope = Envelope::<EnvelopeType0>::new(&sym_key, response)
.map_err(RelayMessageServerError::EnvelopeEncryption)?;
let response = base64::engine::general_purpose::STANDARD.encode(envelope.to_bytes());
publish_relay_message(
&state.relay_client,
&Publish {
topic: msg.topic.clone(),
message: response.into(),
tag: NOTIFY_MARK_NOTIFICATIONS_AS_READ_RESPONSE_TAG,
ttl_secs: NOTIFY_MARK_NOTIFICATIONS_AS_READ_RESPONSE_TTL.as_secs() as u32,
prompt: false,
},
Some(Arc::new(msg)),
state.metrics.as_ref(),
&state.analytics,
)
.await
.map_err(|e| RelayMessageServerError::NotifyServer(e.into())) // TODO change to client error?
};

let response = base64::engine::general_purpose::STANDARD.encode(envelope.to_bytes());
if let Some(watchers_with_subscriptions) = watchers_with_subscriptions {
let watcher_fut = async {
send_to_subscription_watchers(
watchers_with_subscriptions,
&state.notify_keys.authentication_secret,
&state.notify_keys.authentication_client_id,
&state.relay_client,
msg,
state.metrics.as_ref(),
&state.analytics,
)
.await
.map_err(RelayMessageServerError::SubscriptionWatcherSend)
};

publish_relay_message(
&state.relay_client,
&Publish {
topic: msg.topic.clone(),
message: response.into(),
tag: NOTIFY_MARK_NOTIFICATIONS_AS_READ_RESPONSE_TAG,
ttl_secs: NOTIFY_MARK_NOTIFICATIONS_AS_READ_RESPONSE_TTL.as_secs() as u32,
prompt: false,
},
Some(Arc::new(msg)),
state.metrics.as_ref(),
&state.analytics,
)
.await
.map_err(|e| RelayMessageServerError::NotifyServer(e.into()))?; // TODO change to client error?
tokio::try_join!(response_fut, watcher_fut)?;
} else {
response_fut.await?;
}

result.map(|_| ())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
topic: msg.topic.clone(),
});

// Problem: this doesn't send an update to the watcher that made the change (by design) but
// the request was to send these updates to all watchers for mark_notifications_as_read
let (sbs, watchers_with_subscriptions) = prepare_subscription_watchers(
&request_iss_client_id,
&request_auth.shared_claims.mjv,
Expand Down
Loading