diff --git a/luz/migrations/20240113011930_luz.sql b/luz/migrations/20240113011930_luz.sql index a758a23..d8eb90d 100644 --- a/luz/migrations/20240113011930_luz.sql +++ b/luz/migrations/20240113011930_luz.sql @@ -4,6 +4,7 @@ PRAGMA foreign_keys = on; -- TODO: avatar, nick, etc. create table user( jid jid primary key, + -- can receive presence status from non-contacts cached_status text, ); @@ -36,9 +37,11 @@ create table groups_roster( ); -- chat includes reference to user jid chat is with +-- specifically for dms, groups should be different +-- can send chat message to user (creating a new chat if not already exists) create table chats ( id uuid primary key, - contact_id jid not null unique, + user_id jid not null unique, ); -- messages include reference to chat they are in, and who sent them. @@ -46,6 +49,7 @@ create table messages ( id uuid primary key, body text, chat_id uuid not null, + -- TODO: from can be either a jid, a moved jid (for when a contact moves, save original sender jid/user but link to new user), or imported (from another service (save details), linked to new user) from jid not null, -- TODO: read bool not null, foreign key(chat_id) references chats(id), diff --git a/luz/src/chat.rs b/luz/src/chat.rs index a084d29..091b3b6 100644 --- a/luz/src/chat.rs +++ b/luz/src/chat.rs @@ -1,17 +1,12 @@ use uuid::Uuid; -use crate::roster::Contact; - -pub enum Chat { - Direct(DM), - Channel(Channel), -} +use crate::{roster::Contact, user::User}; #[derive(Debug)] pub struct Message { id: Uuid, - // contains full contact information - from: Contact, + // contains full user information + from: User, // TODO: rich text, other contents, threads body: Body, } @@ -21,10 +16,15 @@ pub struct Body { body: String, } -pub struct DM { - contact: Contact, +pub struct Chat { + id: Uuid, + user: User, message_history: Vec, } // TODO: group chats -pub struct Channel {} +// pub enum Chat { +// Direct(DirectChat), +// Channel(Channel), +// } +// pub struct Channel {} diff --git a/luz/src/lib.rs b/luz/src/lib.rs index 1fb58d6..07dc74a 100644 --- a/luz/src/lib.rs +++ b/luz/src/lib.rs @@ -29,6 +29,7 @@ mod connection; mod error; mod presence; mod roster; +mod user; pub struct Luz { receiver: mpsc::Receiver, @@ -269,9 +270,10 @@ impl LuzHandle { } pub enum CommandMessage { - /// connect to XMPP chat server. gets roster and + // TODO: login invisible xep-0186 + /// connect to XMPP chat server. gets roster and publishes initial presence. Connect, - /// disconnect from XMPP chat server. + /// disconnect from XMPP chat server, sending unavailable presence then closing stream. Disconnect, /// get the roster. if offline, retreive cached version from database. should be stored in application memory GetRoster, diff --git a/luz/src/roster.rs b/luz/src/roster.rs index c4502a0..421ee9d 100644 --- a/luz/src/roster.rs +++ b/luz/src/roster.rs @@ -3,9 +3,12 @@ use std::collections::HashSet; use jid::JID; use uuid::Uuid; +use crate::user::User; + #[derive(Debug)] pub struct Contact { // jid is the id used to reference everything, but not the primary key + user: User, jid: JID, subscription: Subscription, /// client user defined name diff --git a/luz/src/user.rs b/luz/src/user.rs new file mode 100644 index 0000000..f4dec84 --- /dev/null +++ b/luz/src/user.rs @@ -0,0 +1,7 @@ +use jid::JID; + +#[derive(Debug)] +pub struct User { + jid: JID, + cached_status: Option, +}