Add plumbing for new message/reply through core, gtk, and osx
This commit is contained in:
@@ -114,11 +114,23 @@ impl DaemonClient for DBusClient {
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn send_message(&mut self, conversation_id: String, text: String) -> Result<Option<String>> {
|
||||
fn reply(&mut self, conversation_id: String, text: String) -> Result<Option<String>> {
|
||||
let attachment_guids: Vec<&str> = vec![];
|
||||
let outgoing_id = KordophoneRepository::send_message(
|
||||
let outgoing_id =
|
||||
KordophoneRepository::reply(&self.proxy(), &conversation_id, &text, attachment_guids)?;
|
||||
Ok(Some(outgoing_id))
|
||||
}
|
||||
|
||||
fn new_conversation(
|
||||
&mut self,
|
||||
handle_ids: Vec<String>,
|
||||
text: String,
|
||||
) -> Result<Option<String>> {
|
||||
let attachment_guids: Vec<&str> = vec![];
|
||||
let handle_ids: Vec<&str> = handle_ids.iter().map(String::as_str).collect();
|
||||
let outgoing_id = KordophoneRepository::new_conversation(
|
||||
&self.proxy(),
|
||||
&conversation_id,
|
||||
handle_ids,
|
||||
&text,
|
||||
attachment_guids,
|
||||
)?;
|
||||
|
||||
@@ -201,7 +201,7 @@ impl DaemonClient for XpcClient {
|
||||
Ok(messages)
|
||||
}
|
||||
|
||||
fn send_message(&mut self, conversation_id: String, text: String) -> Result<Option<String>> {
|
||||
fn reply(&mut self, conversation_id: String, text: String) -> Result<Option<String>> {
|
||||
let mut args = HashMap::new();
|
||||
args.insert(
|
||||
Self::key("conversation_id"),
|
||||
@@ -211,7 +211,34 @@ impl DaemonClient for XpcClient {
|
||||
|
||||
let reply = self
|
||||
.transport
|
||||
.send_with_reply(Self::request("SendMessage", Some(args)));
|
||||
.send_with_reply(Self::request("Reply", Some(args)));
|
||||
let Message::Dictionary(map) = reply else {
|
||||
anyhow::bail!("Unexpected send response");
|
||||
};
|
||||
|
||||
Ok(Self::get_string(&map, "uuid"))
|
||||
}
|
||||
|
||||
fn new_conversation(
|
||||
&mut self,
|
||||
handle_ids: Vec<String>,
|
||||
text: String,
|
||||
) -> Result<Option<String>> {
|
||||
let mut args = HashMap::new();
|
||||
args.insert(
|
||||
Self::key("handle_ids"),
|
||||
Message::Array(
|
||||
handle_ids
|
||||
.into_iter()
|
||||
.map(|handle_id| Message::String(Self::key(&handle_id)))
|
||||
.collect(),
|
||||
),
|
||||
);
|
||||
args.insert(Self::key("text"), Message::String(Self::key(&text)));
|
||||
|
||||
let reply = self
|
||||
.transport
|
||||
.send_with_reply(Self::request("NewConversation", Some(args)));
|
||||
let Message::Dictionary(map) = reply else {
|
||||
anyhow::bail!("Unexpected send response");
|
||||
};
|
||||
|
||||
@@ -24,10 +24,14 @@ pub enum Request {
|
||||
RefreshMessages {
|
||||
conversation_id: String,
|
||||
},
|
||||
SendMessage {
|
||||
Reply {
|
||||
conversation_id: String,
|
||||
text: String,
|
||||
},
|
||||
NewConversation {
|
||||
handle_ids: Vec<String>,
|
||||
text: String,
|
||||
},
|
||||
MarkRead {
|
||||
conversation_id: String,
|
||||
},
|
||||
@@ -42,8 +46,8 @@ pub enum Event {
|
||||
conversation_id: String,
|
||||
messages: Vec<ChatMessage>,
|
||||
},
|
||||
MessageSent {
|
||||
conversation_id: String,
|
||||
MessageQueued {
|
||||
conversation_id: Option<String>,
|
||||
outgoing_id: Option<String>,
|
||||
},
|
||||
MarkedRead,
|
||||
@@ -80,33 +84,38 @@ pub fn spawn_worker(
|
||||
loop {
|
||||
match request_rx.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(req) => {
|
||||
let res =
|
||||
match req {
|
||||
Request::RefreshConversations => {
|
||||
client.get_conversations(200, 0).map(Event::Conversations)
|
||||
}
|
||||
Request::RefreshMessages { conversation_id } => client
|
||||
.get_messages(conversation_id.clone(), None)
|
||||
.map(|messages| Event::Messages {
|
||||
conversation_id,
|
||||
messages,
|
||||
}),
|
||||
Request::SendMessage {
|
||||
let res = match req {
|
||||
Request::RefreshConversations => {
|
||||
client.get_conversations(200, 0).map(Event::Conversations)
|
||||
}
|
||||
Request::RefreshMessages { conversation_id } => client
|
||||
.get_messages(conversation_id.clone(), None)
|
||||
.map(|messages| Event::Messages {
|
||||
conversation_id,
|
||||
text,
|
||||
} => client.send_message(conversation_id.clone(), text).map(
|
||||
|outgoing_id| Event::MessageSent {
|
||||
conversation_id,
|
||||
outgoing_id,
|
||||
},
|
||||
),
|
||||
Request::MarkRead { conversation_id } => client
|
||||
.mark_conversation_as_read(conversation_id.clone())
|
||||
.map(|_| Event::MarkedRead),
|
||||
Request::SyncConversation { conversation_id } => client
|
||||
.sync_conversation(conversation_id.clone())
|
||||
.map(|_| Event::ConversationSyncTriggered { conversation_id }),
|
||||
};
|
||||
messages,
|
||||
}),
|
||||
Request::Reply {
|
||||
conversation_id,
|
||||
text,
|
||||
} => client
|
||||
.reply(conversation_id.clone(), text)
|
||||
.map(|outgoing_id| Event::MessageQueued {
|
||||
conversation_id: Some(conversation_id),
|
||||
outgoing_id,
|
||||
}),
|
||||
Request::NewConversation { handle_ids, text } => client
|
||||
.new_conversation(handle_ids, text)
|
||||
.map(|outgoing_id| Event::MessageQueued {
|
||||
conversation_id: None,
|
||||
outgoing_id,
|
||||
}),
|
||||
Request::MarkRead { conversation_id } => client
|
||||
.mark_conversation_as_read(conversation_id.clone())
|
||||
.map(|_| Event::MarkedRead),
|
||||
Request::SyncConversation { conversation_id } => client
|
||||
.sync_conversation(conversation_id.clone())
|
||||
.map(|_| Event::ConversationSyncTriggered { conversation_id }),
|
||||
};
|
||||
|
||||
match res {
|
||||
Ok(evt) => {
|
||||
@@ -135,7 +144,9 @@ pub(crate) trait DaemonClient {
|
||||
conversation_id: String,
|
||||
last_message_id: Option<String>,
|
||||
) -> Result<Vec<ChatMessage>>;
|
||||
fn send_message(&mut self, conversation_id: String, text: String) -> Result<Option<String>>;
|
||||
fn reply(&mut self, conversation_id: String, text: String) -> Result<Option<String>>;
|
||||
fn new_conversation(&mut self, handle_ids: Vec<String>, text: String)
|
||||
-> Result<Option<String>>;
|
||||
fn mark_conversation_as_read(&mut self, conversation_id: String) -> Result<()>;
|
||||
fn sync_conversation(&mut self, conversation_id: String) -> Result<()>;
|
||||
fn install_signal_handlers(&mut self, _event_tx: mpsc::Sender<Event>) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user