aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src
diff options
context:
space:
mode:
Diffstat (limited to 'filamento/src')
-rw-r--r--filamento/src/chat.rs51
-rw-r--r--filamento/src/db.rs13
-rw-r--r--filamento/src/error.rs26
-rw-r--r--filamento/src/presence.rs41
-rw-r--r--filamento/src/roster.rs50
-rw-r--r--filamento/src/user.rs2
6 files changed, 25 insertions, 158 deletions
diff --git a/filamento/src/chat.rs b/filamento/src/chat.rs
index 147c7f7..557b42b 100644
--- a/filamento/src/chat.rs
+++ b/filamento/src/chat.rs
@@ -1,13 +1,11 @@
use chrono::{DateTime, Utc};
use jid::JID;
-use sqlx::Sqlite;
use uuid::Uuid;
-#[derive(Debug, sqlx::FromRow, Clone)]
+#[derive(Debug, Clone)]
pub struct Message {
pub id: Uuid,
// does not contain full user information
- #[sqlx(rename = "from_jid")]
// bare jid (for now)
pub from: JID,
pub delivery: Option<Delivery>,
@@ -15,7 +13,6 @@ pub struct Message {
// TODO: originally_from
// TODO: message edits
// TODO: message timestamp
- #[sqlx(flatten)]
pub body: Body,
}
@@ -30,61 +27,19 @@ pub enum Delivery {
Queued,
}
-impl sqlx::Type<Sqlite> for Delivery {
- fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo {
- <&str as sqlx::Type<Sqlite>>::type_info()
- }
-}
-
-impl sqlx::Decode<'_, Sqlite> for Delivery {
- fn decode(
- value: <Sqlite as sqlx::Database>::ValueRef<'_>,
- ) -> Result<Self, sqlx::error::BoxDynError> {
- let value = <&str as sqlx::Decode<Sqlite>>::decode(value)?;
- match value {
- "sending" => Ok(Self::Sending),
- "written" => Ok(Self::Written),
- "sent" => Ok(Self::Sent),
- "delivered" => Ok(Self::Delivered),
- "read" => Ok(Self::Read),
- "failed" => Ok(Self::Failed),
- "queued" => Ok(Self::Queued),
- _ => unreachable!(),
- }
- }
-}
-
-impl sqlx::Encode<'_, Sqlite> for Delivery {
- fn encode_by_ref(
- &self,
- buf: &mut <Sqlite as sqlx::Database>::ArgumentBuffer<'_>,
- ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
- let value = match self {
- Delivery::Sending => "sending",
- Delivery::Written => "written",
- Delivery::Sent => "sent",
- Delivery::Delivered => "delivered",
- Delivery::Read => "read",
- Delivery::Failed => "failed",
- Delivery::Queued => "queued",
- };
- <&str as sqlx::Encode<Sqlite>>::encode(value, buf)
- }
-}
-
// TODO: user migrations
// pub enum Migrated {
// Jabber(User),
// Outside,
// }
-#[derive(Debug, sqlx::FromRow, Clone)]
+#[derive(Debug, Clone)]
pub struct Body {
// TODO: rich text, other contents, threads
pub body: String,
}
-#[derive(sqlx::FromRow, Debug, Clone)]
+#[derive(Debug, Clone)]
pub struct Chat {
pub correspondent: JID,
pub have_chatted: bool,
diff --git a/filamento/src/db.rs b/filamento/src/db.rs
index e3bfdac..467030d 100644
--- a/filamento/src/db.rs
+++ b/filamento/src/db.rs
@@ -2,7 +2,6 @@ use std::{collections::HashSet, path::Path};
use chrono::{DateTime, Utc};
use jid::JID;
-use sqlx::{SqlitePool, migrate};
use uuid::Uuid;
use crate::{
@@ -41,8 +40,8 @@ impl Db {
.to_str()
.ok_or(DatabaseOpenError::InvalidPath)?
);
- let db = SqlitePool::connect(&url).await?;
- migrate!().run(&db).await?;
+ // let db = SqlitePool::connect(&url).await?;
+ // migrate!().run(&db).await?;
// Ok(Self { db })
Ok(Self {})
}
@@ -57,10 +56,10 @@ impl Db {
Ok(Self {})
}
- pub(crate) fn new(db: SqlitePool) -> Self {
- // Self { db }
- Self {}
- }
+ // pub(crate) fn new(db: SqlitePool) -> Self {
+ // // Self { db }
+ // Self {}
+ // }
pub(crate) async fn create_user(&self, user: User) -> Result<(), Error> {
Ok(())
diff --git a/filamento/src/error.rs b/filamento/src/error.rs
index f2bf6ef..6b7d0ae 100644
--- a/filamento/src/error.rs
+++ b/filamento/src/error.rs
@@ -166,16 +166,16 @@ pub enum ResponseError {
#[derive(Debug, Error, Clone)]
#[error("database error: {0}")]
-pub struct DatabaseError(pub Arc<sqlx::Error>);
+pub struct DatabaseError(pub Arc<rusqlite::Error>);
-impl From<sqlx::Error> for DatabaseError {
- fn from(e: sqlx::Error) -> Self {
+impl From<rusqlite::Error> for DatabaseError {
+ fn from(e: rusqlite::Error) -> Self {
Self(Arc::new(e))
}
}
-impl From<sqlx::Error> for DatabaseOpenError {
- fn from(e: sqlx::Error) -> Self {
+impl From<rusqlite::Error> for DatabaseOpenError {
+ fn from(e: rusqlite::Error) -> Self {
Self::Error(Arc::new(e))
}
}
@@ -202,20 +202,20 @@ pub enum IqProcessError {
#[derive(Debug, Error, Clone)]
pub enum DatabaseOpenError {
#[error("error: {0}")]
- Error(Arc<sqlx::Error>),
- #[error("migration: {0}")]
- Migration(Arc<sqlx::migrate::MigrateError>),
+ Error(Arc<rusqlite::Error>),
+ // #[error("migration: {0}")]
+ // Migration(Arc<rusqlite::migrate::MigrateError>),
#[error("io: {0}")]
Io(Arc<tokio::io::Error>),
#[error("invalid path")]
InvalidPath,
}
-impl From<sqlx::migrate::MigrateError> for DatabaseOpenError {
- fn from(e: sqlx::migrate::MigrateError) -> Self {
- Self::Migration(Arc::new(e))
- }
-}
+// impl From<sqlx::migrate::MigrateError> for DatabaseOpenError {
+// fn from(e: sqlx::migrate::MigrateError) -> Self {
+// Self::Migration(Arc::new(e))
+// }
+// }
impl From<tokio::io::Error> for DatabaseOpenError {
fn from(e: tokio::io::Error) -> Self {
diff --git a/filamento/src/presence.rs b/filamento/src/presence.rs
index a7a8965..e406cce 100644
--- a/filamento/src/presence.rs
+++ b/filamento/src/presence.rs
@@ -1,15 +1,12 @@
use chrono::{DateTime, Utc};
-use sqlx::Sqlite;
use stanza::{client::presence::String1024, xep_0203::Delay};
use crate::caps;
-#[derive(Debug, Default, sqlx::FromRow, Clone)]
+#[derive(Debug, Default, Clone)]
pub struct Online {
pub show: Option<Show>,
- #[sqlx(rename = "message")]
pub status: Option<String>,
- #[sqlx(skip)]
pub priority: Option<i8>,
}
@@ -21,42 +18,6 @@ pub enum Show {
ExtendedAway,
}
-impl sqlx::Type<Sqlite> for Show {
- fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo {
- <&str as sqlx::Type<Sqlite>>::type_info()
- }
-}
-
-impl sqlx::Decode<'_, Sqlite> for Show {
- fn decode(
- value: <Sqlite as sqlx::Database>::ValueRef<'_>,
- ) -> Result<Self, sqlx::error::BoxDynError> {
- let value = <&str as sqlx::Decode<Sqlite>>::decode(value)?;
- match value {
- "away" => Ok(Self::Away),
- "chat" => Ok(Self::Chat),
- "do-not-disturb" => Ok(Self::DoNotDisturb),
- "extended-away" => Ok(Self::ExtendedAway),
- _ => unreachable!(),
- }
- }
-}
-
-impl sqlx::Encode<'_, Sqlite> for Show {
- fn encode_by_ref(
- &self,
- buf: &mut <Sqlite as sqlx::Database>::ArgumentBuffer<'_>,
- ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
- let value = match self {
- Show::Away => "away",
- Show::Chat => "chat",
- Show::DoNotDisturb => "do-not-disturb",
- Show::ExtendedAway => "extended-away",
- };
- <&str as sqlx::Encode<Sqlite>>::encode(value, buf)
- }
-}
-
#[derive(Debug, Default, Clone)]
pub struct Offline {
pub status: Option<String>,
diff --git a/filamento/src/roster.rs b/filamento/src/roster.rs
index 43c32f5..ba5b3cd 100644
--- a/filamento/src/roster.rs
+++ b/filamento/src/roster.rs
@@ -1,14 +1,13 @@
use std::collections::HashSet;
use jid::JID;
-use sqlx::Sqlite;
pub struct ContactUpdate {
pub name: Option<String>,
pub groups: HashSet<String>,
}
-#[derive(Debug, sqlx::FromRow, Clone)]
+#[derive(Debug, Clone)]
pub struct Contact {
// jid is the id used to reference everything, but not the primary key
pub user_jid: JID,
@@ -18,7 +17,6 @@ pub struct Contact {
// TODO: avatar, nickname
/// nickname picked by contact
// nickname: Option<String>,
- #[sqlx(skip)]
pub groups: HashSet<String>,
}
@@ -37,52 +35,6 @@ pub enum Subscription {
// Remove,
}
-impl sqlx::Type<Sqlite> for Subscription {
- fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo {
- <&str as sqlx::Type<Sqlite>>::type_info()
- }
-}
-
-impl sqlx::Decode<'_, Sqlite> for Subscription {
- fn decode(
- value: <Sqlite as sqlx::Database>::ValueRef<'_>,
- ) -> Result<Self, sqlx::error::BoxDynError> {
- let value = <&str as sqlx::Decode<Sqlite>>::decode(value)?;
- match value {
- "none" => Ok(Self::None),
- "pending-out" => Ok(Self::PendingOut),
- "pending-in" => Ok(Self::PendingIn),
- "pending-in-pending-out" => Ok(Self::PendingInPendingOut),
- "only-out" => Ok(Self::OnlyOut),
- "only-in" => Ok(Self::OnlyIn),
- "out-pending-in" => Ok(Self::OutPendingIn),
- "in-pending-out" => Ok(Self::InPendingOut),
- "buddy" => Ok(Self::Buddy),
- _ => panic!("unexpected subscription `{value}`"),
- }
- }
-}
-
-impl sqlx::Encode<'_, Sqlite> for Subscription {
- fn encode_by_ref(
- &self,
- buf: &mut <Sqlite as sqlx::Database>::ArgumentBuffer<'_>,
- ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
- let value = match self {
- Subscription::None => "none",
- Subscription::PendingOut => "pending-out",
- Subscription::PendingIn => "pending-in",
- Subscription::PendingInPendingOut => "pending-in-pending-out",
- Subscription::OnlyOut => "only-out",
- Subscription::OnlyIn => "only-in",
- Subscription::OutPendingIn => "out-pending-in",
- Subscription::InPendingOut => "in-pending-out",
- Subscription::Buddy => "buddy",
- };
- <&str as sqlx::Encode<Sqlite>>::encode(value, buf)
- }
-}
-
// none
// >
// >>
diff --git a/filamento/src/user.rs b/filamento/src/user.rs
index 8669fc3..b2ea8e4 100644
--- a/filamento/src/user.rs
+++ b/filamento/src/user.rs
@@ -1,6 +1,6 @@
use jid::JID;
-#[derive(Debug, sqlx::FromRow, Clone)]
+#[derive(Debug, Clone)]
pub struct User {
pub jid: JID,
pub nick: Option<String>,