cargo clippy/fix
This commit is contained in:
@@ -94,10 +94,7 @@ impl TokenStore for Database {
|
|||||||
async fn get_token(&mut self) -> Option<JwtToken> {
|
async fn get_token(&mut self) -> Option<JwtToken> {
|
||||||
self.with_settings(|settings| {
|
self.with_settings(|settings| {
|
||||||
let token: Result<Option<JwtToken>> = settings.get(TOKEN_KEY);
|
let token: Result<Option<JwtToken>> = settings.get(TOKEN_KEY);
|
||||||
match token {
|
token.unwrap_or_default()
|
||||||
Ok(data) => data,
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
}).await
|
}).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ pub struct MessageBuilder {
|
|||||||
date: Option<NaiveDateTime>,
|
date: Option<NaiveDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for MessageBuilder {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MessageBuilder {
|
impl MessageBuilder {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
database::{Database, DatabaseAccess},
|
database::{Database, DatabaseAccess},
|
||||||
repository::Repository,
|
|
||||||
models::{
|
models::{
|
||||||
conversation::{Conversation, ConversationBuilder},
|
conversation::{Conversation, ConversationBuilder},
|
||||||
participant::Participant,
|
participant::Participant,
|
||||||
message::Message,
|
message::Message,
|
||||||
},
|
},
|
||||||
settings::Settings,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to compare participants ignoring database IDs
|
// Helper function to compare participants ignoring database IDs
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ extern crate serde;
|
|||||||
|
|
||||||
use std::{path::PathBuf, str};
|
use std::{path::PathBuf, str};
|
||||||
|
|
||||||
use crate::api::{TokenStore, InMemoryTokenStore};
|
use crate::api::TokenStore;
|
||||||
use hyper::{Body, Client, Method, Request, Uri};
|
use hyper::{Body, Client, Method, Request, Uri};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -247,6 +247,7 @@ impl<K: TokenStore + Send + Sync> HTTPAPIClient<K> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::api::InMemoryTokenStore;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn local_mock_client() -> HTTPAPIClient<InMemoryTokenStore> {
|
fn local_mock_client() -> HTTPAPIClient<InMemoryTokenStore> {
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ pub struct InMemoryTokenStore {
|
|||||||
token: Option<JwtToken>,
|
token: Option<JwtToken>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for InMemoryTokenStore {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl InMemoryTokenStore {
|
impl InMemoryTokenStore {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { token: None }
|
Self { token: None }
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ impl Daemon {
|
|||||||
// Fetch conversations from server
|
// Fetch conversations from server
|
||||||
let fetched_conversations = client.get_conversations().await?;
|
let fetched_conversations = client.get_conversations().await?;
|
||||||
let db_conversations: Vec<kordophone_db::models::Conversation> = fetched_conversations.into_iter()
|
let db_conversations: Vec<kordophone_db::models::Conversation> = fetched_conversations.into_iter()
|
||||||
.map(|c| kordophone_db::models::Conversation::from(c))
|
.map(kordophone_db::models::Conversation::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Process each conversation
|
// Process each conversation
|
||||||
@@ -205,7 +205,7 @@ impl Daemon {
|
|||||||
|
|
||||||
let messages = client.get_messages(&conversation_id, None, None, last_message_id).await?;
|
let messages = client.get_messages(&conversation_id, None, None, last_message_id).await?;
|
||||||
let db_messages: Vec<kordophone_db::models::Message> = messages.into_iter()
|
let db_messages: Vec<kordophone_db::models::Message> = messages.into_iter()
|
||||||
.map(|m| kordophone_db::models::Message::from(m))
|
.map(kordophone_db::models::Message::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Insert each message
|
// Insert each message
|
||||||
@@ -221,8 +221,7 @@ impl Daemon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_settings(&mut self) -> Result<Settings> {
|
async fn get_settings(&mut self) -> Result<Settings> {
|
||||||
let settings = self.database.with_settings(|s|
|
let settings = self.database.with_settings(Settings::from_db
|
||||||
Settings::from_db(s)
|
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
Ok(settings)
|
Ok(settings)
|
||||||
@@ -237,8 +236,7 @@ impl Daemon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_client_impl(database: &mut Arc<Mutex<Database>>) -> Result<HTTPAPIClient<DatabaseTokenStore>> {
|
async fn get_client_impl(database: &mut Arc<Mutex<Database>>) -> Result<HTTPAPIClient<DatabaseTokenStore>> {
|
||||||
let settings = database.with_settings(|s|
|
let settings = database.with_settings(Settings::from_db
|
||||||
Settings::from_db(s)
|
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
let server_url = settings.server_url
|
let server_url = settings.server_url
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ mod keys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub server_url: Option<String>,
|
pub server_url: Option<String>,
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
@@ -41,12 +42,3 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
server_url: None,
|
|
||||||
username: None,
|
|
||||||
credential_item: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use log::info;
|
use log::info;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use dbus_crossroads::Crossroads;
|
use dbus_crossroads::Crossroads;
|
||||||
use dbus_tokio::connection;
|
use dbus_tokio::connection;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::daemon::{
|
|||||||
DaemonResult,
|
DaemonResult,
|
||||||
events::{Event, Reply},
|
events::{Event, Reply},
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
signals::Signal,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::dbus::interface::NetBuzzertKordophoneRepository as DbusRepository;
|
use crate::dbus::interface::NetBuzzertKordophoneRepository as DbusRepository;
|
||||||
@@ -54,9 +53,11 @@ impl DbusRepository for ServerImpl {
|
|||||||
|
|
||||||
fn get_conversations(&mut self) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
|
fn get_conversations(&mut self) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
|
||||||
self.send_event_sync(Event::GetAllConversations)
|
self.send_event_sync(Event::GetAllConversations)
|
||||||
.and_then(|conversations| {
|
.map(|conversations| {
|
||||||
// Convert conversations to DBus property maps
|
// Convert conversations to DBus property maps
|
||||||
let result = conversations.into_iter().map(|conv| {
|
|
||||||
|
|
||||||
|
conversations.into_iter().map(|conv| {
|
||||||
let mut map = arg::PropMap::new();
|
let mut map = arg::PropMap::new();
|
||||||
map.insert("guid".into(), arg::Variant(Box::new(conv.guid)));
|
map.insert("guid".into(), arg::Variant(Box::new(conv.guid)));
|
||||||
map.insert("display_name".into(), arg::Variant(Box::new(conv.display_name.unwrap_or_default())));
|
map.insert("display_name".into(), arg::Variant(Box::new(conv.display_name.unwrap_or_default())));
|
||||||
@@ -65,9 +66,7 @@ impl DbusRepository for ServerImpl {
|
|||||||
map.insert("participants".into(), arg::Variant(Box::new(conv.participants.into_iter().map(|p| p.display_name()).collect::<Vec<String>>())));
|
map.insert("participants".into(), arg::Variant(Box::new(conv.participants.into_iter().map(|p| p.display_name()).collect::<Vec<String>>())));
|
||||||
map.insert("date".into(), arg::Variant(Box::new(conv.date.and_utc().timestamp())));
|
map.insert("date".into(), arg::Variant(Box::new(conv.date.and_utc().timestamp())));
|
||||||
map
|
map
|
||||||
}).collect();
|
}).collect()
|
||||||
|
|
||||||
Ok(result)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,17 +82,17 @@ impl DbusRepository for ServerImpl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.send_event_sync(|r| Event::GetMessages(conversation_id, last_message_id_opt, r))
|
self.send_event_sync(|r| Event::GetMessages(conversation_id, last_message_id_opt, r))
|
||||||
.and_then(|messages| {
|
.map(|messages| {
|
||||||
let result = messages.into_iter().map(|msg| {
|
|
||||||
|
|
||||||
|
messages.into_iter().map(|msg| {
|
||||||
let mut map = arg::PropMap::new();
|
let mut map = arg::PropMap::new();
|
||||||
map.insert("id".into(), arg::Variant(Box::new(msg.id)));
|
map.insert("id".into(), arg::Variant(Box::new(msg.id)));
|
||||||
map.insert("text".into(), arg::Variant(Box::new(msg.text)));
|
map.insert("text".into(), arg::Variant(Box::new(msg.text)));
|
||||||
map.insert("date".into(), arg::Variant(Box::new(msg.date.and_utc().timestamp())));
|
map.insert("date".into(), arg::Variant(Box::new(msg.date.and_utc().timestamp())));
|
||||||
map.insert("sender".into(), arg::Variant(Box::new(msg.sender.display_name())));
|
map.insert("sender".into(), arg::Variant(Box::new(msg.sender.display_name())));
|
||||||
map
|
map
|
||||||
}).collect();
|
}).collect()
|
||||||
|
|
||||||
Ok(result)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,9 +120,7 @@ impl DbusSettings for ServerImpl {
|
|||||||
|
|
||||||
fn server_url(&self) -> Result<String, dbus::MethodErr> {
|
fn server_url(&self) -> Result<String, dbus::MethodErr> {
|
||||||
self.send_event_sync(Event::GetAllSettings)
|
self.send_event_sync(Event::GetAllSettings)
|
||||||
.and_then(|settings| {
|
.map(|settings| settings.server_url.unwrap_or_default())
|
||||||
Ok(settings.server_url.unwrap_or_default())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_server_url(&self, value: String) -> Result<(), dbus::MethodErr> {
|
fn set_server_url(&self, value: String) -> Result<(), dbus::MethodErr> {
|
||||||
@@ -138,9 +135,7 @@ impl DbusSettings for ServerImpl {
|
|||||||
|
|
||||||
fn username(&self) -> Result<String, dbus::MethodErr> {
|
fn username(&self) -> Result<String, dbus::MethodErr> {
|
||||||
self.send_event_sync(Event::GetAllSettings)
|
self.send_event_sync(Event::GetAllSettings)
|
||||||
.and_then(|settings| {
|
.map(|settings| settings.username.unwrap_or_default())
|
||||||
Ok(settings.username.unwrap_or_default())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_username(&self, value: String) -> Result<(), dbus::MethodErr> {
|
fn set_username(&self, value: String) -> Result<(), dbus::MethodErr> {
|
||||||
@@ -155,12 +150,7 @@ impl DbusSettings for ServerImpl {
|
|||||||
|
|
||||||
fn credential_item(&self) -> Result<dbus::Path<'static>, dbus::MethodErr> {
|
fn credential_item(&self) -> Result<dbus::Path<'static>, dbus::MethodErr> {
|
||||||
self.send_event_sync(Event::GetAllSettings)
|
self.send_event_sync(Event::GetAllSettings)
|
||||||
.and_then(|settings| {
|
.map(|settings| settings.credential_item.unwrap_or_default()).map(|item| dbus::Path::new(item).unwrap_or_default())
|
||||||
Ok(settings.credential_item.unwrap_or_default())
|
|
||||||
})
|
|
||||||
.and_then(|item| {
|
|
||||||
Ok(dbus::Path::new(item).unwrap_or_default())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_credential_item(&self, value: dbus::Path<'static>) -> Result<(), dbus::MethodErr> {
|
fn set_credential_item(&self, value: dbus::Path<'static>) -> Result<(), dbus::MethodErr> {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use kordophone::api::http_client::HTTPAPIClient;
|
|||||||
use kordophone::api::http_client::Credentials;
|
use kordophone::api::http_client::Credentials;
|
||||||
use kordophone::api::InMemoryTokenStore;
|
use kordophone::api::InMemoryTokenStore;
|
||||||
|
|
||||||
use dotenv;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use crate::printers::{ConversationPrinter, MessagePrinter};
|
use crate::printers::{ConversationPrinter, MessagePrinter};
|
||||||
@@ -58,7 +57,7 @@ struct ClientCli {
|
|||||||
impl ClientCli {
|
impl ClientCli {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let api = make_api_client_from_env();
|
let api = make_api_client_from_env();
|
||||||
Self { api: api }
|
Self { api }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn print_version(&mut self) -> Result<()> {
|
pub async fn print_version(&mut self) -> Result<()> {
|
||||||
|
|||||||
@@ -140,8 +140,6 @@ impl DaemonCli {
|
|||||||
loop {
|
loop {
|
||||||
self.conn.process(std::time::Duration::from_millis(1000))?;
|
self.conn.process(std::time::Duration::from_millis(1000))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn config(&mut self, cmd: ConfigCommands) -> Result<()> {
|
pub async fn config(&mut self, cmd: ConfigCommands) -> Result<()> {
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ use clap::Subcommand;
|
|||||||
use kordophone::APIInterface;
|
use kordophone::APIInterface;
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use kordophone_db::{
|
use kordophone_db::database::{Database, DatabaseAccess};
|
||||||
database::{Database, DatabaseAccess},
|
|
||||||
models::{Conversation, Message},
|
|
||||||
};
|
|
||||||
use crate::{client, printers::{ConversationPrinter, MessagePrinter}};
|
use crate::{client, printers::{ConversationPrinter, MessagePrinter}};
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
@@ -138,7 +135,7 @@ impl DbClient {
|
|||||||
let mut client = client::make_api_client_from_env();
|
let mut client = client::make_api_client_from_env();
|
||||||
let fetched_conversations = client.get_conversations().await?;
|
let fetched_conversations = client.get_conversations().await?;
|
||||||
let db_conversations: Vec<kordophone_db::models::Conversation> = fetched_conversations.into_iter()
|
let db_conversations: Vec<kordophone_db::models::Conversation> = fetched_conversations.into_iter()
|
||||||
.map(|c| kordophone_db::models::Conversation::from(c))
|
.map(kordophone_db::models::Conversation::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Process each conversation
|
// Process each conversation
|
||||||
@@ -153,7 +150,7 @@ impl DbClient {
|
|||||||
// Fetch and sync messages for this conversation
|
// Fetch and sync messages for this conversation
|
||||||
let messages = client.get_messages(&conversation_id, None, None, None).await?;
|
let messages = client.get_messages(&conversation_id, None, None, None).await?;
|
||||||
let db_messages: Vec<kordophone_db::models::Message> = messages.into_iter()
|
let db_messages: Vec<kordophone_db::models::Message> = messages.into_iter()
|
||||||
.map(|m| kordophone_db::models::Message::from(m))
|
.map(kordophone_db::models::Message::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Insert each message
|
// Insert each message
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ impl<'a> ConversationPrinter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for ConversationPrinter<'a> {
|
impl Display for ConversationPrinter<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
self.doc.render_fmt(180, f)
|
self.doc.render_fmt(180, f)
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ pub struct MessagePrinter<'a> {
|
|||||||
doc: RcDoc<'a, PrintableMessage>
|
doc: RcDoc<'a, PrintableMessage>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for MessagePrinter<'a> {
|
impl Display for MessagePrinter<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
self.doc.render_fmt(180, f)
|
self.doc.render_fmt(180, f)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user