Skip to content

Commit

Permalink
fix topic key for user events
Browse files Browse the repository at this point in the history
  • Loading branch information
abrkn committed Aug 19, 2024
1 parent 029ad46 commit 65e7fe4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ws/robust/subs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::super::ws_manager::{Message, SubscriptionSendData};
use super::super::ws_manager::{Message, Subscription, SubscriptionSendData};
use super::{Stream, Sub, SubId, SubToken, Subs, Unsubscribe};
use crate::BaseUrl;
use anyhow::Result;
Expand All @@ -24,6 +24,14 @@ impl Drop for SubToken {
}

impl Subs {
fn get_topic_key_for_subscription(topic: &Topic) -> String {
match topic {
Subscription::UserEvents { user: _ } => "userEvents".to_string(),
Subscription::OrderUpdates { user: _ } => "orderUpdates".to_string(),
_ => serde_json::to_string(topic).expect("Failed to convert subscription to string"),
}
}

pub async fn connect(
base_url: &BaseUrl,
mut cancel_rx: mpsc::Receiver<()>,
Expand Down Expand Up @@ -75,7 +83,7 @@ impl Subs {
.id_counter
.fetch_add(1, std::sync::atomic::Ordering::SeqCst);

let topic_key = serde_json::to_string(&topic)?;
let topic_key = Self::get_topic_key_for_subscription(&topic);

let sub = Sub {
id,
Expand Down

0 comments on commit 65e7fe4

Please sign in to comment.