fix all warnings
This commit is contained in:
@@ -86,19 +86,10 @@ impl From<tungstenite::Error> for Error {
|
||||
}
|
||||
|
||||
trait AuthBuilder {
|
||||
fn with_auth(self, token: &Option<JwtToken>) -> Self;
|
||||
fn with_auth_string(self, token: &Option<String>) -> Self;
|
||||
}
|
||||
|
||||
impl AuthBuilder for hyper::http::request::Builder {
|
||||
fn with_auth(self, token: &Option<JwtToken>) -> Self {
|
||||
if let Some(token) = &token {
|
||||
self.header("Authorization", token.to_header_value())
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn with_auth_string(self, token: &Option<String>) -> 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<Option<Self::Item>> {
|
||||
self.body
|
||||
.poll_next_unpin(cx)
|
||||
.map_err(|e| Error::HTTPError(e))
|
||||
.map_err(Error::HTTPError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +301,7 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
||||
|
||||
async fn fetch_attachment_data(
|
||||
&mut self,
|
||||
guid: &String,
|
||||
guid: &str,
|
||||
preview: bool,
|
||||
) -> Result<ResponseStream, Self::Error> {
|
||||
let endpoint = format!("attachment?guid={}&preview={}", guid, preview);
|
||||
@@ -324,7 +315,7 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
||||
&mut self,
|
||||
mut data: tokio::io::BufReader<R>,
|
||||
filename: &str,
|
||||
size: u64,
|
||||
_size: u64,
|
||||
) -> Result<String, Self::Error>
|
||||
where
|
||||
R: tokio::io::AsyncRead + Unpin + Send + Sync + 'static,
|
||||
|
||||
@@ -47,7 +47,7 @@ pub trait APIInterface {
|
||||
// (GET) /attachment
|
||||
async fn fetch_attachment_data(
|
||||
&mut self,
|
||||
guid: &String,
|
||||
guid: &str,
|
||||
preview: bool,
|
||||
) -> Result<Self::ResponseStream, Self::Error>;
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Event, TestError>>;
|
||||
type UpdateStream = BoxStream<'static, Result<Vec<UpdateItem>, TestError>>;
|
||||
type EventStream = BoxStream<'static, Result<SocketEvent, TestError>>;
|
||||
type UpdateStream = BoxStream<'static, Result<SocketUpdate, TestError>>;
|
||||
|
||||
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<SinkMessage, Error = Self::Error>) {
|
||||
(
|
||||
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<Result<Vec<UpdateItem>, TestError>> = vec![];
|
||||
futures_util::stream::iter(results.into_iter()).boxed()
|
||||
}
|
||||
|
||||
fn get_sink(&mut self) -> impl futures_util::Sink<SinkMessage> {
|
||||
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<Self::ResponseStream, Self::Error> {
|
||||
Ok(futures_util::stream::iter(vec![Ok(Bytes::from_static(b"test"))]).boxed())
|
||||
|
||||
@@ -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<Mutex<Database>>,
|
||||
|
||||
@@ -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<T> = Result<T, Box<dyn Error + Send + Sync>>;
|
||||
|
||||
type DaemonClient = HTTPAPIClient<DatabaseAuthenticationStore>;
|
||||
|
||||
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<Conversation> {
|
||||
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<String>,
|
||||
_last_message_id: Option<MessageID>,
|
||||
) -> Vec<Message> {
|
||||
// Get outgoing messages for this conversation.
|
||||
let empty_vec: Vec<OutgoingMessage> = vec![];
|
||||
@@ -601,10 +591,6 @@ impl Daemon {
|
||||
self.database.with_settings(|s| settings.save(s)).await
|
||||
}
|
||||
|
||||
async fn get_client(&mut self) -> Result<HTTPAPIClient<DatabaseAuthenticationStore>> {
|
||||
Self::get_client_impl(&mut self.database).await
|
||||
}
|
||||
|
||||
async fn get_client_impl(
|
||||
database: &mut Arc<Mutex<Database>>,
|
||||
) -> Result<HTTPAPIClient<DatabaseAuthenticationStore>> {
|
||||
|
||||
@@ -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<T: Send + Clone + 'static> {
|
||||
connection: Arc<SyncConnection>,
|
||||
implementation: T,
|
||||
}
|
||||
|
||||
impl<T: Send + Clone + 'static> Endpoint<T> {
|
||||
pub fn new(connection: Arc<SyncConnection>, implementation: T) -> Self {
|
||||
Self {
|
||||
connection,
|
||||
implementation,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register_object<F, R>(&self, path: &str, register_fn: F)
|
||||
where
|
||||
F: Fn(&mut Crossroads) -> R,
|
||||
R: IntoIterator<Item = dbus_crossroads::IfaceToken<T>>,
|
||||
{
|
||||
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<S>(&self, path: &str, signal: S) -> Result<u32, ()>
|
||||
where
|
||||
S: dbus::message::SignalArgs + dbus::arg::AppendAll,
|
||||
{
|
||||
let message = signal.to_emit_message(&Path::new(path).unwrap());
|
||||
self.connection.send(message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user