make addUser request work

This commit is contained in:
Horhik 2021-04-16 20:00:21 +03:00
parent f876588add
commit 7c447bd6f8
6 changed files with 27 additions and 19 deletions

View file

@ -52,7 +52,7 @@ pub fn send_message(user_id: Id, message: String, conn: &Connection, server_send
let db_message = db::types::Message {
id: message_id,
date: chrono::offset::Local::now(),
user_id: Id(uuid::Uuid::parse_str(identifier).unwrap()),
user_id: Id(uuid::Uuid::parse_str(identifier).expect("failed to parse user ID")),
message: message.clone(),
from_me: false,
};

View file

@ -17,28 +17,42 @@ pub fn request_selector(json: &str, server_sender: SP, conn: &Connection) -> Res
let parsed: Request = serde_json::from_str(json).unwrap();
match parsed{
Request::StartApp => {
handlers::start_app(server_sender.clone())?
match handlers::start_app(server_sender.clone()) {
Ok(_) => return Ok(()),
Err(_) => {}
// Sending error to user, because failed to add user
// let _ = server_sender
// .clone()
// .send(PackedMessage::ToClient(
// json!(AppError {
// res_type: ErrorType::FailedToAddUser
// })
// .to_string(),
// ))
// .unwrap();
// return Ok(());
}
},
Request::StopApp => {
handlers::stop_app(&conn, server_sender.clone())?
match handlers::stop_app(&conn, server_sender.clone()) { Ok(_) => {}, Err(_) => {} }
},
Request::LoadUsers => {
handlers::load_users(&conn, server_sender.clone())?
match handlers::load_users(&conn, server_sender.clone()){ Ok(_) => {}, Err(_) => {} }
},
Request::SendMessage {
user_id, message
} => {
handlers::send_message(user_id, message, &conn, server_sender.clone())?
match handlers::send_message(user_id, message, &conn, server_sender.clone()){ Ok(_) => {}, Err(_) => {} }
},
Request::LoadMessages{
user_id, count, start_index
} => {
handlers::load_messages(user_id, start_index, count, &conn, server_sender.clone())?
match handlers::load_messages(user_id, start_index, count, &conn, server_sender.clone()){ Ok(_) => {}, Err(_) => {} }
},
Request::AddUser{
name, sign_key, insert_key
} => {
handlers::add_user(name, insert_key, sign_key, &conn, server_sender.clone())?
match handlers::add_user(name, insert_key, sign_key, &conn, server_sender.clone()){ Ok(_) => {}, Err(_) => {} }
},
}

View file

@ -77,13 +77,6 @@ async fn connection_for_receiving(
log::info!("Connection for receiving launched");
while let Ok(res) = client_receiver.recv() {
//TODO call client get after receiving NodeHello
/*
if res.message.lines().next() == Some("NodeHello") {
let server_sender = server_sender.clone();
task::spawn(request_repeater(server_sender)).await?;
log::info!("Client received: \n {}", res.message);
}
*/
match res {
PackedMessage::FromCore(json) => {
sender

View file

@ -11,7 +11,7 @@ pub async fn request_repeater(ss: SP) -> io::Result<()> {
//TODO create a field with tracked users
let time = std::time::Duration::from_millis(1000);
std::thread::sleep(time);
match ss.send(PackedMessage::FromFreenet(
match ss.send(PackedMessage::ToFreenet(
ClientGet::new_default(SSK{sign_key: "9Zq-H7vg1iN6852rcL3mQQaIfPZODnIJnKyIy1dE6mk".to_string(), decrypt_key: "n-vQibdLXPDMtW7k5ftbR9HVz4Tb184lUc~MiUGHWAM".to_string(),settings: Some("AQACAAE".to_string())},
"check",
ReturnType::Direct).convert()

View file

@ -8,10 +8,10 @@ use types::DB_PATH;
fn create_db(conn: &Connection) -> Result<()> {
match conn.execute(
"CREATE TABLE users (
id INTEGER PRIMARY KEY,
id BLOB PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
sign_key BLOB NOT NULL,
insert_key BLOB NOT NULL,
sign_key BLOB UNIQUE NOT NULL,
insert_key BLOB UNIQUE NOT NULL,
messages_count INTEGER
)",
params![],
@ -22,7 +22,7 @@ fn create_db(conn: &Connection) -> Result<()> {
match conn.execute(
"CREATE TABLE messages (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
user_id BLOB NOT NULL,
date datetime NOT NULL,
message TEXT NOT NULL,
from_me BOOL

View file

@ -40,6 +40,7 @@ pub fn load_all_users(conn: &Connection) -> Result<Vec<User>> {
}
pub fn add_user(user: User, conn: &Connection) -> Result<()> {
log::info!("{:?}", user);
match conn.execute(
"INSERT INTO users (
id,