aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/chat.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 14:29:40 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 14:29:40 +0000
commit2211f324782cdc617b4b5ecd071178e372539fe4 (patch)
treea5ea5ce11d748424447dee23173d3cb8aec648ea /filamento/src/chat.rs
parent2f8671978e18c1e1e7834056ae674f32fbde3868 (diff)
downloadluz-2211f324782cdc617b4b5ecd071178e372539fe4.tar.gz
luz-2211f324782cdc617b4b5ecd071178e372539fe4.tar.bz2
luz-2211f324782cdc617b4b5ecd071178e372539fe4.zip
refactor: rename crates and move client logic to separate crate `filament`
Diffstat (limited to 'filamento/src/chat.rs')
-rw-r--r--filamento/src/chat.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/filamento/src/chat.rs b/filamento/src/chat.rs
new file mode 100644
index 0000000..c1194ea
--- /dev/null
+++ b/filamento/src/chat.rs
@@ -0,0 +1,57 @@
+use chrono::{DateTime, Utc};
+use jid::JID;
+use uuid::Uuid;
+
+#[derive(Debug, sqlx::FromRow, Clone)]
+pub struct Message {
+ pub id: Uuid,
+ // does not contain full user information
+ #[sqlx(rename = "from_jid")]
+ pub from: JID,
+ pub timestamp: DateTime<Utc>,
+ // TODO: originally_from
+ // TODO: message edits
+ // TODO: message timestamp
+ #[sqlx(flatten)]
+ pub body: Body,
+}
+
+// TODO: user migrations
+// pub enum Migrated {
+// Jabber(User),
+// Outside,
+// }
+
+#[derive(Debug, sqlx::FromRow, Clone)]
+pub struct Body {
+ // TODO: rich text, other contents, threads
+ pub body: String,
+}
+
+#[derive(sqlx::FromRow, Debug, Clone)]
+pub struct Chat {
+ pub correspondent: JID,
+ // pub unread_messages: i32,
+ // pub latest_message: Message,
+ // when a new message is received, the chat should be updated, and the new message should be delivered too.
+ // message history is not stored in chat, retreived separately.
+ // pub message_history: Vec<Message>,
+}
+
+pub enum ChatUpdate {}
+
+impl Chat {
+ pub fn new(correspondent: JID) -> Self {
+ Self { correspondent }
+ }
+ pub fn correspondent(&self) -> &JID {
+ &self.correspondent
+ }
+}
+
+// TODO: group chats
+// pub enum Chat {
+// Direct(DirectChat),
+// Channel(Channel),
+// }
+// pub struct Channel {}