Personal iOS fork of Witchsky (itself a fork of Bluesky social-app).
tigerfly docs offline-drafts.md
7.9 kB · 183 lines
Markdown
at main

Offline draft persistence #

Status: Design note; implementation intentionally deferred.

Problem #

Post drafts are currently server-first. Saving calls the Bluesky draft service, and draft media is copied into local storage only after that request succeeds. In airplane mode, the composer shows “Failed to save draft” and keeps the current text only in memory. Force-quitting the app can lose it.

Message drafts are also memory-only. They survive navigation during the current process but not an app restart.

The persisted query cache may make previously fetched server drafts visible offline, but it is not a durable source of truth for unsynced user input.

Product intent #

Offline post drafts #

As a signed-in Tigerfly user I want to save and edit post drafts without an internet connection So that I do not lose work while traveling or temporarily offline.

Offline message drafts #

As a signed-in Tigerfly user I want unfinished messages to survive navigation and app restarts So that I can continue writing them when I return.

Desired experience #

  • Saving while offline succeeds locally and reports “Saved on this device.”
  • Locally saved drafts appear alongside server drafts and remain editable while offline.
  • Text, threads, replies, quotes, labels, language settings, interaction settings, and supported media are retained.
  • Drafts survive force-quit, device restart, and an app update.
  • When connectivity returns, local post drafts sync to the existing Bluesky draft service.
  • A draft remains locally available until the server confirms the corresponding create, update, or delete operation.
  • Failed synchronization is non-destructive and visibly retryable.
  • A successfully published post removes its corresponding local and server draft state.
  • Message drafts persist per account and conversation and are cleared after a successful send.

Acceptance criteria #

Offline post drafts #

Scenario: Saving a new draft offline #

  • Given the user is signed in and has no internet connection
  • And the composer contains valid draft content
  • When the user saves the draft
  • Then the user is told that the draft was saved on this device
  • And the draft appears in their drafts
  • And the composer may be closed without losing the draft

Scenario: Restoring after an app restart #

  • Given the user saved a post draft while offline
  • When the user reopens Tigerfly without an internet connection
  • Then the saved draft appears in their drafts
  • And reopening it restores its text, settings, and locally available media

Scenario: Synchronizing after reconnection #

  • Given the user has a locally saved post draft
  • When Tigerfly regains a working connection
  • Then the draft becomes available through the user’s server-backed drafts
  • And the local draft remains available until synchronization succeeds
  • And the user is not given duplicate drafts after synchronization

Scenario: Synchronization fails #

  • Given the user has a locally saved post draft
  • When synchronization cannot be completed
  • Then the draft remains locally available and editable
  • And the user can retry synchronization later
  • And no draft content or media is deleted

Scenario: Editing a server draft while offline #

  • Given a previously loaded server draft is available offline
  • When the user edits and saves it without an internet connection
  • Then the edits are retained locally
  • And the original server draft is not overwritten until connectivity returns and conflict checks succeed

Scenario: Publishing a saved draft #

  • Given a local or synchronized draft is open
  • When the post is published successfully
  • Then it no longer appears in the user’s drafts
  • And its unreferenced local media is removed

Offline message drafts #

Scenario: Restoring an unfinished message #

  • Given the user has written but not sent a message
  • When the user leaves the conversation and later returns, including after restarting Tigerfly
  • Then the unfinished message is restored in the same conversation

Scenario: Clearing a sent message draft #

  • Given an unfinished message has been restored
  • When the message is sent successfully
  • Then the saved message draft is removed

Technical direction #

Durable local source of truth #

Use an account-scoped local draft repository rather than React Query persistence as the source of truth. Store draft metadata and serialized draft content in durable key-value storage. Store media in the existing draft media directory.

A local post-draft record should retain:

  • A stable local identifier.
  • The account DID.
  • The complete draft payload required to reconstruct the composer.
  • An optional server draft identifier and the server revision observed before offline editing.
  • Creation and modification timestamps.
  • Referenced local media paths.
  • Synchronization state and the latest synchronization error, without storing credentials.

Message drafts need a smaller account-and-conversation-scoped record containing the text and modification time.

Save ordering #

For an offline-capable save:

  1. Validate the draft.
  2. Copy new media into durable local storage.
  3. Atomically write the local draft record.
  4. Report local success and allow the composer to close.
  5. Attempt server synchronization only when connectivity is available.

If the local write fails, keep the composer open and report that the draft was not saved. Do not acknowledge success before both metadata and required media are durable.

Draft list #

Merge local records with fetched server drafts:

  • A synchronized local record and its matching server draft render as one draft.
  • A local-only record renders with an offline or pending-sync status.
  • A failed record remains visible with a retry action.
  • Server drafts not represented locally continue to render normally.
  • The query cache may accelerate startup, but local records determine whether unsynced work exists.

Synchronization #

Run synchronization after confirmed reconnection and when the app becomes active:

  • Create server drafts for local-only records.
  • Update server drafts for locally edited records.
  • Apply deletions only after preserving enough state to retry safely.
  • Make each operation idempotent so repeated reconnect events cannot create duplicates.
  • Remove local synchronization metadata only after the server response is committed locally.

Conflicts #

Before updating a server draft edited offline, compare it with the server revision observed when editing began. If the server copy changed elsewhere, preserve both versions rather than silently overwriting either one. Present the local copy as a recoverable conflict that the user can review or save as a separate draft.

Account lifecycle and privacy #

  • Isolate all draft records and media by account DID.
  • Never place tokens or credentials in draft storage.
  • Remove local records and media when the user explicitly removes an account.
  • Before ordinary sign-out, avoid silently deleting unsynced work. Either retain it for that account or warn the user and offer a deliberate deletion choice.
  • Garbage-collect media only when no local draft references it.

Existing implementation touchpoints #

  • src/view/com/composer/Composer.tsx
  • src/view/com/composer/drafts/state/queries.ts
  • src/view/com/composer/drafts/state/api.ts
  • src/view/com/composer/drafts/state/schema.ts
  • src/view/com/composer/drafts/state/storage.ts
  • src/view/com/composer/drafts/state/storage.web.ts
  • src/state/messages/message-drafts.tsx
  • src/state/session/index.tsx
  • src/lib/react-query.tsx

Non-goals #

  • Publishing posts while offline.
  • Sending messages while offline.
  • Treating the React Query cache as durable draft storage.
  • Uploading media before the user has asked to synchronize or publish.
  • Silently resolving multi-device draft conflicts by overwriting one version.