diff --git a/src/main.rs b/src/main.rs index 8c5e69c..ddf9089 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,6 @@ use uuid::Uuid; use chrono::Utc; use std::sync::Arc; - #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] enum PayloadKind { @@ -56,8 +55,6 @@ async fn get_auth_id(token: &str) -> Result> { Ok(id) } -// Функция создает первый чат для пользователя. В чате два участника: пользователь и автор с идентификатором 1. -// Данные чата сохраняются в Redis. async fn create_first_chat(author_id: i32, con: &mut redis::aio::Connection) -> Result, Box> { let chat_id = Uuid::new_v4().to_string(); let members = vec![author_id.to_string(), "1".to_string()]; @@ -145,12 +142,14 @@ async fn sse_handler( }; let mut pubsub = con.into_pubsub(); - for chat_id in chats { - if let Err(e) = pubsub.subscribe(format!("chat:{}", chat_id)).await { - eprintln!("Failed to subscribe to chat: {}", e); + + let mut con = match redis.get_async_connection().await { + Ok(con) => con, + Err(e) => { + eprintln!("Failed to get async connection: {}", e); return HttpResponse::InternalServerError().finish(); } - } + }; let _ = match con.srem::<&str, &i32, usize>("authors-online", &author_id).await { Ok(_) => (), @@ -160,7 +159,7 @@ async fn sse_handler( } }; - let server_event = match Arc::clone(&rx).recv().await { + let server_event = match rx.recv().await { Ok(event) => event, Err(e) => { eprintln!("Failed to receive server event: {}", e);