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,12 +1,12 @@
use kordophone::APIInterface;
use kordophone::api::http_client::HTTPAPIClient;
use kordophone::api::http_client::Credentials;
use kordophone::api::InMemoryAuthenticationStore;
use kordophone::api::event_socket::EventSocket;
use kordophone::api::http_client::Credentials;
use kordophone::api::http_client::HTTPAPIClient;
use kordophone::api::InMemoryAuthenticationStore;
use kordophone::APIInterface;
use crate::printers::{ConversationPrinter, MessagePrinter};
use anyhow::Result;
use clap::Subcommand;
use crate::printers::{ConversationPrinter, MessagePrinter};
use kordophone::model::event::EventData;
use kordophone::model::outgoing_message::OutgoingMessage;
@@ -16,18 +16,18 @@ pub fn make_api_client_from_env() -> HTTPAPIClient<InMemoryAuthenticationStore>
dotenv::dotenv().ok();
// read from env
let base_url = std::env::var("KORDOPHONE_API_URL")
.expect("KORDOPHONE_API_URL must be set");
let base_url = std::env::var("KORDOPHONE_API_URL").expect("KORDOPHONE_API_URL must be set");
let credentials = Credentials {
username: std::env::var("KORDOPHONE_USERNAME")
.expect("KORDOPHONE_USERNAME must be set"),
username: std::env::var("KORDOPHONE_USERNAME").expect("KORDOPHONE_USERNAME must be set"),
password: std::env::var("KORDOPHONE_PASSWORD")
.expect("KORDOPHONE_PASSWORD must be set"),
password: std::env::var("KORDOPHONE_PASSWORD").expect("KORDOPHONE_PASSWORD must be set"),
};
HTTPAPIClient::new(base_url.parse().unwrap(), InMemoryAuthenticationStore::new(Some(credentials)))
HTTPAPIClient::new(
base_url.parse().unwrap(),
InMemoryAuthenticationStore::new(Some(credentials)),
)
}
#[derive(Subcommand)]
@@ -36,9 +36,7 @@ pub enum Commands {
Conversations,
/// Prints all messages in a conversation.
Messages {
conversation_id: String,
},
Messages { conversation_id: String },
/// Prints the server Kordophone version.
Version,
@@ -65,7 +63,10 @@ impl Commands {
Commands::Messages { conversation_id } => client.print_messages(conversation_id).await,
Commands::RawUpdates => client.print_raw_updates().await,
Commands::Events => client.print_events().await,
Commands::SendMessage { conversation_id, message } => client.send_message(conversation_id, message).await,
Commands::SendMessage {
conversation_id,
message,
} => client.send_message(conversation_id, message).await,
}
}
}
@@ -96,7 +97,10 @@ impl ClientCli {
}
pub async fn print_messages(&mut self, conversation_id: String) -> Result<()> {
let messages = self.api.get_messages(&conversation_id, None, None, None).await?;
let messages = self
.api
.get_messages(&conversation_id, None, None, None)
.await?;
for message in messages {
println!("{}", MessagePrinter::new(&message.into()));
}
@@ -113,8 +117,11 @@ impl ClientCli {
println!("Conversation changed: {}", conversation.guid);
}
EventData::MessageReceived(conversation, message) => {
println!("Message received: msg: {} conversation: {}", message.guid, conversation.guid);
}
println!(
"Message received: msg: {} conversation: {}",
message.guid, conversation.guid
);
}
}
}
Ok(())
@@ -143,5 +150,3 @@ impl ClientCli {
Ok(())
}
}