onechatsocial-database 0.6.21

Revolt Backend: Database Implementation
Documentation
use std::collections::HashMap;

use crate::{events::client::EventV1, Database};

use onechatsocial_result::Result;

pub type UserSettings = HashMap<String, (i64, String)>;

#[async_trait]
pub trait UserSettingsImpl {
    async fn set(self, db: &Database, user: &str) -> Result<()>;
}

#[async_trait]
impl UserSettingsImpl for UserSettings {
    async fn set(self, db: &Database, user: &str) -> Result<()> {
        db.set_user_settings(user, &self).await?;

        EventV1::UserSettingsUpdate {
            id: user.to_string(),
            update: self,
        }
        .private(user.to_string())
        .await;

        Ok(())
    }
}