diff --git a/Cargo.lock b/Cargo.lock index e3c0474..9655f6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -232,6 +232,21 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "async-trait" version = "0.1.73" @@ -349,6 +364,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + [[package]] name = "combine" version = "4.6.6" @@ -458,12 +487,14 @@ name = "discoursio-presense" version = "0.2.0" dependencies = [ "actix-web", + "chrono", "futures", "redis", "reqwest", "serde", "serde_json", "tokio", + "uuid", ] [[package]] @@ -760,6 +791,29 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.4.0" @@ -918,6 +972,15 @@ dependencies = [ "tempfile", ] +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -1575,6 +1638,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "uuid" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1700,6 +1769,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 1867f61..b66ae41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,8 @@ serde_json = "1.0" tokio = { version = "1", features = ["full"] } reqwest = { version = "0.11", features = ["json"] } futures = "0.3.28" +uuid = "1.4.1" +chrono = "0.4" [[bin]] name = "presense" diff --git a/src/main.rs b/src/main.rs index f030675..2b593bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,8 @@ use std::env; use std::error::Error; use futures::StreamExt; use tokio::sync::broadcast::{self, Receiver}; +use uuid::Uuid; +use chrono::Utc; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] @@ -54,21 +56,18 @@ async fn get_auth_id(token: &str) -> Result> { async fn create_first_chat(author_id: i32) -> Vec { - let chat_id = uuid::Uuid::new_v4().to_string(); + let chat_id = Uuid::new_v4().to_string(); let members = vec![author_id.to_string(), "1".to_string()]; - let title = ""; - let created_by = author_id; - let timestamp = chrono::Utc::now().timestamp(); - let admins = if members.len() == 2 && title.is_empty() { members.clone() } else { vec![] }; + let timestamp = Utc::now().timestamp(); let chat = serde_json::json!({ "id": chat_id, - "users": members, - "title": title, - "createdBy": created_by, + "admins": members, + "members": members.clone(), + "title": "", + "createdBy": author_id, "createdAt": timestamp, "updatedAt": timestamp, - "admins": admins, }); let _: () = redis::pipe() @@ -92,7 +91,7 @@ async fn sse_handler( let author_id = match get_auth_id(&token).await { Ok(id) => id, Err(e) => { - eprintln!("Не удалось проверить токен: {}", e); + eprintln!("TOKEN check failed: {}", e); return HttpResponse::Unauthorized().finish(); } };