Skip to content

Commit

Permalink
Fix graphql__ws_client
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi311 committed Sep 10, 2024
1 parent 089a806 commit 1aedf67
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions crates/tanoshi-web/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub async fn fetch_recent_updates(

pub async fn subscribe_recent_updates() -> Result<(), Box<dyn Error>> {
use futures::StreamExt;
use graphql_ws_client::{graphql::StreamingOperation, GraphQLClientClientBuilder};
use graphql_ws_client::{graphql::StreamingOperation, Client};
use serde::Serialize;
use web_sys::{Notification, NotificationOptions};

Expand All @@ -257,20 +257,12 @@ pub async fn subscribe_recent_updates() -> Result<(), Box<dyn Error>> {
let (ws, wsio) =
ws_stream_wasm::WsMeta::connect(graphql_ws_host(), Some(vec!["graphql-transport-ws"]))
.await?;
let (sink, stream) = graphql_ws_client::wasm_websocket_combined_split(ws, wsio).await;

let token = local_storage()
.get("token")
.unwrap_throw()
.unwrap_or_else(|| "".to_string());
let mut client = GraphQLClientClientBuilder::new()
.payload(Payload { token })
.build(stream, sink, async_executors::AsyncStd)
.await?;
let connection = graphql_ws_client::ws_stream_wasm::Connection::new((ws, wsio)).await;
let (client, _): (Client, graphql_ws_client::ConnectionActor) = Client::build(connection).await?;

let op: StreamingOperation<SubscribeChapterUpdates> =
StreamingOperation::new(subscribe_chapter_updates::Variables {});
let mut stream = client.streaming_operation(op).await?;
let mut stream = client.subscribe(op).await?;

let mut updates = HashMap::<String, Vec<String>>::new();
loop {
Expand All @@ -290,13 +282,13 @@ pub async fn subscribe_recent_updates() -> Result<(), Box<dyn Error>> {
}
Either::Right((_, _)) => {
for (manga_title, chapters) in updates.iter() {
let mut opts = NotificationOptions::new();
let opts = NotificationOptions::new();
if chapters.len() > 1 {
opts.body(&format!("{} chapter updates", chapters.len()));
opts.set_body(&format!("{} chapter updates", chapters.len()));
} else if chapters.len() == 1 {
opts.body(&chapters[0]);
opts.set_body(&chapters[0]);
} else {
opts.body("no chapter updates");
opts.set_body("no chapter updates");
}

let _ = Notification::new_with_options(&manga_title, &opts).unwrap_throw();
Expand Down

0 comments on commit 1aedf67

Please sign in to comment.