some updates
This commit is contained in:
parent
35d2eafdb8
commit
8bd332c892
|
@ -1,10 +1,11 @@
|
|||
use super::response::User;
|
||||
use super::response::{AppStatus, ResponseType};
|
||||
use crate::api::request::Request;
|
||||
use crate::api::types::Message as FrontMessage;
|
||||
use crate::chat::init_config;
|
||||
use crate::chat::types::PackedMessage;
|
||||
use crate::chat::types::SP;
|
||||
use crate::db::{self, messages, types, users};
|
||||
use crate::db::{self, messages, types::Message as DbMessage, users};
|
||||
use async_std::io::Result;
|
||||
use fcpv2::client::fcp_types::{ClientHello, ClientPut};
|
||||
use fcpv2::types::{
|
||||
|
@ -85,13 +86,6 @@ pub fn send_message(
|
|||
conn: &Connection,
|
||||
server_sender: SP,
|
||||
) -> Result<()> {
|
||||
log::debug!("CUM CUM");
|
||||
log::debug!("CUM CUM");
|
||||
log::debug!("CUM CUM");
|
||||
log::debug!("CUM CUM");
|
||||
log::debug!("CUM CUM");
|
||||
log::debug!("CUM CUM");
|
||||
log::debug!("CUM CUM");
|
||||
if let Ok(user_data) = db::users::get_user_by_id(user_id, conn) {
|
||||
// Add message to DB
|
||||
let key = user_data.insert_key;
|
||||
|
@ -106,9 +100,9 @@ pub fn send_message(
|
|||
from_me: true,
|
||||
};
|
||||
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 =
|
||||
ClientPut::new_default_direct(fcpv2::types::USK{ ssk: key, path: format!("{}/{}", &identifier, message_id)}, &format!("{}/{}", &identifier, &message_id )[..], &message[..]).convert();
|
||||
ClientPut::new_default_direct(fcpv2::types::USK{ ssk: key, path: format!("{}/{}", &identifier, message_id)}, &format!("new-messge-{}/{}", &identifier, &message_id )[..], &message[..]).convert();
|
||||
server_sender
|
||||
.send(PackedMessage::ToFreenet(fcp_req))
|
||||
.unwrap();
|
||||
|
@ -136,8 +130,18 @@ pub fn load_messages(
|
|||
conn: &Connection,
|
||||
server_sender: SP,
|
||||
) -> Result<()> {
|
||||
let messages = db::messages::select_n_last_messages(user_id, start_index, count, conn).unwrap();
|
||||
let jsoned = json!(messages);
|
||||
let messages: Vec<DbMessage> = db::messages::select_n_last_messages(user_id.clone(), start_index, count, conn).unwrap();
|
||||
let jsoned = json!(
|
||||
ResponseType::MessageList{
|
||||
messages: messages.into_iter().map(|msg| -> FrontMessage {return FrontMessage{
|
||||
message: msg.message,
|
||||
date: msg.date,
|
||||
id: user_id.0,
|
||||
from_me: msg.from_me,
|
||||
}}).collect(),
|
||||
id: user_id.0
|
||||
}
|
||||
);
|
||||
let _ = server_sender.send(PackedMessage::ToClient(jsoned.to_string())).unwrap();
|
||||
Ok(())
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ use crate::db::types::User as SqliteUser;
|
|||
use serde_derive::{Deserialize, Serialize};
|
||||
use tungstenite::http::Response;
|
||||
pub type InsertKey = String;
|
||||
|
||||
use crate::db::types::Id;
|
||||
use crate::api::types::Message;
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(tag = "type")]
|
||||
|
@ -23,6 +26,11 @@ pub enum ResponseType {
|
|||
},
|
||||
UserList {
|
||||
users: Vec<User>,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
MessageList{
|
||||
id: uuid::Uuid,
|
||||
messages: Vec<Message>
|
||||
}
|
||||
}
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
|
@ -6,6 +6,6 @@ use serde::{Serialize, Deserialize};
|
|||
pub struct Message {
|
||||
pub message: String,
|
||||
pub date: Time,
|
||||
pub id: Id,
|
||||
pub id: uuid::Uuid,
|
||||
pub from_me: bool,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::chat::types::PackedMessage;
|
||||
use crate::db;
|
||||
use crate::db::types::Id;
|
||||
use async_std::{
|
||||
io,
|
||||
net::{TcpListener, TcpStream},
|
||||
|
@ -132,7 +133,7 @@ async fn connection_for_receiving(
|
|||
crate::db::types::Message {
|
||||
id: id,
|
||||
date: jsoned.date,
|
||||
user_id: jsoned.id,
|
||||
user_id: Id(jsoned.id),
|
||||
message: jsoned.message,
|
||||
from_me: jsoned.from_me,
|
||||
},
|
||||
|
@ -148,11 +149,14 @@ async fn connection_for_receiving(
|
|||
*/
|
||||
}
|
||||
None => {}
|
||||
_ => {}
|
||||
_ => {
|
||||
log::debug!("Got message from Freenet:\n {:?}", &r )
|
||||
}
|
||||
}
|
||||
// .expect("Couldn't send messge");
|
||||
}
|
||||
_ => {}
|
||||
_ => {
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ pub async fn request_repeater(ss: SP, conn: Pool<SqliteConnectionManager>) -> io
|
|||
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();
|
||||
|
|
Loading…
Reference in a new issue