aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'filamento/src/lib.rs')
-rw-r--r--filamento/src/lib.rs74
1 files changed, 40 insertions, 34 deletions
diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs
index 030dc43..b284c7e 100644
--- a/filamento/src/lib.rs
+++ b/filamento/src/lib.rs
@@ -98,6 +98,33 @@ pub enum Command {
/// chatroom). if disconnected, will be cached so when client connects, message will be sent.
SendMessage(JID, Body, oneshot::Sender<Result<(), WriteError>>),
}
+
+#[derive(Debug, Clone)]
+pub enum UpdateMessage {
+ Error(Error),
+ Online(Online, Vec<Contact>),
+ Offline(Offline),
+ /// received roster from jabber server (replace full app roster state with this)
+ /// is this needed?
+ FullRoster(Vec<Contact>),
+ /// (only update app roster state, don't replace)
+ RosterUpdate(Contact),
+ RosterDelete(JID),
+ /// presences should be stored with users in the ui, not contacts, as presences can be received from anyone
+ Presence {
+ from: JID,
+ presence: Presence,
+ },
+ // TODO: receipts
+ // MessageDispatched(Uuid),
+ Message {
+ to: JID,
+ message: Message,
+ },
+ SubscriptionRequest(jid::JID),
+ Unsupported(Stanza),
+}
+
/// an xmpp client that is suited for a chat client use case
#[derive(Debug)]
pub struct Client {
@@ -147,20 +174,24 @@ impl Client {
let (_sup_send, sup_recv) = oneshot::channel();
let sup_recv = sup_recv.fuse();
- let logic = ClientLogic::new(db, Arc::new(Mutex::new(HashMap::new())), update_send);
+ let client = Self {
+ sender: command_sender,
+ // TODO: configure timeout
+ timeout: Duration::from_secs(10),
+ };
+
+ let logic = ClientLogic::new(
+ client.clone(),
+ db,
+ Arc::new(Mutex::new(HashMap::new())),
+ update_send,
+ );
let actor: CoreClient<ClientLogic> =
CoreClient::new(jid, password, command_receiver, None, sup_recv, logic);
tokio::spawn(async move { actor.run().await });
- (
- Self {
- sender: command_sender,
- // TODO: configure timeout
- timeout: Duration::from_secs(10),
- },
- update_recv,
- )
+ (client, update_recv)
}
pub async fn get_roster(&self) -> Result<Vec<Contact>, CommandError<RosterError>> {
@@ -453,28 +484,3 @@ impl From<Command> for CoreClientCommand<Command> {
CoreClientCommand::Command(value)
}
}
-
-#[derive(Debug, Clone)]
-pub enum UpdateMessage {
- Error(Error),
- Online(Online, Vec<Contact>),
- Offline(Offline),
- /// received roster from jabber server (replace full app roster state with this)
- /// is this needed?
- FullRoster(Vec<Contact>),
- /// (only update app roster state, don't replace)
- RosterUpdate(Contact),
- RosterDelete(JID),
- /// presences should be stored with users in the ui, not contacts, as presences can be received from anyone
- Presence {
- from: JID,
- presence: Presence,
- },
- // TODO: receipts
- // MessageDispatched(Uuid),
- Message {
- to: JID,
- message: Message,
- },
- SubscriptionRequest(jid::JID),
-}