2025-04-27 12:53:45 -07:00
|
|
|
use tokio::sync::oneshot;
|
2025-05-02 14:22:43 -07:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
2025-05-03 21:45:53 -07:00
|
|
|
use kordophone::model::ConversationID;
|
|
|
|
|
use kordophone::model::OutgoingMessage;
|
2025-05-25 18:52:18 -07:00
|
|
|
use kordophone_db::models::{Conversation, Message};
|
2025-05-03 21:45:53 -07:00
|
|
|
|
2025-04-27 18:07:58 -07:00
|
|
|
use crate::daemon::settings::Settings;
|
2025-05-25 18:52:18 -07:00
|
|
|
use crate::daemon::Attachment;
|
2025-04-27 12:53:45 -07:00
|
|
|
|
2025-04-27 13:40:59 -07:00
|
|
|
pub type Reply<T> = oneshot::Sender<T>;
|
2025-04-27 12:53:45 -07:00
|
|
|
|
2025-04-27 13:40:59 -07:00
|
|
|
#[derive(Debug)]
|
2025-04-27 12:53:45 -07:00
|
|
|
pub enum Event {
|
|
|
|
|
/// Get the version of the daemon.
|
|
|
|
|
GetVersion(Reply<String>),
|
|
|
|
|
|
2025-05-01 20:36:43 -07:00
|
|
|
/// Asynchronous event for syncing the conversation list with the server.
|
|
|
|
|
SyncConversationList(Reply<()>),
|
|
|
|
|
|
2025-05-25 18:52:18 -07:00
|
|
|
/// Asynchronous event for syncing all conversations with the server.
|
2025-04-27 12:53:45 -07:00
|
|
|
SyncAllConversations(Reply<()>),
|
|
|
|
|
|
2025-04-28 18:39:52 -07:00
|
|
|
/// Asynchronous event for syncing a single conversation with the server.
|
|
|
|
|
SyncConversation(String, Reply<()>),
|
|
|
|
|
|
2025-04-27 12:53:45 -07:00
|
|
|
/// Returns all known conversations from the database.
|
2025-05-25 18:52:18 -07:00
|
|
|
/// Parameters:
|
2025-05-03 18:19:48 -07:00
|
|
|
/// - limit: The maximum number of conversations to return. (-1 for no limit)
|
|
|
|
|
/// - offset: The offset into the conversation list to start returning conversations from.
|
|
|
|
|
GetAllConversations(i32, i32, Reply<Vec<Conversation>>),
|
2025-04-27 18:07:58 -07:00
|
|
|
|
|
|
|
|
/// Returns all known settings from the database.
|
|
|
|
|
GetAllSettings(Reply<Settings>),
|
|
|
|
|
|
|
|
|
|
/// Update settings in the database.
|
|
|
|
|
UpdateSettings(Settings, Reply<()>),
|
2025-04-28 16:00:04 -07:00
|
|
|
|
|
|
|
|
/// Returns all messages for a conversation from the database.
|
2025-05-25 18:52:18 -07:00
|
|
|
/// Parameters:
|
2025-04-28 16:00:04 -07:00
|
|
|
/// - conversation_id: The ID of the conversation to get messages for.
|
|
|
|
|
/// - last_message_id: (optional) The ID of the last message to get. If None, all messages are returned.
|
|
|
|
|
GetMessages(String, Option<String>, Reply<Vec<Message>>),
|
2025-05-01 01:08:13 -07:00
|
|
|
|
2025-05-02 14:22:43 -07:00
|
|
|
/// Enqueues a message to be sent to the server.
|
2025-05-25 18:52:18 -07:00
|
|
|
/// Parameters:
|
2025-05-02 14:22:43 -07:00
|
|
|
/// - conversation_id: The ID of the conversation to send the message to.
|
|
|
|
|
/// - text: The text of the message to send.
|
|
|
|
|
/// - reply: The outgoing message ID (not the server-assigned message ID).
|
|
|
|
|
SendMessage(String, String, Reply<Uuid>),
|
|
|
|
|
|
2025-05-03 21:45:53 -07:00
|
|
|
/// Notifies the daemon that a message has been sent.
|
2025-05-25 18:52:18 -07:00
|
|
|
/// Parameters:
|
2025-05-03 21:45:53 -07:00
|
|
|
/// - message: The message that was sent.
|
|
|
|
|
/// - outgoing_message: The outgoing message that was sent.
|
|
|
|
|
/// - conversation_id: The ID of the conversation that the message was sent to.
|
|
|
|
|
MessageSent(Message, OutgoingMessage, ConversationID),
|
|
|
|
|
|
2025-05-25 18:52:18 -07:00
|
|
|
/// Gets an attachment object from the attachment store.
|
|
|
|
|
/// Parameters:
|
|
|
|
|
/// - guid: The attachment guid
|
|
|
|
|
/// - reply: Reply of the attachment object, if known.
|
|
|
|
|
GetAttachment(String, Reply<Attachment>),
|
|
|
|
|
|
2025-05-26 16:19:26 -07:00
|
|
|
/// Downloads an attachment from the server.
|
|
|
|
|
/// Parameters:
|
|
|
|
|
/// - attachment_id: The attachment ID to download
|
|
|
|
|
/// - reply: Reply indicating success or failure
|
|
|
|
|
DownloadAttachment(String, Reply<()>),
|
|
|
|
|
|
2025-05-01 01:08:13 -07:00
|
|
|
/// Delete all conversations from the database.
|
|
|
|
|
DeleteAllConversations(Reply<()>),
|
2025-04-27 12:53:45 -07:00
|
|
|
}
|