fixes-14
This commit is contained in:
parent
1535e1a36c
commit
30b7282cfe
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -484,7 +484,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "discoursio-presense"
|
name = "discoursio-presense"
|
||||||
version = "0.2.0"
|
version = "0.2.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -57,7 +57,20 @@ async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
|
||||||
// Функция создает первый чат для пользователя. В чате два участника: пользователь и автор с идентификатором 1.
|
// Функция создает первый чат для пользователя. В чате два участника: пользователь и автор с идентификатором 1.
|
||||||
// Данные чата сохраняются в Redis.
|
// Данные чата сохраняются в Redis.
|
||||||
async fn create_first_chat(author_id: i32, con: &mut redis::aio::Connection) -> Result<Vec<String>, Box<dyn Error>> {
|
async fn create_first_chat(author_id: i32, con: &mut redis::aio::Connection) -> Result<Vec<String>, Box<dyn Error>> {
|
||||||
// ...
|
let chat_id = Uuid::new_v4().to_string();
|
||||||
|
let members = vec![author_id.to_string(), "1".to_string()];
|
||||||
|
let timestamp = Utc::now().timestamp();
|
||||||
|
|
||||||
|
let chat = serde_json::json!({
|
||||||
|
"id": chat_id.clone(),
|
||||||
|
"admins": members.clone(),
|
||||||
|
"members": members.clone(),
|
||||||
|
"title": "",
|
||||||
|
"createdBy": author_id,
|
||||||
|
"createdAt": timestamp,
|
||||||
|
"updatedAt": timestamp,
|
||||||
|
});
|
||||||
|
|
||||||
let _: () = redis::pipe()
|
let _: () = redis::pipe()
|
||||||
.atomic()
|
.atomic()
|
||||||
.cmd("SADD")
|
.cmd("SADD")
|
||||||
|
@ -70,6 +83,7 @@ async fn create_first_chat(author_id: i32, con: &mut redis::aio::Connection) ->
|
||||||
.ignore()
|
.ignore()
|
||||||
.query_async(con)
|
.query_async(con)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(vec![chat.to_string()])
|
Ok(vec![chat.to_string()])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +118,7 @@ async fn sse_handler(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let chats: Vec<String> = match con.smembers(format!("chats_by_author/{}", author_id)).await {
|
let chats: Vec<String> = match con.smembers::<String, Vec<String>>(format!("chats_by_author/{}", author_id)).await {
|
||||||
Ok(chats) => {
|
Ok(chats) => {
|
||||||
if chats.is_empty() {
|
if chats.is_empty() {
|
||||||
match create_first_chat(author_id, &mut con).await {
|
match create_first_chat(author_id, &mut con).await {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user