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