make addUser request work
This commit is contained in:
parent
f876588add
commit
7c447bd6f8
|
@ -52,7 +52,7 @@ pub fn send_message(user_id: Id, message: String, conn: &Connection, server_send
|
||||||
let db_message = db::types::Message {
|
let db_message = db::types::Message {
|
||||||
id: message_id,
|
id: message_id,
|
||||||
date: chrono::offset::Local::now(),
|
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(),
|
message: message.clone(),
|
||||||
from_me: false,
|
from_me: false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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();
|
let parsed: Request = serde_json::from_str(json).unwrap();
|
||||||
match parsed{
|
match parsed{
|
||||||
Request::StartApp => {
|
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 => {
|
Request::StopApp => {
|
||||||
handlers::stop_app(&conn, server_sender.clone())?
|
match handlers::stop_app(&conn, server_sender.clone()) { Ok(_) => {}, Err(_) => {} }
|
||||||
},
|
},
|
||||||
Request::LoadUsers => {
|
Request::LoadUsers => {
|
||||||
handlers::load_users(&conn, server_sender.clone())?
|
match handlers::load_users(&conn, server_sender.clone()){ Ok(_) => {}, Err(_) => {} }
|
||||||
},
|
},
|
||||||
Request::SendMessage {
|
Request::SendMessage {
|
||||||
user_id, message
|
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{
|
Request::LoadMessages{
|
||||||
user_id, count, start_index
|
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{
|
Request::AddUser{
|
||||||
name, sign_key, insert_key
|
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(_) => {} }
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,13 +77,6 @@ async fn connection_for_receiving(
|
||||||
log::info!("Connection for receiving launched");
|
log::info!("Connection for receiving launched");
|
||||||
while let Ok(res) = client_receiver.recv() {
|
while let Ok(res) = client_receiver.recv() {
|
||||||
//TODO call client get after receiving NodeHello
|
//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 {
|
match res {
|
||||||
PackedMessage::FromCore(json) => {
|
PackedMessage::FromCore(json) => {
|
||||||
sender
|
sender
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
||||||
//TODO create a field with tracked users
|
//TODO create a field with tracked users
|
||||||
let time = std::time::Duration::from_millis(1000);
|
let time = std::time::Duration::from_millis(1000);
|
||||||
std::thread::sleep(time);
|
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())},
|
ClientGet::new_default(SSK{sign_key: "9Zq-H7vg1iN6852rcL3mQQaIfPZODnIJnKyIy1dE6mk".to_string(), decrypt_key: "n-vQibdLXPDMtW7k5ftbR9HVz4Tb184lUc~MiUGHWAM".to_string(),settings: Some("AQACAAE".to_string())},
|
||||||
"check",
|
"check",
|
||||||
ReturnType::Direct).convert()
|
ReturnType::Direct).convert()
|
||||||
|
|
|
@ -8,10 +8,10 @@ use types::DB_PATH;
|
||||||
fn create_db(conn: &Connection) -> Result<()> {
|
fn create_db(conn: &Connection) -> Result<()> {
|
||||||
match conn.execute(
|
match conn.execute(
|
||||||
"CREATE TABLE users (
|
"CREATE TABLE users (
|
||||||
id INTEGER PRIMARY KEY,
|
id BLOB PRIMARY KEY,
|
||||||
name TEXT UNIQUE NOT NULL,
|
name TEXT UNIQUE NOT NULL,
|
||||||
sign_key BLOB NOT NULL,
|
sign_key BLOB UNIQUE NOT NULL,
|
||||||
insert_key BLOB NOT NULL,
|
insert_key BLOB UNIQUE NOT NULL,
|
||||||
messages_count INTEGER
|
messages_count INTEGER
|
||||||
)",
|
)",
|
||||||
params![],
|
params![],
|
||||||
|
@ -22,7 +22,7 @@ fn create_db(conn: &Connection) -> Result<()> {
|
||||||
match conn.execute(
|
match conn.execute(
|
||||||
"CREATE TABLE messages (
|
"CREATE TABLE messages (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
user_id INTEGER NOT NULL,
|
user_id BLOB NOT NULL,
|
||||||
date datetime NOT NULL,
|
date datetime NOT NULL,
|
||||||
message TEXT NOT NULL,
|
message TEXT NOT NULL,
|
||||||
from_me BOOL
|
from_me BOOL
|
||||||
|
|
|
@ -40,6 +40,7 @@ pub fn load_all_users(conn: &Connection) -> Result<Vec<User>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_user(user: User, conn: &Connection) -> Result<()> {
|
pub fn add_user(user: User, conn: &Connection) -> Result<()> {
|
||||||
|
log::info!("{:?}", user);
|
||||||
match conn.execute(
|
match conn.execute(
|
||||||
"INSERT INTO users (
|
"INSERT INTO users (
|
||||||
id,
|
id,
|
||||||
|
|
Loading…
Reference in a new issue