Private
Public Access
1
0

cargo fmt

This commit is contained in:
2025-06-06 16:39:31 -07:00
parent 8cd72d9417
commit 1d3b2f25ba
44 changed files with 758 additions and 505 deletions

View File

@@ -1,8 +1,8 @@
use crate::printers::{ConversationPrinter, MessagePrinter};
use anyhow::Result;
use clap::Subcommand;
use dbus::blocking::{Connection, Proxy};
use prettytable::table;
use crate::printers::{ConversationPrinter, MessagePrinter};
const DBUS_NAME: &str = "net.buzzert.kordophonecd";
const DBUS_PATH: &str = "/net/buzzert/kordophonecd/daemon";
@@ -21,9 +21,7 @@ pub enum Commands {
Conversations,
/// Runs a full sync operation for a conversation and its messages.
Sync {
conversation_id: Option<String>,
},
Sync { conversation_id: Option<String> },
/// Runs a sync operation for the conversation list.
SyncList,
@@ -31,7 +29,7 @@ pub enum Commands {
/// Prints the server Kordophone version.
Version,
/// Configuration options
/// Configuration options
Config {
#[command(subcommand)]
command: ConfigCommands,
@@ -62,14 +60,10 @@ pub enum ConfigCommands {
Print,
/// Sets the server URL.
SetServerUrl {
url: String,
},
SetServerUrl { url: String },
/// Sets the username.
SetUsername {
username: String,
},
SetUsername { username: String },
}
impl Commands {
@@ -82,9 +76,19 @@ impl Commands {
Commands::SyncList => client.sync_conversations_list().await,
Commands::Config { command } => client.config(command).await,
Commands::Signals => client.wait_for_signals().await,
Commands::Messages { conversation_id, last_message_id } => client.print_messages(conversation_id, last_message_id).await,
Commands::Messages {
conversation_id,
last_message_id,
} => {
client
.print_messages(conversation_id, last_message_id)
.await
}
Commands::DeleteAllConversations => client.delete_all_conversations().await,
Commands::SendMessage { conversation_id, text } => client.enqueue_outgoing_message(conversation_id, text).await,
Commands::SendMessage {
conversation_id,
text,
} => client.enqueue_outgoing_message(conversation_id, text).await,
}
}
}
@@ -96,12 +100,13 @@ struct DaemonCli {
impl DaemonCli {
pub fn new() -> Result<Self> {
Ok(Self {
conn: Connection::new_session()?
conn: Connection::new_session()?,
})
}
fn proxy(&self) -> Proxy<&Connection> {
self.conn.with_proxy(DBUS_NAME, DBUS_PATH, std::time::Duration::from_millis(5000))
self.conn
.with_proxy(DBUS_NAME, DBUS_PATH, std::time::Duration::from_millis(5000))
}
pub async fn print_version(&mut self) -> Result<()> {
@@ -117,7 +122,7 @@ impl DaemonCli {
for conversation in conversations {
println!("{}", ConversationPrinter::new(&conversation.into()));
}
Ok(())
}
@@ -136,8 +141,16 @@ impl DaemonCli {
.map_err(|e| anyhow::anyhow!("Failed to sync conversations: {}", e))
}
pub async fn print_messages(&mut self, conversation_id: String, last_message_id: Option<String>) -> Result<()> {
let messages = KordophoneRepository::get_messages(&self.proxy(), &conversation_id, &last_message_id.unwrap_or_default())?;
pub async fn print_messages(
&mut self,
conversation_id: String,
last_message_id: Option<String>,
) -> Result<()> {
let messages = KordophoneRepository::get_messages(
&self.proxy(),
&conversation_id,
&last_message_id.unwrap_or_default(),
)?;
println!("Number of messages: {}", messages.len());
for message in messages {
@@ -147,8 +160,13 @@ impl DaemonCli {
Ok(())
}
pub async fn enqueue_outgoing_message(&mut self, conversation_id: String, text: String) -> Result<()> {
let outgoing_message_id = KordophoneRepository::send_message(&self.proxy(), &conversation_id, &text)?;
pub async fn enqueue_outgoing_message(
&mut self,
conversation_id: String,
text: String,
) -> Result<()> {
let outgoing_message_id =
KordophoneRepository::send_message(&self.proxy(), &conversation_id, &text)?;
println!("Outgoing message ID: {}", outgoing_message_id);
Ok(())
}
@@ -159,10 +177,12 @@ impl DaemonCli {
pub use super::dbus_interface::NetBuzzertKordophoneRepositoryConversationsUpdated as ConversationsUpdated;
}
let _id = self.proxy().match_signal(|h: dbus_signals::ConversationsUpdated, _: &Connection, _: &Message| {
println!("Signal: Conversations updated");
true
});
let _id = self.proxy().match_signal(
|h: dbus_signals::ConversationsUpdated, _: &Connection, _: &Message| {
println!("Signal: Conversations updated");
true
},
);
println!("Waiting for signals...");
loop {
@@ -205,4 +225,4 @@ impl DaemonCli {
KordophoneRepository::delete_all_conversations(&self.proxy())
.map_err(|e| anyhow::anyhow!("Failed to delete all conversations: {}", e))
}
}
}