aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/roster.rs
diff options
context:
space:
mode:
Diffstat (limited to 'filamento/src/roster.rs')
-rw-r--r--filamento/src/roster.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/filamento/src/roster.rs b/filamento/src/roster.rs
index ba5b3cd..99682b1 100644
--- a/filamento/src/roster.rs
+++ b/filamento/src/roster.rs
@@ -1,6 +1,10 @@
use std::collections::HashSet;
use jid::JID;
+use rusqlite::{
+ ToSql,
+ types::{FromSql, ToSqlOutput, Value},
+};
pub struct ContactUpdate {
pub name: Option<String>,
@@ -35,6 +39,46 @@ pub enum Subscription {
// Remove,
}
+impl ToSql for Subscription {
+ fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
+ Ok(match self {
+ Subscription::None => ToSqlOutput::Owned(Value::Text("none".to_string())),
+ Subscription::PendingOut => ToSqlOutput::Owned(Value::Text("pending-out".to_string())),
+ Subscription::PendingIn => ToSqlOutput::Owned(Value::Text("pending-in".to_string())),
+ Subscription::PendingInPendingOut => {
+ ToSqlOutput::Owned(Value::Text("pending-in-pending-out".to_string()))
+ }
+ Subscription::OnlyOut => ToSqlOutput::Owned(Value::Text("only-out".to_string())),
+ Subscription::OnlyIn => ToSqlOutput::Owned(Value::Text("only-in".to_string())),
+ Subscription::OutPendingIn => {
+ ToSqlOutput::Owned(Value::Text("out-pending-in".to_string()))
+ }
+ Subscription::InPendingOut => {
+ ToSqlOutput::Owned(Value::Text("in-pending-out".to_string()))
+ }
+ Subscription::Buddy => ToSqlOutput::Owned(Value::Text("buddy".to_string())),
+ })
+ }
+}
+
+impl FromSql for Subscription {
+ fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
+ Ok(match value.as_str()? {
+ "none" => Self::None,
+ "pending-out" => Self::PendingOut,
+ "pending-in" => Self::PendingIn,
+ "pending-in-pending-out" => Self::PendingInPendingOut,
+ "only-out" => Self::OnlyOut,
+ "only-in" => Self::OnlyIn,
+ "out-pending-in" => Self::OutPendingIn,
+ "in-pending-out" => Self::InPendingOut,
+ "buddy" => Self::Buddy,
+ // TODO: don't have these lol
+ value => panic!("unexpected subscription `{value}`"),
+ })
+ }
+}
+
// none
// >
// >>