kitgit

tirbofish/kitgit · commit

dbfb44e6710bccfc98906cb97f596756091e91a5

merge: feat/theme-toggle into integrate/all-features

Verified

Thribhu K <4tkbytes@pm.me> · 2026-07-28 23:38

view full diff

diff --git a/migrations/012_user_theme.sql b/migrations/012_user_theme.sql
new file mode 100644
index 0000000..7b57126
--- /dev/null
+++ b/migrations/012_user_theme.sql
@@ -0,0 +1,10 @@
+-- Per-user appearance preference: light | dark | system
+
+ALTER TABLE users
+    ADD COLUMN IF NOT EXISTS theme TEXT NOT NULL DEFAULT 'system';
+
+ALTER TABLE users
+    DROP CONSTRAINT IF EXISTS users_theme_check;
+
+ALTER TABLE users
+    ADD CONSTRAINT users_theme_check CHECK (theme IN ('light', 'dark', 'system'));
diff --git a/src/db/models.rs b/src/db/models.rs
index 441145f..6b0de67 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -17,10 +17,21 @@ pub struct User {
     pub is_suspended: bool,
     pub show_email: bool,
     pub vigilant_mode: bool,
+    /// `light`, `dark`, or `system` (follows prefers-color-scheme).
+    pub theme: String,
     pub created_at: DateTime<Utc>,
     pub updated_at: DateTime<Utc>,
 }
 
+impl User {
+    pub fn theme_pref(&self) -> &str {
+        match self.theme.as_str() {
+            "light" | "dark" => self.theme.as_str(),
+            _ => "system",
+        }
+    }
+}
+
 #[derive(Debug, Clone, FromRow)]
 pub struct UserMfa {
     pub user_id: Uuid,
diff --git a/src/db/queries.rs b/src/db/queries.rs
index 7a47198..c1f7898 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -2003,6 +2003,19 @@ pub async fn update_privacy(
     .await?)
 }
 

Large diffs are not rendered by default. Showing the first 50 of 317 lines. Show full diff