From 46e5887d1829cf9aade17aa6e716fcb39ff29878 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 2 Jan 2026 02:22:09 +0800 Subject: Add host mode and update sheet visibility model - Add `using_host_mode` field to LocalConfig with getter/setter - Replace `my_sheets`/`other_sheets` with `visible_sheets`/`invisible_sheets` - Add `reference_sheets` set for host-owned sheets - Add `shares_in_my_sheets` map to track external merge requests - Update `use_sheet` to check `visible_sheets` instead of `my_sheets` --- crates/vcs_data/src/data/local/config.rs | 17 ++++++++++++++++- crates/vcs_data/src/data/local/latest_info.rs | 22 ++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/vcs_data/src/data/local/config.rs b/crates/vcs_data/src/data/local/config.rs index 28bd439..cfbc0d4 100644 --- a/crates/vcs_data/src/data/local/config.rs +++ b/crates/vcs_data/src/data/local/config.rs @@ -32,6 +32,10 @@ pub struct LocalConfig { /// This ID will be used to verify access permissions when connecting to the upstream server. using_account: MemberId, + /// Whether the current member is interacting as a host. + /// In host mode, full Vault operation permissions are available except for adding new content. + using_host_mode: bool, + /// Whether the local workspace is stained. /// /// If stained, it can only set an upstream server with the same identifier. @@ -52,6 +56,7 @@ impl Default for LocalConfig { PORT, )), using_account: "unknown".to_string(), + using_host_mode: false, stained_uuid: None, sheet_in_use: None, } @@ -81,6 +86,11 @@ impl LocalConfig { Ok(()) } + /// Set the host mode + pub fn set_host_mode(&mut self, host_mode: bool) { + self.using_host_mode = host_mode; + } + /// Set the currently used sheet pub async fn use_sheet(&mut self, sheet: SheetName) -> Result<(), std::io::Error> { let sheet = snake_case!(sheet); @@ -110,7 +120,7 @@ impl LocalConfig { }; // Check if the sheet exists - if !latest_info.my_sheets.contains(&sheet) { + if !latest_info.visible_sheets.contains(&sheet) { return Err(std::io::Error::new( std::io::ErrorKind::NotFound, "Sheet not found", @@ -291,6 +301,11 @@ impl LocalConfig { self.using_account.clone() } + /// Check if the current member is interacting as a host. + pub fn is_host_mode(&self) -> bool { + self.using_host_mode + } + /// Check if the local workspace is stained. pub fn stained(&self) -> bool { self.stained_uuid.is_some() diff --git a/crates/vcs_data/src/data/local/latest_info.rs b/crates/vcs_data/src/data/local/latest_info.rs index ce45372..27409be 100644 --- a/crates/vcs_data/src/data/local/latest_info.rs +++ b/crates/vcs_data/src/data/local/latest_info.rs @@ -1,4 +1,5 @@ use std::{ + collections::{HashMap, HashSet}, path::{Path, PathBuf}, time::SystemTime, }; @@ -11,6 +12,7 @@ use crate::{ data::{ member::{Member, MemberId}, sheet::{SheetData, SheetName}, + vault::sheet_share::{Share, SheetShareId}, }, }; @@ -23,13 +25,25 @@ const ACCOUNT: &str = "{account}"; #[cfg_file(path = CLIENT_FILE_LATEST_INFO_NOSET)] pub struct LatestInfo { // Sheets - /// My sheets, indicating which sheets I can edit - pub my_sheets: Vec, - /// Other sheets, indicating which sheets I can export files to (these sheets are not readable to me) - pub other_sheets: Vec, + /// Visible sheets, + /// indicating which sheets I can edit + pub visible_sheets: Vec, + + /// Invisible sheets, + /// indicating which sheets I can export files to (these sheets are not readable to me) + pub invisible_sheets: Vec, + + /// Reference sheets, + /// indicating sheets owned by the host, visible to everyone, + /// but only the host can modify or add mappings within them + pub reference_sheets: HashSet, + /// Reference sheet data, indicating what files I can get from the reference sheet pub ref_sheet_content: SheetData, + /// Shares in my sheets, indicating which external merge requests have entries that I can view + pub shares_in_my_sheets: HashMap>, + /// Update instant pub update_instant: Option, -- cgit