fix issue with sending messages to wrong uri
This commit is contained in:
parent
8bd332c892
commit
60f5ed6c6e
|
@ -92,6 +92,10 @@ pub fn send_message(
|
||||||
let identifier = &user_data.id.0.to_string()[..];
|
let identifier = &user_data.id.0.to_string()[..];
|
||||||
let message_id: u32 = user_data.my_messages_count;
|
let message_id: u32 = user_data.my_messages_count;
|
||||||
let id = Id(uuid::Uuid::parse_str(identifier).expect("failed to parse user ID"));
|
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 {
|
let db_message = db::types::Message {
|
||||||
id: message_id,
|
id: message_id,
|
||||||
date: chrono::offset::Local::now(),
|
date: chrono::offset::Local::now(),
|
||||||
|
@ -102,7 +106,7 @@ pub fn send_message(
|
||||||
let _ = db::messages::add_my_message(db_message, conn).unwrap();
|
let _ = db::messages::add_my_message(db_message, conn).unwrap();
|
||||||
log::debug!("Sending new message to freent...");
|
log::debug!("Sending new message to freent...");
|
||||||
let fcp_req: String =
|
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
|
server_sender
|
||||||
.send(PackedMessage::ToFreenet(fcp_req))
|
.send(PackedMessage::ToFreenet(fcp_req))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -122,24 +122,24 @@ async fn connection_for_receiving(
|
||||||
&data.identifier,
|
&data.identifier,
|
||||||
&data.data
|
&data.data
|
||||||
);
|
);
|
||||||
server_sender.send(PackedMessage::ToClient(data.data.clone()));
|
server_sender.send(PackedMessage::ToClient(data.data.clone())).unwrap();
|
||||||
//TOOD parse identifier
|
let (_, id) =
|
||||||
let (uuid, id) =
|
|
||||||
crate::api::identifier::parse_message_identifier(&data.identifier);
|
crate::api::identifier::parse_message_identifier(&data.identifier);
|
||||||
log::debug!("parsed identifier: {:?} {:?}", uuid, id);
|
|
||||||
let jsoned: crate::api::types::Message =
|
let jsoned: crate::api::types::Message =
|
||||||
serde_json::from_str(&data.data[..]).unwrap();
|
serde_json::from_str(&data.data[..]).unwrap();
|
||||||
|
let uid = Id(jsoned.id);
|
||||||
crate::db::messages::add_message(
|
crate::db::messages::add_message(
|
||||||
crate::db::types::Message {
|
crate::db::types::Message {
|
||||||
id: id,
|
id: id,
|
||||||
date: jsoned.date,
|
date: jsoned.date,
|
||||||
user_id: Id(jsoned.id),
|
user_id: uid.clone(),
|
||||||
message: jsoned.message,
|
message: jsoned.message,
|
||||||
from_me: jsoned.from_me,
|
from_me: jsoned.from_me,
|
||||||
},
|
},
|
||||||
&db,
|
&db,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap();
|
||||||
|
crate::db::users::increase_my_messages_count(uid.clone(), &db).unwrap();
|
||||||
/*async_std::task::block_on(
|
/*async_std::task::block_on(
|
||||||
sender
|
sender
|
||||||
// TODO freenet_response_handler
|
// TODO freenet_response_handler
|
||||||
|
|
|
@ -18,9 +18,7 @@ pub async fn request_repeater(ss: SP, conn: Pool<SqliteConnectionManager>) -> io
|
||||||
log::debug!("Request Repeater Started!");
|
log::debug!("Request Repeater Started!");
|
||||||
let config: String = String::from_utf8_lossy(&std::fs::read(".hole.toml")?).parse().unwrap();
|
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 parsed: crate::chat::Config = toml::from_str(&config[..]).unwrap();
|
||||||
|
|
||||||
log::debug!("Config gotted: {:?}", &config);
|
log::debug!("Config gotted: {:?}", &config);
|
||||||
// let identifier_fil = File::open( ) ;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let users: Vec<crate::db::types::User> = crate::db::users::load_all_users(&db).unwrap();
|
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");
|
log::debug!("enough sleep");
|
||||||
for user in users {
|
for user in users {
|
||||||
let id = user.id.0.to_string();
|
let id = user.id.0.to_string();
|
||||||
let index = user.messages_count + 1;
|
let index = user.messages_count;
|
||||||
|
|
||||||
let key = USK {
|
let key = USK {
|
||||||
ssk: parsed.private_key.clone(),
|
ssk: parsed.private_key.clone(),
|
||||||
|
@ -45,7 +43,9 @@ pub async fn request_repeater(ss: SP, conn: Pool<SqliteConnectionManager>) -> io
|
||||||
ReturnType::Direct,
|
ReturnType::Direct,
|
||||||
)
|
)
|
||||||
.convert(),
|
.convert(),
|
||||||
)) {
|
|
||||||
|
))
|
||||||
|
{
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => continue ,
|
Err(e) => continue ,
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,6 @@ use std::{
|
||||||
+--------------+ | | | | | | | |
|
+--------------+ | | | | | | | |
|
||||||
| +----------------------------+ +---------------------------------+ | +-------------------+
|
| +----------------------------+ +---------------------------------+ | +-------------------+
|
||||||
| |
|
| |
|
||||||
| |
|
|
||||||
+-----------------------------------------------------------------------------------+
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue