fixes-16
This commit is contained in:
parent
f693a8418e
commit
fd22aeb518
15
src/main.rs
15
src/main.rs
|
@ -87,8 +87,6 @@ async fn create_first_chat(author_id: i32, con: &mut redis::aio::Connection) ->
|
||||||
Ok(vec![chat.to_string()])
|
Ok(vec![chat.to_string()])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция проверяет токен пользователя, получает список чатов пользователя из Redis
|
|
||||||
// и подписывается на события этих чатов. Если у пользователя нет чатов, создается первый чат.
|
|
||||||
async fn sse_handler(
|
async fn sse_handler(
|
||||||
token: web::Path<String>,
|
token: web::Path<String>,
|
||||||
mut rx: web::Data<Receiver<String>>,
|
mut rx: web::Data<Receiver<String>>,
|
||||||
|
@ -110,7 +108,7 @@ async fn sse_handler(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let _: () = match con.command("SADD", "authors-online", &author_id).await {
|
let _: () = match con.sadd("authors-online", &author_id).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to add author to online list: {}", e);
|
eprintln!("Failed to add author to online list: {}", e);
|
||||||
|
@ -135,12 +133,12 @@ async fn sse_handler(
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to get chats by author: {}", e);
|
eprintln!("Failed to get chats by author: {}", e);
|
||||||
match create_first_chat(author_id, &mut con).await {
|
match create_first_chat(author_id, &mut con).await {
|
||||||
Ok(chat) => chat,
|
Ok(chat) => chat,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to create first chat: {}", e);
|
eprintln!("Failed to create first chat: {}", e);
|
||||||
return HttpResponse::InternalServerError().finish();
|
return HttpResponse::InternalServerError().finish();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,7 +158,6 @@ async fn sse_handler(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Later in the sse_handler function
|
|
||||||
let server_event = match rx.recv().await {
|
let server_event = match rx.recv().await {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user