aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/presence.rs
diff options
context:
space:
mode:
Diffstat (limited to 'filamento/src/presence.rs')
-rw-r--r--filamento/src/presence.rs28
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>,