diff options
author | 2025-04-17 17:30:22 +0100 | |
---|---|---|
committer | 2025-04-17 17:30:22 +0100 | |
commit | 61b755c890dcaa66daa35942ca87cc00269b0fe9 (patch) | |
tree | 36190a844cfef474d5e11fe473db462bb4a4d135 /filamento/src/presence.rs | |
parent | 26d0ee51e232b793bc83ba565c0e9ab820d8d0db (diff) | |
download | luz-61b755c890dcaa66daa35942ca87cc00269b0fe9.tar.gz luz-61b755c890dcaa66daa35942ca87cc00269b0fe9.tar.bz2 luz-61b755c890dcaa66daa35942ca87cc00269b0fe9.zip |
feat(filamento): full wasm support by switching to rusqlite
Diffstat (limited to 'filamento/src/presence.rs')
-rw-r--r-- | filamento/src/presence.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/filamento/src/presence.rs b/filamento/src/presence.rs index e406cce..2184ad2 100644 --- a/filamento/src/presence.rs +++ b/filamento/src/presence.rs @@ -1,4 +1,8 @@ use chrono::{DateTime, Utc}; +use rusqlite::{ + ToSql, + types::{FromSql, ToSqlOutput, Value}, +}; use stanza::{client::presence::String1024, xep_0203::Delay}; use crate::caps; @@ -18,6 +22,30 @@ pub enum Show { ExtendedAway, } +impl ToSql for Show { + fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> { + Ok(match self { + Show::Away => ToSqlOutput::Owned(Value::Text("away".to_string())), + Show::Chat => ToSqlOutput::Owned(Value::Text("chat".to_string())), + Show::DoNotDisturb => ToSqlOutput::Owned(Value::Text("do-not-disturb".to_string())), + Show::ExtendedAway => ToSqlOutput::Owned(Value::Text("extended-away".to_string())), + }) + } +} + +impl FromSql for Show { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> { + Ok(match value.as_str()? { + "away" => Self::Away, + "chat" => Self::Chat, + "do-not-disturb" => Self::DoNotDisturb, + "extended-away" => Self::ExtendedAway, + // TODO: horrible + value => panic!("unexpected {value}"), + }) + } +} + #[derive(Debug, Default, Clone)] pub struct Offline { pub status: Option<String>, |