fix issue with sending messages to wrong uri

This commit is contained in:
Horhik 2021-04-24 16:33:25 +03:00
parent 8bd332c892
commit 60f5ed6c6e
4 changed files with 15 additions and 13 deletions

View file

@ -92,6 +92,10 @@ pub fn send_message(
let identifier = &user_data.id.0.to_string()[..];
let message_id: u32 = user_data.my_messages_count;
let id = Id(uuid::Uuid::parse_str(identifier).expect("failed to parse user ID"));
let config: String = String::from_utf8_lossy(&std::fs::read(".hole.toml")?).parse().unwrap();
let parsed: crate::chat::Config = toml::from_str(&config[..]).unwrap();
let my_id = parsed.id.0.to_string();
let db_message = db::types::Message {
id: message_id,
date: chrono::offset::Local::now(),
@ -102,7 +106,7 @@ pub fn send_message(
let _ = db::messages::add_my_message(db_message, conn).unwrap();
log::debug!("Sending new message to freent...");
let fcp_req: String =
ClientPut::new_default_direct(fcpv2::types::USK{ ssk: key, path: format!("{}/{}", &identifier, message_id)}, &format!("new-messge-{}/{}", &identifier, &message_id )[..], &message[..]).convert();
ClientPut::new_default_direct(fcpv2::types::USK{ ssk: key, path: format!("{}/{}", &my_id, message_id)}, &format!("new-messge-{}/{}", &identifier, &message_id )[..], &message[..]).convert();
server_sender
.send(PackedMessage::ToFreenet(fcp_req))
.unwrap();

View file

@ -122,24 +122,24 @@ async fn connection_for_receiving(
&data.identifier,
&data.data
);
server_sender.send(PackedMessage::ToClient(data.data.clone()));
//TOOD parse identifier
let (uuid, id) =
server_sender.send(PackedMessage::ToClient(data.data.clone())).unwrap();
let (_, id) =
crate::api::identifier::parse_message_identifier(&data.identifier);
log::debug!("parsed identifier: {:?} {:?}", uuid, id);
let jsoned: crate::api::types::Message =
serde_json::from_str(&data.data[..]).unwrap();
let uid = Id(jsoned.id);
crate::db::messages::add_message(
crate::db::types::Message {
id: id,
date: jsoned.date,
user_id: Id(jsoned.id),
user_id: uid.clone(),
message: jsoned.message,
from_me: jsoned.from_me,
},
&db,
)
.unwrap()
.unwrap();
crate::db::users::increase_my_messages_count(uid.clone(), &db).unwrap();
/*async_std::task::block_on(
sender
// TODO freenet_response_handler

View file

@ -18,9 +18,7 @@ pub async fn request_repeater(ss: SP, conn: Pool<SqliteConnectionManager>) -> io
log::debug!("Request Repeater Started!");
let config: String = String::from_utf8_lossy(&std::fs::read(".hole.toml")?).parse().unwrap();
let parsed: crate::chat::Config = toml::from_str(&config[..]).unwrap();
log::debug!("Config gotted: {:?}", &config);
// let identifier_fil = File::open( ) ;
loop {
let users: Vec<crate::db::types::User> = crate::db::users::load_all_users(&db).unwrap();
@ -29,7 +27,7 @@ pub async fn request_repeater(ss: SP, conn: Pool<SqliteConnectionManager>) -> io
log::debug!("enough sleep");
for user in users {
let id = user.id.0.to_string();
let index = user.messages_count + 1;
let index = user.messages_count;
let key = USK {
ssk: parsed.private_key.clone(),
@ -45,7 +43,9 @@ pub async fn request_repeater(ss: SP, conn: Pool<SqliteConnectionManager>) -> io
ReturnType::Direct,
)
.convert(),
)) {
))
{
Ok(_) => {},
Err(e) => continue ,
}

View file

@ -40,8 +40,6 @@ use std::{
+--------------+ | | | | | | | |
| +----------------------------+ +---------------------------------+ | +-------------------+
| |
| |
+-----------------------------------------------------------------------------------+
*/