core, web: pin, archive and reorder a note someone shared with you

Schema v12 adds notes.state_at: a recipient's own pin, archive and order are
stamped there instead of on updated_at, which stays the text's time. Push sends
them only to a server advertising `shared_state` (push::Accepts), a view share
included; the first pull at that level starts the feed over once so held copies
drop their owner's pins. The client speaks protocol 7 and lists `shares` and
`shared_state` among the features a server may lack.

The web card and editor offer pin, archive and drag on shared notes; share and
trash stay the owner's, and the board's trash key skips notes you don't own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 17:13:58 -04:00
co-authored by Claude Opus 5.5
parent 63955bbe97
commit 89cd1c76bb
9 changed files with 304 additions and 91 deletions
+32 -12
View File
@@ -115,17 +115,27 @@ fn forget_shared_notes(conn: &Connection) -> rusqlite::Result<()> {
Ok(())
}
/// Start the change feed over the first time this device pulls with shares (#5175).
/// How much of sharing this device's copy of the feed reflects, kept in
/// `sync_state.shares_synced`. Each level changed what the feed says about notes a
/// device may already hold, below the cursor it already has.
///
/// Notes shared before this build sit below the cursor the device already holds, so
/// without a restart they would only arrive once something next changed them.
/// Returns whether it restarted. Once per link: `set_link` to another server and
/// `clear_link` both reset the flag.
pub fn begin_shares(conn: &Connection) -> rusqlite::Result<bool> {
/// Shared notes arrive at all (#5175).
pub const SHARES: i64 = 1;
/// A shared note's pin, archive and position are this account's own (#5176). Before,
/// the feed sent the owner's, and a device holding those would keep showing them
/// until something next changed the note.
pub const SHARED_STATE: i64 = 2;
/// Start the change feed over the first time this device pulls at a sharing `level`
/// the server offers, so what it already holds is re-read in that level's terms.
///
/// Returns whether it restarted. Once per level per link: `set_link` to another
/// server and `clear_link` both go back to none.
pub fn begin_shares(conn: &Connection, level: i64) -> rusqlite::Result<bool> {
let restarted = conn.execute(
"UPDATE sync_state SET last_cursor = NULL, shares_synced = 1
WHERE id = 1 AND shares_synced = 0",
[],
"UPDATE sync_state SET last_cursor = NULL, shares_synced = ?1
WHERE id = 1 AND shares_synced < ?1",
params![level],
)?;
Ok(restarted > 0)
}
@@ -342,14 +352,24 @@ mod tests {
let conn = db();
set_link(&conn, "https://a.example.com", "tok-1").expect("link");
set_cursor(&conn, 500).expect("cursor");
assert!(begin_shares(&conn).expect("begin"));
assert!(begin_shares(&conn, SHARES).expect("begin"));
assert_eq!(read(&conn).expect("read").last_cursor, 0);
set_cursor(&conn, 600).expect("cursor");
assert!(!begin_shares(&conn).expect("again"), "only the first time");
assert!(
!begin_shares(&conn, SHARES).expect("again"),
"only the first time"
);
assert_eq!(read(&conn).expect("read").last_cursor, 600);
// A server offering more of sharing starts it over once more, and only once.
assert!(begin_shares(&conn, SHARED_STATE).expect("a newer server"));
assert_eq!(read(&conn).expect("read").last_cursor, 0);
set_cursor(&conn, 700).expect("cursor");
assert!(!begin_shares(&conn, SHARED_STATE).expect("again"));
assert!(!begin_shares(&conn, SHARES).expect("an older level"));
assert_eq!(read(&conn).expect("read").last_cursor, 700);
// Another server is a fresh start, shares included.
set_link(&conn, "https://b.example.com", "tok-2").expect("relink");
assert!(begin_shares(&conn).expect("new server"));
assert!(begin_shares(&conn, SHARES).expect("new server"));
}
#[test]