mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 19:25:00 +03:00
Match the 0.27.5 mobile detail page: - Open each document in its primary mode. The DocActions sheet starts with the Page | Edgeless view switch and adds Default to Edgeless mode and Default to Page mode, which write primaryMode to db$docProperties. - Show the Read only / Editing toggle in the header of an editable page in Page mode. The toggle gates Page edits in the embedded editor. - Add View table of contents. The sheet lists the title and the H1-H6 headings, marks the heading at the reading position, and scrolls the editor to the tapped entry. - When a date has more than one journal, add the journal conflict list to the page menu and to the Journals tab. A tap opens a journal. Its operations remove the journal mark or move the journal to trash after the Delete doc? confirmation. - Scroll each sheet over its measured content height instead of a fixed 360 px range, so a long outline reaches its last heading.
143 lines
5.3 KiB
Rust
143 lines
5.3 KiB
Rust
//! Permanent deletes made outside the shell (another session on the same SQLite workspace)
|
|
//! leave the mobile projection, the CRDT cache, and the open page, while shell-only drafts and
|
|
//! same-ID documents of other workspaces stay.
|
|
|
|
#![cfg(not(target_family = "wasm"))]
|
|
|
|
use affine_client::{EditorDocMode, HostKind, SqliteWorkspaceStore, WorkspaceSession};
|
|
use affine_mobile::{
|
|
MobileDocRecord, MobileLocale, MobileRoute, MobileWorkspaceBridge, seed_showcase_state,
|
|
};
|
|
use ui_tokens::ThemeMode;
|
|
|
|
const SERVER: &str = "affine-cloud";
|
|
const WS_ID: &str = "ws-remote-delete";
|
|
|
|
async fn load_session(store: &SqliteWorkspaceStore, client: u64, now: i64) -> WorkspaceSession {
|
|
store
|
|
.load_workspace_session(
|
|
"u-remote-delete",
|
|
client,
|
|
HostKind::Native,
|
|
SERVER,
|
|
"https://app.affine.pro",
|
|
now,
|
|
)
|
|
.await
|
|
.unwrap()
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn remote_permanent_delete_clears_projection_cache_and_open_page() {
|
|
for docs in [10usize, 100, 1_000] {
|
|
let base_dir = std::env::temp_dir().join(format!(
|
|
"affine-mobile-remote-delete-{docs}-{}",
|
|
std::process::id()
|
|
));
|
|
let _ = std::fs::remove_dir_all(&base_dir);
|
|
let store = SqliteWorkspaceStore::open(&base_dir, "workspace", SERVER, WS_ID)
|
|
.await
|
|
.unwrap();
|
|
let mut bridge = MobileWorkspaceBridge::new(load_session(&store, 7101, 1_000).await);
|
|
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-12-01");
|
|
bridge.sync_into_state(&mut state, 1_000);
|
|
|
|
let mut ids = Vec::with_capacity(docs);
|
|
for i in 0..docs {
|
|
let (summary, pending) = bridge
|
|
.session_mut()
|
|
.create_document(
|
|
&format!("Doc {i:04}"),
|
|
EditorDocMode::Page,
|
|
None,
|
|
1_100 + i as i64,
|
|
)
|
|
.unwrap();
|
|
bridge
|
|
.session_mut()
|
|
.enqueue_pending_persist_updates(pending);
|
|
ids.push(summary.id.as_str().to_string());
|
|
}
|
|
bridge.sync_into_state(&mut state, 3_000);
|
|
assert_eq!(state.active_workspace().docs().len(), docs);
|
|
|
|
// A shell-only draft that never reached the session, and a same-ID document in the
|
|
// other workspace slice.
|
|
let draft = state.create_doc(None, 3_100.0);
|
|
let victim = ids[docs / 2].clone();
|
|
state.workspace_store[1].docs_mut().push(MobileDocRecord {
|
|
id: victim.clone(),
|
|
title: "Same ID elsewhere".into(),
|
|
body_preview: String::new(),
|
|
tags: Vec::new(),
|
|
updated_at_ms: 1,
|
|
is_favorite: false,
|
|
trashed: false,
|
|
journal_date: None,
|
|
primary_mode: affine_mobile::state::DocMode::Page,
|
|
clock: 1,
|
|
outgoing_edges: Vec::new(),
|
|
blocks: Vec::new(),
|
|
});
|
|
bridge.open_document(&mut state, &victim, 3_200).unwrap();
|
|
assert_eq!(state.route, MobileRoute::Page(victim.clone()));
|
|
assert!(
|
|
state
|
|
.active_workspace()
|
|
.doc_crdt_updates()
|
|
.contains_key(&victim)
|
|
);
|
|
bridge
|
|
.flush_session_mutations(&state, &store, 3_300)
|
|
.await
|
|
.unwrap();
|
|
|
|
// Another session path trashes and permanently deletes the open document.
|
|
bridge.session_mut().trash_document(&victim, 4_000).unwrap();
|
|
assert!(
|
|
bridge
|
|
.session_mut()
|
|
.delete_document_permanently(&victim, 4_010)
|
|
.unwrap()
|
|
);
|
|
assert!(bridge.sync_into_state(&mut state, 4_100), "{docs} docs");
|
|
|
|
let ws = state.active_workspace();
|
|
assert!(ws.doc(&victim).is_none(), "{docs} docs: projection kept");
|
|
assert!(
|
|
!ws.doc_crdt_updates().contains_key(&victim),
|
|
"{docs} docs: CRDT cache kept"
|
|
);
|
|
assert_eq!(ws.docs().len(), docs, "{docs} docs: draft or others lost");
|
|
assert!(ws.doc(&draft).is_some(), "{docs} docs: draft lost");
|
|
assert_eq!(state.route, MobileRoute::Page(draft.clone()));
|
|
assert!(
|
|
state.workspace_store[1]
|
|
.docs()
|
|
.iter()
|
|
.any(|d| d.id == victim),
|
|
"{docs} docs: same ID in another workspace removed"
|
|
);
|
|
|
|
// A second sync and a flushed reopen do not bring the document back.
|
|
assert!(!bridge.sync_into_state(&mut state, 4_200));
|
|
assert!(state.doc_by_id(&victim).is_none());
|
|
bridge
|
|
.flush_session_mutations(&state, &store, 4_300)
|
|
.await
|
|
.unwrap();
|
|
store.close().await;
|
|
|
|
let store = SqliteWorkspaceStore::open(&base_dir, "workspace", SERVER, WS_ID)
|
|
.await
|
|
.unwrap();
|
|
let mut bridge = MobileWorkspaceBridge::new(load_session(&store, 7102, 5_000).await);
|
|
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-12-01");
|
|
bridge.sync_into_state(&mut state, 5_000);
|
|
assert!(state.doc_by_id(&victim).is_none(), "{docs} docs: revived");
|
|
assert_eq!(state.active_workspace().docs().len(), docs - 1);
|
|
store.close().await;
|
|
let _ = std::fs::remove_dir_all(&base_dir);
|
|
}
|
|
}
|