mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
61fd608200
* refactor: rename structs * chore: read database id from view * chore: fix open database error because of create a database view for database id * chore: fix tests * chore: rename datbase id to view id in flutter * refactor: move grid and board to database view folder * refactor: rename functions * refactor: move calender to datbase view folder * refactor: rename app_flowy to appflowy_flutter * chore: reanming * chore: fix freeze gen * chore: remove todos * refactor: view process events * chore: add link database test * chore: just open view if there is opened database
92 lines
2.9 KiB
Rust
92 lines
2.9 KiB
Rust
use crate::entities::{
|
|
AppearanceSettingsPB, UpdateUserProfilePayloadPB, UserProfilePB, UserSettingPB,
|
|
APPEARANCE_DEFAULT_THEME,
|
|
};
|
|
use crate::{errors::FlowyError, services::UserSession};
|
|
use flowy_sqlite::kv::KV;
|
|
use lib_dispatch::prelude::*;
|
|
use std::{convert::TryInto, sync::Arc};
|
|
use user_model::UpdateUserProfileParams;
|
|
|
|
#[tracing::instrument(level = "debug", skip(session))]
|
|
pub async fn init_user_handler(session: AFPluginState<Arc<UserSession>>) -> Result<(), FlowyError> {
|
|
session.init_user().await?;
|
|
Ok(())
|
|
}
|
|
|
|
#[tracing::instrument(level = "debug", skip(session))]
|
|
pub async fn check_user_handler(
|
|
session: AFPluginState<Arc<UserSession>>,
|
|
) -> DataResult<UserProfilePB, FlowyError> {
|
|
let user_profile: UserProfilePB = session.check_user().await?.into();
|
|
data_result_ok(user_profile)
|
|
}
|
|
|
|
#[tracing::instrument(level = "debug", skip(session))]
|
|
pub async fn get_user_profile_handler(
|
|
session: AFPluginState<Arc<UserSession>>,
|
|
) -> DataResult<UserProfilePB, FlowyError> {
|
|
let user_profile: UserProfilePB = session.get_user_profile().await?.into();
|
|
data_result_ok(user_profile)
|
|
}
|
|
|
|
#[tracing::instrument(level = "debug", name = "sign_out", skip(session))]
|
|
pub async fn sign_out(session: AFPluginState<Arc<UserSession>>) -> Result<(), FlowyError> {
|
|
session.sign_out().await?;
|
|
Ok(())
|
|
}
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, session))]
|
|
pub async fn update_user_profile_handler(
|
|
data: AFPluginData<UpdateUserProfilePayloadPB>,
|
|
session: AFPluginState<Arc<UserSession>>,
|
|
) -> Result<(), FlowyError> {
|
|
let params: UpdateUserProfileParams = data.into_inner().try_into()?;
|
|
session.update_user_profile(params).await?;
|
|
Ok(())
|
|
}
|
|
|
|
const APPEARANCE_SETTING_CACHE_KEY: &str = "appearance_settings";
|
|
|
|
#[tracing::instrument(level = "debug", skip(data), err)]
|
|
pub async fn set_appearance_setting(
|
|
data: AFPluginData<AppearanceSettingsPB>,
|
|
) -> Result<(), FlowyError> {
|
|
let mut setting = data.into_inner();
|
|
if setting.theme.is_empty() {
|
|
setting.theme = APPEARANCE_DEFAULT_THEME.to_string();
|
|
}
|
|
|
|
let s = serde_json::to_string(&setting)?;
|
|
KV::set_str(APPEARANCE_SETTING_CACHE_KEY, s);
|
|
Ok(())
|
|
}
|
|
|
|
#[tracing::instrument(level = "debug", err)]
|
|
pub async fn get_appearance_setting() -> DataResult<AppearanceSettingsPB, FlowyError> {
|
|
match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) {
|
|
None => data_result_ok(AppearanceSettingsPB::default()),
|
|
Some(s) => {
|
|
let setting = match serde_json::from_str(&s) {
|
|
Ok(setting) => setting,
|
|
Err(e) => {
|
|
tracing::error!(
|
|
"Deserialize AppearanceSettings failed: {:?}, fallback to default",
|
|
e
|
|
);
|
|
AppearanceSettingsPB::default()
|
|
},
|
|
};
|
|
data_result_ok(setting)
|
|
},
|
|
}
|
|
}
|
|
|
|
#[tracing::instrument(level = "debug", skip_all, err)]
|
|
pub async fn get_user_setting(
|
|
session: AFPluginState<Arc<UserSession>>,
|
|
) -> DataResult<UserSettingPB, FlowyError> {
|
|
let user_setting = session.user_setting()?;
|
|
data_result_ok(user_setting)
|
|
}
|