feat(desktop): sync channel sections across devices via Nostr#792
Open
wpfleger96 wants to merge 3 commits into
Open
feat(desktop): sync channel sections across devices via Nostr#792wpfleger96 wants to merge 3 commits into
wpfleger96 wants to merge 3 commits into
Conversation
18ae736 to
6fdfbd5
Compare
881b951 to
f081fbf
Compare
Channel sections were localStorage-only, meaning they didn't sync across devices. Adds a NIP-78 (kind 30078) event-based sync layer so sections created, renamed, deleted, or reordered on any device propagate to all others. localStorage is retained as a local cache for instant rendering on startup.
Cancel stale debounce when applying remote updates to prevent publishing overwritten state. Track pending publishes for retry on reconnect. Add pubkey validation before decrypting relay events. Extract applyRemote reconcile helper and swapSectionOrder to eliminate duplication. Fix createSection to construct section before setStore so return value is deterministic. Add NIP-01 event ID tie-breaking. Wire resetSyncState into resetWorkspaceState.
Extract swapSectionOrder to channelSectionsHelpers.ts for testability. 27 tests covering parseChannelSectionPayload validation, stripOrphanedAssignments identity semantics, localStorage round-trip, and swapSectionOrder boundary conditions.
02d06b9 to
2b5e69e
Compare
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Stacked on #789 (must merge first). #789 adds the channel sections UI with localStorage persistence; this PR adds Nostr event sync so sections propagate across devices.
Summary
channelSectionsSync.tsmodule encapsulating all relay interaction: fetch, publish (debounced ~2s), live subscription, and NIP-44 encrypt/decrypt. Uses kind 30078 (NIP-78 app-specific data) withd-tag"channel-sections", same pattern asReadStateManageruseChannelSections.tsto fetch from relay on mount, reconcile with localStorage (remote wins if newer, local migrates to relay if no remote event exists), subscribe to live updates from other devices, re-fetch on reconnect, and publish after every mutationMath.max(now, lastSeenRemoteTimestamp + 1)) to handle clock skew, plus NIP-01 event ID tie-breaking for equal timestampsevent.pubkeybefore decrypting relay events, matchingReadStateManager's guardparseChannelSectionPayloadfromchannelSectionsStorage.ts(eliminates duplicated validation) andswapSectionOrderintochannelSectionsHelpers.tsresetSyncState()intoresetWorkspaceState()inuseWorkspaceInit.tsper the project's module-singleton reset conventionKIND_CHANNEL_SECTIONSconstant inkinds.tswith comment explaining shared kind 30078 value