diff --git a/kordophone/src/api/http_client.rs b/kordophone/src/api/http_client.rs index a7be3f7..6bd29f8 100644 --- a/kordophone/src/api/http_client.rs +++ b/kordophone/src/api/http_client.rs @@ -86,19 +86,10 @@ impl From for Error { } trait AuthBuilder { - fn with_auth(self, token: &Option) -> Self; fn with_auth_string(self, token: &Option) -> Self; } impl AuthBuilder for hyper::http::request::Builder { - fn with_auth(self, token: &Option) -> Self { - if let Some(token) = &token { - self.header("Authorization", token.to_header_value()) - } else { - self - } - } - fn with_auth_string(self, token: &Option) -> Self { if let Some(token) = &token { self.header("Authorization", format!("Bearer: {}", token)) @@ -223,7 +214,7 @@ impl Stream for ResponseStream { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.body .poll_next_unpin(cx) - .map_err(|e| Error::HTTPError(e)) + .map_err(Error::HTTPError) } } @@ -310,7 +301,7 @@ impl APIInterface for HTTPAPIClient { async fn fetch_attachment_data( &mut self, - guid: &String, + guid: &str, preview: bool, ) -> Result { let endpoint = format!("attachment?guid={}&preview={}", guid, preview); @@ -324,7 +315,7 @@ impl APIInterface for HTTPAPIClient { &mut self, mut data: tokio::io::BufReader, filename: &str, - size: u64, + _size: u64, ) -> Result where R: tokio::io::AsyncRead + Unpin + Send + Sync + 'static, diff --git a/kordophone/src/api/mod.rs b/kordophone/src/api/mod.rs index 7220511..f092307 100644 --- a/kordophone/src/api/mod.rs +++ b/kordophone/src/api/mod.rs @@ -47,7 +47,7 @@ pub trait APIInterface { // (GET) /attachment async fn fetch_attachment_data( &mut self, - guid: &String, + guid: &str, preview: bool, ) -> Result; diff --git a/kordophone/src/model/outgoing_message.rs b/kordophone/src/model/outgoing_message.rs index 15e03a7..93da21f 100644 --- a/kordophone/src/model/outgoing_message.rs +++ b/kordophone/src/model/outgoing_message.rs @@ -62,7 +62,7 @@ impl OutgoingMessageBuilder { pub fn build(self) -> OutgoingMessage { OutgoingMessage { - guid: self.guid.unwrap_or_else(|| Uuid::new_v4()), + guid: self.guid.unwrap_or_else(Uuid::new_v4), text: self.text.unwrap(), conversation_id: self.conversation_id.unwrap(), file_transfer_guids: self.file_transfer_guids.unwrap_or_default(), diff --git a/kordophone/src/model/update.rs b/kordophone/src/model/update.rs index e92f857..b61ef5d 100644 --- a/kordophone/src/model/update.rs +++ b/kordophone/src/model/update.rs @@ -3,6 +3,7 @@ use super::message::Message; use serde::Deserialize; #[derive(Debug, Clone, Deserialize)] +#[derive(Default)] pub struct UpdateItem { #[serde(rename = "messageSequenceNumber")] pub seq: u64, @@ -17,13 +18,3 @@ pub struct UpdateItem { pub pong: bool, } -impl Default for UpdateItem { - fn default() -> Self { - Self { - seq: 0, - conversation: None, - message: None, - pong: false, - } - } -} diff --git a/kordophone/src/tests/test_client.rs b/kordophone/src/tests/test_client.rs index c514bbd..0ab53d3 100644 --- a/kordophone/src/tests/test_client.rs +++ b/kordophone/src/tests/test_client.rs @@ -6,7 +6,7 @@ use uuid::Uuid; pub use crate::APIInterface; use crate::{ - api::event_socket::{EventSocket, SinkMessage}, + api::event_socket::{EventSocket, SinkMessage, SocketEvent, SocketUpdate}, api::http_client::Credentials, model::{ Conversation, ConversationID, Event, JwtToken, Message, MessageID, OutgoingMessage, @@ -16,6 +16,7 @@ use crate::{ use bytes::Bytes; use futures_util::stream::BoxStream; +use futures_util::Sink; use futures_util::StreamExt; pub struct TestClient { @@ -52,21 +53,20 @@ impl TestEventSocket { #[async_trait] impl EventSocket for TestEventSocket { type Error = TestError; - type EventStream = BoxStream<'static, Result>; - type UpdateStream = BoxStream<'static, Result, TestError>>; + type EventStream = BoxStream<'static, Result>; + type UpdateStream = BoxStream<'static, Result>; - async fn events(self) -> Self::EventStream { - futures_util::stream::iter(self.events.into_iter().map(Ok)).boxed() + async fn events(self) -> (Self::EventStream, impl Sink) { + ( + futures_util::stream::iter(self.events.into_iter().map(Ok)).boxed(), + futures_util::sink::sink(), + ) } async fn raw_updates(self) -> Self::UpdateStream { let results: Vec, TestError>> = vec![]; futures_util::stream::iter(results.into_iter()).boxed() } - - fn get_sink(&mut self) -> impl futures_util::Sink { - todo!("") - } } #[async_trait] @@ -126,7 +126,7 @@ impl APIInterface for TestClient { async fn fetch_attachment_data( &mut self, - guid: &String, + guid: &str, preview: bool, ) -> Result { Ok(futures_util::stream::iter(vec![Ok(Bytes::from_static(b"test"))]).boxed()) diff --git a/kordophoned/src/daemon/attachment_store.rs b/kordophoned/src/daemon/attachment_store.rs index b8c1718..0ba3df3 100644 --- a/kordophoned/src/daemon/attachment_store.rs +++ b/kordophoned/src/daemon/attachment_store.rs @@ -56,12 +56,6 @@ enum AttachmentStoreError { APIClientError(String), } -#[derive(Debug, Clone)] -struct DownloadRequest { - guid: String, - preview: bool, -} - pub struct AttachmentStore { store_path: PathBuf, database: Arc>, diff --git a/kordophoned/src/daemon/mod.rs b/kordophoned/src/daemon/mod.rs index b79fbbb..4428f4a 100644 --- a/kordophoned/src/daemon/mod.rs +++ b/kordophoned/src/daemon/mod.rs @@ -29,7 +29,7 @@ use kordophone_db::{ use kordophone::api::http_client::HTTPAPIClient; use kordophone::api::APIInterface; use kordophone::model::outgoing_message::OutgoingMessage; -use kordophone::model::ConversationID; +use kordophone::model::{ConversationID, MessageID}; mod update_monitor; use update_monitor::{UpdateMonitor, UpdateMonitorCommand}; @@ -57,8 +57,6 @@ pub enum DaemonError { pub type DaemonResult = Result>; -type DaemonClient = HTTPAPIClient; - pub mod target { pub static SYNC: &str = "sync"; pub static EVENT: &str = "event"; @@ -392,14 +390,6 @@ impl Daemon { self.signal_receiver.take().unwrap() } - async fn get_conversations(&mut self) -> Vec { - self.database - .lock() - .await - .with_repository(|r| r.all_conversations(i32::MAX, 0).unwrap()) - .await - } - async fn get_conversations_limit_offset( &mut self, limit: i32, @@ -415,7 +405,7 @@ impl Daemon { async fn get_messages( &mut self, conversation_id: String, - last_message_id: Option, + _last_message_id: Option, ) -> Vec { // Get outgoing messages for this conversation. let empty_vec: Vec = vec![]; @@ -601,10 +591,6 @@ impl Daemon { self.database.with_settings(|s| settings.save(s)).await } - async fn get_client(&mut self) -> Result> { - Self::get_client_impl(&mut self.database).await - } - async fn get_client_impl( database: &mut Arc>, ) -> Result> { diff --git a/kordophoned/src/dbus/endpoint.rs b/kordophoned/src/dbus/endpoint.rs index aa327b5..f6b8ef3 100644 --- a/kordophoned/src/dbus/endpoint.rs +++ b/kordophoned/src/dbus/endpoint.rs @@ -73,57 +73,3 @@ impl DbusRegistry { self.connection.send(message) } } - -// Keep the old Endpoint struct for backward compatibility during transition -#[derive(Clone)] -pub struct Endpoint { - connection: Arc, - implementation: T, -} - -impl Endpoint { - pub fn new(connection: Arc, implementation: T) -> Self { - Self { - connection, - implementation, - } - } - - pub async fn register_object(&self, path: &str, register_fn: F) - where - F: Fn(&mut Crossroads) -> R, - R: IntoIterator>, - { - let dbus_path = String::from(path); - - // Enable async support for the crossroads instance. - // (Currently irrelevant since dbus generates sync code) - let mut cr = Crossroads::new(); - cr.set_async_support(Some(( - self.connection.clone(), - Box::new(|x| { - tokio::spawn(x); - }), - ))); - - // Register the daemon as a D-Bus object with multiple interfaces - let tokens: Vec<_> = register_fn(&mut cr).into_iter().collect(); - cr.insert(dbus_path, &tokens, self.implementation.clone()); - - // Start receiving messages. - self.connection.start_receive( - MatchRule::new_method_call(), - Box::new(move |msg, conn| cr.handle_message(msg, conn).is_ok()), - ); - - info!(target: "dbus", "Registered endpoint at {} with {} interfaces", path, tokens.len()); - } - - pub fn send_signal(&self, path: &str, signal: S) -> Result - where - S: dbus::message::SignalArgs + dbus::arg::AppendAll, - { - let message = signal.to_emit_message(&Path::new(path).unwrap()); - self.connection.send(message) - } -}