Private
Public Access
1
0

cargo clippy/fix

This commit is contained in:
2025-04-28 16:06:51 -07:00
parent c189e5f9e3
commit e7d837d68c
13 changed files with 43 additions and 61 deletions

View File

@@ -94,10 +94,7 @@ impl TokenStore for Database {
async fn get_token(&mut self) -> Option<JwtToken> {
self.with_settings(|settings| {
let token: Result<Option<JwtToken>> = settings.get(TOKEN_KEY);
match token {
Ok(data) => data,
Err(_) => None,
}
token.unwrap_or_default()
}).await
}

View File

@@ -47,6 +47,12 @@ pub struct MessageBuilder {
date: Option<NaiveDateTime>,
}
impl Default for MessageBuilder {
fn default() -> Self {
Self::new()
}
}
impl MessageBuilder {
pub fn new() -> Self {
Self {

View File

@@ -1,12 +1,10 @@
use crate::{
database::{Database, DatabaseAccess},
repository::Repository,
database::{Database, DatabaseAccess},
models::{
conversation::{Conversation, ConversationBuilder},
participant::Participant,
message::Message,
},
settings::Settings,
},
};
// Helper function to compare participants ignoring database IDs

View File

@@ -3,7 +3,7 @@ extern crate serde;
use std::{path::PathBuf, str};
use crate::api::{TokenStore, InMemoryTokenStore};
use crate::api::TokenStore;
use hyper::{Body, Client, Method, Request, Uri};
use async_trait::async_trait;
@@ -247,7 +247,8 @@ impl<K: TokenStore + Send + Sync> HTTPAPIClient<K> {
#[cfg(test)]
mod test {
use super::*;
use crate::api::InMemoryTokenStore;
#[cfg(test)]
fn local_mock_client() -> HTTPAPIClient<InMemoryTokenStore> {
let base_url = "http://localhost:5738".parse().unwrap();

View File

@@ -42,6 +42,12 @@ pub struct InMemoryTokenStore {
token: Option<JwtToken>,
}
impl Default for InMemoryTokenStore {
fn default() -> Self {
Self::new()
}
}
impl InMemoryTokenStore {
pub fn new() -> Self {
Self { token: None }

View File

@@ -182,7 +182,7 @@ impl Daemon {
// Fetch conversations from server
let fetched_conversations = client.get_conversations().await?;
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();
// Process each conversation
@@ -205,7 +205,7 @@ impl Daemon {
let messages = client.get_messages(&conversation_id, None, None, last_message_id).await?;
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();
// Insert each message
@@ -221,8 +221,7 @@ impl Daemon {
}
async fn get_settings(&mut self) -> Result<Settings> {
let settings = self.database.with_settings(|s|
Settings::from_db(s)
let settings = self.database.with_settings(Settings::from_db
).await?;
Ok(settings)
@@ -237,8 +236,7 @@ impl Daemon {
}
async fn get_client_impl(database: &mut Arc<Mutex<Database>>) -> Result<HTTPAPIClient<DatabaseTokenStore>> {
let settings = database.with_settings(|s|
Settings::from_db(s)
let settings = database.with_settings(Settings::from_db
).await?;
let server_url = settings.server_url

View File

@@ -8,6 +8,7 @@ mod keys {
}
#[derive(Debug)]
#[derive(Default)]
pub struct Settings {
pub server_url: 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,
}
}
}

View File

@@ -1,5 +1,5 @@
use log::info;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use dbus_crossroads::Crossroads;
use dbus_tokio::connection;

View File

@@ -9,7 +9,6 @@ use crate::daemon::{
DaemonResult,
events::{Event, Reply},
settings::Settings,
signals::Signal,
};
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> {
self.send_event_sync(Event::GetAllConversations)
.and_then(|conversations| {
.map(|conversations| {
// Convert conversations to DBus property maps
let result = conversations.into_iter().map(|conv| {
conversations.into_iter().map(|conv| {
let mut map = arg::PropMap::new();
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())));
@@ -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("date".into(), arg::Variant(Box::new(conv.date.and_utc().timestamp())));
map
}).collect();
Ok(result)
}).collect()
})
}
@@ -83,17 +82,17 @@ impl DbusRepository for ServerImpl {
};
self.send_event_sync(|r| Event::GetMessages(conversation_id, last_message_id_opt, r))
.and_then(|messages| {
let result = messages.into_iter().map(|msg| {
.map(|messages| {
messages.into_iter().map(|msg| {
let mut map = arg::PropMap::new();
map.insert("id".into(), arg::Variant(Box::new(msg.id)));
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("sender".into(), arg::Variant(Box::new(msg.sender.display_name())));
map
}).collect();
Ok(result)
}).collect()
})
}
}
@@ -121,9 +120,7 @@ impl DbusSettings for ServerImpl {
fn server_url(&self) -> Result<String, dbus::MethodErr> {
self.send_event_sync(Event::GetAllSettings)
.and_then(|settings| {
Ok(settings.server_url.unwrap_or_default())
})
.map(|settings| settings.server_url.unwrap_or_default())
}
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> {
self.send_event_sync(Event::GetAllSettings)
.and_then(|settings| {
Ok(settings.username.unwrap_or_default())
})
.map(|settings| settings.username.unwrap_or_default())
}
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> {
self.send_event_sync(Event::GetAllSettings)
.and_then(|settings| {
Ok(settings.credential_item.unwrap_or_default())
})
.and_then(|item| {
Ok(dbus::Path::new(item).unwrap_or_default())
})
.map(|settings| settings.credential_item.unwrap_or_default()).map(|item| dbus::Path::new(item).unwrap_or_default())
}
fn set_credential_item(&self, value: dbus::Path<'static>) -> Result<(), dbus::MethodErr> {

View File

@@ -3,7 +3,6 @@ use kordophone::api::http_client::HTTPAPIClient;
use kordophone::api::http_client::Credentials;
use kordophone::api::InMemoryTokenStore;
use dotenv;
use anyhow::Result;
use clap::Subcommand;
use crate::printers::{ConversationPrinter, MessagePrinter};
@@ -58,7 +57,7 @@ struct ClientCli {
impl ClientCli {
pub fn new() -> Self {
let api = make_api_client_from_env();
Self { api: api }
Self { api }
}
pub async fn print_version(&mut self) -> Result<()> {

View File

@@ -140,8 +140,6 @@ impl DaemonCli {
loop {
self.conn.process(std::time::Duration::from_millis(1000))?;
}
Ok(())
}
pub async fn config(&mut self, cmd: ConfigCommands) -> Result<()> {

View File

@@ -3,10 +3,7 @@ use clap::Subcommand;
use kordophone::APIInterface;
use std::{env, path::PathBuf};
use kordophone_db::{
database::{Database, DatabaseAccess},
models::{Conversation, Message},
};
use kordophone_db::database::{Database, DatabaseAccess};
use crate::{client, printers::{ConversationPrinter, MessagePrinter}};
#[derive(Subcommand)]
@@ -138,7 +135,7 @@ impl DbClient {
let mut client = client::make_api_client_from_env();
let fetched_conversations = client.get_conversations().await?;
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();
// Process each conversation
@@ -153,7 +150,7 @@ impl DbClient {
// Fetch and sync messages for this conversation
let messages = client.get_messages(&conversation_id, None, None, None).await?;
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();
// Insert each message

View File

@@ -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 {
self.doc.render_fmt(180, f)
}
@@ -158,7 +158,7 @@ pub struct MessagePrinter<'a> {
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 {
self.doc.render_fmt(180, f)
}