AppFlowy/frontend/rust-lib/flowy-user/src/entities/user_setting.rs

247 lines
5.5 KiB
Rust
Raw Normal View History

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use crate::entities::EncryptionTypePB;
2022-01-28 02:56:55 +00:00
2023-10-02 07:12:24 +00:00
use super::date_time::{UserDateFormatPB, UserTimeFormatPB};
2022-01-28 02:56:55 +00:00
#[derive(ProtoBuf, Default, Debug, Clone)]
2022-07-19 06:40:56 +00:00
pub struct UserPreferencesPB {
#[pb(index = 1)]
user_id: String,
2022-01-28 02:56:55 +00:00
#[pb(index = 2)]
appearance_setting: AppearanceSettingsPB,
2023-10-02 07:12:24 +00:00
#[pb(index = 3)]
date_time_settings: DateTimeSettingsPB,
2022-01-28 02:56:55 +00:00
}
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
2022-07-19 06:40:56 +00:00
pub struct AppearanceSettingsPB {
#[pb(index = 1)]
pub theme: String,
2022-01-28 02:56:55 +00:00
#[pb(index = 2)]
#[serde(default)]
pub theme_mode: ThemeModePB,
#[pb(index = 3)]
pub font: String,
#[pb(index = 4)]
pub monospace_font: String,
#[pb(index = 5)]
#[serde(default)]
pub locale: LocaleSettingsPB,
2022-02-01 04:15:11 +00:00
#[pb(index = 6)]
#[serde(default = "DEFAULT_RESET_VALUE")]
pub reset_to_default: bool,
#[pb(index = 7)]
#[serde(default)]
pub setting_key_value: HashMap<String, String>,
#[pb(index = 8)]
#[serde(default)]
pub is_menu_collapsed: bool,
#[pb(index = 9)]
#[serde(default)]
pub menu_offset: f64,
#[pb(index = 10)]
#[serde(default)]
pub layout_direction: LayoutDirectionPB,
// If the value is FALLBACK which is the default value then it will fall back
// to layout direction and it will use that as default text direction.
#[pb(index = 11)]
#[serde(default)]
pub text_direction: TextDirectionPB,
2022-02-01 04:15:11 +00:00
}
2022-06-27 12:53:47 +00:00
const DEFAULT_RESET_VALUE: fn() -> bool = || APPEARANCE_RESET_AS_DEFAULT;
#[derive(ProtoBuf_Enum, Serialize, Deserialize, Clone, Debug, Default)]
pub enum ThemeModePB {
Light = 0,
Dark = 1,
#[default]
System = 2,
}
#[derive(ProtoBuf_Enum, Serialize, Deserialize, Clone, Debug, Default)]
pub enum LayoutDirectionPB {
#[default]
LTRLayout = 0,
RTLLayout = 1,
}
#[derive(ProtoBuf_Enum, Serialize, Deserialize, Clone, Debug, Default)]
pub enum TextDirectionPB {
LTR = 0,
RTL = 1,
AUTO = 2,
#[default]
FALLBACK = 3,
}
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
2022-07-19 06:40:56 +00:00
pub struct LocaleSettingsPB {
#[pb(index = 1)]
pub language_code: String,
#[pb(index = 2)]
pub country_code: String,
}
2022-07-19 06:40:56 +00:00
impl std::default::Default for LocaleSettingsPB {
fn default() -> Self {
Self {
language_code: "en".to_owned(),
country_code: "".to_owned(),
}
}
}
2023-10-02 07:12:24 +00:00
pub const APPEARANCE_DEFAULT_THEME: &str = "Default";
pub const APPEARANCE_DEFAULT_FONT: &str = "Poppins";
pub const APPEARANCE_DEFAULT_MONOSPACE_FONT: &str = "SF Mono";
2022-06-27 12:53:47 +00:00
const APPEARANCE_RESET_AS_DEFAULT: bool = true;
const APPEARANCE_DEFAULT_IS_MENU_COLLAPSED: bool = false;
const APPEARANCE_DEFAULT_MENU_OFFSET: f64 = 0.0;
2022-01-28 02:56:55 +00:00
2022-07-19 06:40:56 +00:00
impl std::default::Default for AppearanceSettingsPB {
fn default() -> Self {
AppearanceSettingsPB {
theme: APPEARANCE_DEFAULT_THEME.to_owned(),
theme_mode: ThemeModePB::default(),
font: APPEARANCE_DEFAULT_FONT.to_owned(),
monospace_font: APPEARANCE_DEFAULT_MONOSPACE_FONT.to_owned(),
locale: LocaleSettingsPB::default(),
reset_to_default: APPEARANCE_RESET_AS_DEFAULT,
setting_key_value: HashMap::default(),
is_menu_collapsed: APPEARANCE_DEFAULT_IS_MENU_COLLAPSED,
menu_offset: APPEARANCE_DEFAULT_MENU_OFFSET,
layout_direction: LayoutDirectionPB::default(),
text_direction: TextDirectionPB::default(),
2022-01-28 02:56:55 +00:00
}
}
2022-01-28 02:56:55 +00:00
}
#[derive(Default, ProtoBuf)]
pub struct CloudSettingPB {
#[pb(index = 1)]
pub(crate) enable_sync: bool,
#[pb(index = 2)]
pub(crate) enable_encrypt: bool,
#[pb(index = 3)]
pub encrypt_secret: String,
#[pb(index = 4)]
pub server_url: String,
}
#[derive(Default, ProtoBuf)]
pub struct UpdateCloudConfigPB {
#[pb(index = 1, one_of)]
pub enable_sync: Option<bool>,
#[pb(index = 2, one_of)]
pub enable_encrypt: Option<bool>,
}
#[derive(Default, ProtoBuf)]
pub struct UserSecretPB {
#[pb(index = 1)]
pub user_id: i64,
#[pb(index = 2)]
pub encryption_secret: String,
#[pb(index = 3)]
pub encryption_type: EncryptionTypePB,
#[pb(index = 4)]
pub encryption_sign: String,
}
#[derive(Default, ProtoBuf)]
pub struct UserEncryptionConfigurationPB {
#[pb(index = 1)]
pub require_secret: bool,
}
feat: migrate user data to cloud (#3078) * refactor: weak passed-in params in handler * refactor: rename struct * chore: update tables * chore: update schema * chore: add permission * chore: update tables * chore: support transaction mode * chore: workspace database id * chore: add user workspace * feat: return list of workspaces * chore: add user to workspace * feat: separate database row table * refactor: update schema * chore: partition table * chore: use transaction * refactor: dir * refactor: collab db ref * fix: collab db lock * chore: rename files * chore: add tables descriptions * chore: update readme * docs: update documentation * chore: rename crate * chore: update ref * chore: update tests * chore: update tests * refactor: crate deps * chore: update crate ref * chore: remove unused deps * chore: remove unused deps * chore: update collab crate refs * chore: replace client with transaction in pooler * refactor: return error type * refactor: use anyhow error in deps * feat: supabase postgrest user signin (wip) * fix: Cargo.toml source git deps, changed Error to anyhow::Error * fix: uuid serialization * chore: fix conflict * chore: extend the response * feat: add implementation place holders * feat: impl get_user_workspaces * feat: impl get_user_profile * test: create workspace * fix: postgrest: field names and alias * chore: implement folder restful api * chore: implement collab storate with restful api * feat: added placeholders for impl: update_user_profile, check_user * feat: impl: update_user_profile * feat: impl: check_user * fix: use UidResponse, add more debug info for serde serialization error * fix: get_user_profile: use Optional<UserProfileResponse> * chore: imple init sync * chore: support soft delete * feat: postgresql: add migration test * feat: postgresql migration test: added UID display and colored output * feat: postgresql migration test: workspace role * feat: postgresql migration test: create shared common utils * feat: postgresql migration test: fixed shebang * chore: add flush_collab_update pg function * chore: implement datbaase and document restful api * chore: migrate to use restful api * chore: update table schema * chore: fix tests * chore: remove unused code * chore: format code * chore: remove unused env * fix: tauri build * fix: tauri build --------- Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg>
2023-07-29 01:46:24 +00:00
#[derive(ProtoBuf_Enum, Debug, Clone, Eq, PartialEq, Default)]
pub enum NetworkTypePB {
#[default]
NetworkUnknown = 0,
Wifi = 1,
Cell = 2,
Ethernet = 3,
Bluetooth = 4,
VPN = 5,
}
feat: migrate user data to cloud (#3078) * refactor: weak passed-in params in handler * refactor: rename struct * chore: update tables * chore: update schema * chore: add permission * chore: update tables * chore: support transaction mode * chore: workspace database id * chore: add user workspace * feat: return list of workspaces * chore: add user to workspace * feat: separate database row table * refactor: update schema * chore: partition table * chore: use transaction * refactor: dir * refactor: collab db ref * fix: collab db lock * chore: rename files * chore: add tables descriptions * chore: update readme * docs: update documentation * chore: rename crate * chore: update ref * chore: update tests * chore: update tests * refactor: crate deps * chore: update crate ref * chore: remove unused deps * chore: remove unused deps * chore: update collab crate refs * chore: replace client with transaction in pooler * refactor: return error type * refactor: use anyhow error in deps * feat: supabase postgrest user signin (wip) * fix: Cargo.toml source git deps, changed Error to anyhow::Error * fix: uuid serialization * chore: fix conflict * chore: extend the response * feat: add implementation place holders * feat: impl get_user_workspaces * feat: impl get_user_profile * test: create workspace * fix: postgrest: field names and alias * chore: implement folder restful api * chore: implement collab storate with restful api * feat: added placeholders for impl: update_user_profile, check_user * feat: impl: update_user_profile * feat: impl: check_user * fix: use UidResponse, add more debug info for serde serialization error * fix: get_user_profile: use Optional<UserProfileResponse> * chore: imple init sync * chore: support soft delete * feat: postgresql: add migration test * feat: postgresql migration test: added UID display and colored output * feat: postgresql migration test: workspace role * feat: postgresql migration test: create shared common utils * feat: postgresql migration test: fixed shebang * chore: add flush_collab_update pg function * chore: implement datbaase and document restful api * chore: migrate to use restful api * chore: update table schema * chore: fix tests * chore: remove unused code * chore: format code * chore: remove unused env * fix: tauri build * fix: tauri build --------- Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg>
2023-07-29 01:46:24 +00:00
impl NetworkTypePB {
pub fn is_reachable(&self) -> bool {
match self {
NetworkTypePB::NetworkUnknown | NetworkTypePB::Bluetooth => false,
NetworkTypePB::Wifi | NetworkTypePB::Cell | NetworkTypePB::Ethernet | NetworkTypePB::VPN => {
true
},
}
}
}
feat: migrate user data to cloud (#3078) * refactor: weak passed-in params in handler * refactor: rename struct * chore: update tables * chore: update schema * chore: add permission * chore: update tables * chore: support transaction mode * chore: workspace database id * chore: add user workspace * feat: return list of workspaces * chore: add user to workspace * feat: separate database row table * refactor: update schema * chore: partition table * chore: use transaction * refactor: dir * refactor: collab db ref * fix: collab db lock * chore: rename files * chore: add tables descriptions * chore: update readme * docs: update documentation * chore: rename crate * chore: update ref * chore: update tests * chore: update tests * refactor: crate deps * chore: update crate ref * chore: remove unused deps * chore: remove unused deps * chore: update collab crate refs * chore: replace client with transaction in pooler * refactor: return error type * refactor: use anyhow error in deps * feat: supabase postgrest user signin (wip) * fix: Cargo.toml source git deps, changed Error to anyhow::Error * fix: uuid serialization * chore: fix conflict * chore: extend the response * feat: add implementation place holders * feat: impl get_user_workspaces * feat: impl get_user_profile * test: create workspace * fix: postgrest: field names and alias * chore: implement folder restful api * chore: implement collab storate with restful api * feat: added placeholders for impl: update_user_profile, check_user * feat: impl: update_user_profile * feat: impl: check_user * fix: use UidResponse, add more debug info for serde serialization error * fix: get_user_profile: use Optional<UserProfileResponse> * chore: imple init sync * chore: support soft delete * feat: postgresql: add migration test * feat: postgresql migration test: added UID display and colored output * feat: postgresql migration test: workspace role * feat: postgresql migration test: create shared common utils * feat: postgresql migration test: fixed shebang * chore: add flush_collab_update pg function * chore: implement datbaase and document restful api * chore: migrate to use restful api * chore: update table schema * chore: fix tests * chore: remove unused code * chore: format code * chore: remove unused env * fix: tauri build * fix: tauri build --------- Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg>
2023-07-29 01:46:24 +00:00
#[derive(ProtoBuf, Debug, Default, Clone)]
pub struct NetworkStatePB {
#[pb(index = 1)]
pub ty: NetworkTypePB,
}
2023-10-02 07:12:24 +00:00
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
pub struct DateTimeSettingsPB {
#[pb(index = 1)]
pub date_format: UserDateFormatPB,
#[pb(index = 2)]
pub time_format: UserTimeFormatPB,
#[pb(index = 3)]
pub timezone_id: String,
}
impl std::default::Default for DateTimeSettingsPB {
fn default() -> Self {
DateTimeSettingsPB {
date_format: UserDateFormatPB::Friendly,
time_format: UserTimeFormatPB::TwentyFourHour,
timezone_id: "".to_owned(),
}
}
}
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
pub struct NotificationSettingsPB {
#[pb(index = 1)]
#[serde(default)]
pub notifications_enabled: bool,
}
impl std::default::Default for NotificationSettingsPB {
fn default() -> Self {
NotificationSettingsPB {
notifications_enabled: true,
}
}
}