Private
Public Access
1
0

Add plumbing for new message/reply through core, gtk, and osx

This commit is contained in:
2026-04-01 18:03:15 -07:00
parent a61127622c
commit 99f695d6f2
22 changed files with 460 additions and 128 deletions

View File

@@ -93,7 +93,9 @@ impl Commands {
Commands::Mark { conversation_id } => {
client.mark_conversation_as_read(conversation_id).await
}
Commands::Delete { conversation_id } => client.delete_conversation(conversation_id).await,
Commands::Delete { conversation_id } => {
client.delete_conversation(conversation_id).await
}
}
}
}
@@ -211,11 +213,7 @@ impl ClientCli {
Ok(())
}
async fn send_message(
&mut self,
target: OutgoingMessageTarget,
message: String,
) -> Result<()> {
async fn send_message(&mut self, target: OutgoingMessageTarget, message: String) -> Result<()> {
let outgoing_message = OutgoingMessage::builder()
.target(target)
.text(message)
@@ -255,8 +253,11 @@ impl ClientCli {
}
pub async fn reply(&mut self, conversation_id: String, message: String) -> Result<()> {
self.send_message(OutgoingMessageTarget::Conversation(conversation_id), message)
.await
self.send_message(
OutgoingMessageTarget::Conversation(conversation_id),
message,
)
.await
}
pub async fn new_message(&mut self, handle_ids: Vec<String>, message: String) -> Result<()> {

View File

@@ -109,15 +109,20 @@ impl DaemonInterface for DBusDaemonInterface {
Ok(())
}
async fn enqueue_outgoing_message(
&mut self,
conversation_id: String,
text: String,
) -> Result<()> {
async fn reply(&mut self, conversation_id: String, text: String) -> Result<()> {
let attachment_guids: Vec<&str> = vec![];
let outgoing_message_id = KordophoneRepository::send_message(
let outgoing_message_id =
KordophoneRepository::reply(&self.proxy(), &conversation_id, &text, attachment_guids)?;
println!("Outgoing message ID: {}", outgoing_message_id);
Ok(())
}
async fn new_conversation(&mut self, handle_ids: Vec<String>, text: String) -> Result<()> {
let attachment_guids: Vec<&str> = vec![];
let handle_ids: Vec<&str> = handle_ids.iter().map(String::as_str).collect();
let outgoing_message_id = KordophoneRepository::new_conversation(
&self.proxy(),
&conversation_id,
handle_ids,
&text,
attachment_guids,
)?;

View File

@@ -21,11 +21,8 @@ pub trait DaemonInterface {
conversation_id: String,
last_message_id: Option<String>,
) -> Result<()>;
async fn enqueue_outgoing_message(
&mut self,
conversation_id: String,
text: String,
) -> Result<()>;
async fn reply(&mut self, conversation_id: String, text: String) -> Result<()>;
async fn new_conversation(&mut self, handle_ids: Vec<String>, text: String) -> Result<()>;
async fn wait_for_signals(&mut self) -> Result<()>;
async fn config(&mut self, cmd: ConfigCommands) -> Result<()>;
async fn delete_all_conversations(&mut self) -> Result<()>;
@@ -73,11 +70,12 @@ impl DaemonInterface for StubDaemonInterface {
"Daemon interface not implemented on this platform"
))
}
async fn enqueue_outgoing_message(
&mut self,
_conversation_id: String,
_text: String,
) -> Result<()> {
async fn reply(&mut self, _conversation_id: String, _text: String) -> Result<()> {
Err(anyhow::anyhow!(
"Daemon interface not implemented on this platform"
))
}
async fn new_conversation(&mut self, _handle_ids: Vec<String>, _text: String) -> Result<()> {
Err(anyhow::anyhow!(
"Daemon interface not implemented on this platform"
))
@@ -161,12 +159,20 @@ pub enum Commands {
/// Deletes all conversations.
DeleteAllConversations,
/// Enqueues an outgoing message to be sent to a conversation.
SendMessage {
/// Replies to an existing conversation.
#[command(alias = "send-message")]
Reply {
conversation_id: String,
text: String,
},
/// Starts a new conversation with one or more resolved handles.
New {
#[arg(long = "handle", required = true)]
handle_ids: Vec<String>,
text: String,
},
/// Downloads an attachment from the server to the attachment store. Returns the path to the attachment.
DownloadAttachment { attachment_id: String },
@@ -208,10 +214,11 @@ impl Commands {
.await
}
Commands::DeleteAllConversations => client.delete_all_conversations().await,
Commands::SendMessage {
Commands::Reply {
conversation_id,
text,
} => client.enqueue_outgoing_message(conversation_id, text).await,
} => client.reply(conversation_id, text).await,
Commands::New { handle_ids, text } => client.new_conversation(handle_ids, text).await,
Commands::UploadAttachment { path } => client.upload_attachment(path).await,
Commands::DownloadAttachment { attachment_id } => {
client.download_attachment(attachment_id).await

View File

@@ -371,11 +371,7 @@ impl DaemonInterface for XpcDaemonInterface {
_ => Err(anyhow::anyhow!("Unexpected messages payload")),
}
}
async fn enqueue_outgoing_message(
&mut self,
_conversation_id: String,
_text: String,
) -> Result<()> {
async fn reply(&mut self, _conversation_id: String, _text: String) -> Result<()> {
let mach_port_name = Self::build_service_name()?;
let mut client = XPCClient::connect(&mach_port_name);
let mut args = HashMap::new();
@@ -387,10 +383,34 @@ impl DaemonInterface for XpcDaemonInterface {
Self::key("text"),
Message::String(CString::new(_text).unwrap()),
);
let reply = self
.call_method(&mut client, "SendMessage", Some(args))
let response = self.call_method(&mut client, "Reply", Some(args)).await?;
if let Some(uuid) = Self::get_string(&response, "uuid") {
println!("Outgoing message ID: {}", uuid.to_string_lossy());
}
Ok(())
}
async fn new_conversation(&mut self, handle_ids: Vec<String>, text: String) -> Result<()> {
let mach_port_name = Self::build_service_name()?;
let mut client = XPCClient::connect(&mach_port_name);
let mut args = HashMap::new();
args.insert(
Self::key("handle_ids"),
Message::Array(
handle_ids
.into_iter()
.map(|handle_id| Message::String(CString::new(handle_id).unwrap()))
.collect(),
),
);
args.insert(
Self::key("text"),
Message::String(CString::new(text).unwrap()),
);
let response = self
.call_method(&mut client, "NewConversation", Some(args))
.await?;
if let Some(uuid) = Self::get_string(&reply, "uuid") {
if let Some(uuid) = Self::get_string(&response, "uuid") {
println!("Outgoing message ID: {}", uuid.to_string_lossy());
}
Ok(())