This commit makes drafts persistent. It does so by: 1. Converting `DraftsArtifacts` into Nostr events 2. Wrapping those Nostr events into NIP-37 notes 3. Saving those NIP-37 notes into NostrDB 4. Loading those same notes at startup 5. Unwrapping NIP-37 notes into Nostr events 6. Parsing that into `DraftsArtifacts`, loaded into DamusState 7. PostView can then load these drafts Furthermore, a UX indicator was added to show when a draft has been saved. Limitations: 1. No encoding/decoding roundtrip guarantees. That would require extensive and heavy refactoring which is out of the scope of this commit. 2. We rely on `UserSettings` to keep track of note ids, while we do not have Ndb query capabilities 3. No NIP-37 relay sync support has been added yet, as that adds important privacy and sync conflict considerations which are out of the scope of this ticket, which is ensuring people don't lose their progress while writing notes. 4. The main use cases and scenarios have been tested. Because of (1), there may be some small inconsistencies on the stored version of the draft, but care was taken to keep the substantial portions of the content intact. Closes: https://github.com/damus-io/damus/issues/1862 Changelog-Added: Added local persistence of note drafts Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
22 lines
613 B
Swift
22 lines
613 B
Swift
//
|
||
// DraftTests.swift
|
||
// damusTests
|
||
//
|
||
// Created by Daniel D’Aquino on 2025-01-15
|
||
|
||
import XCTest
|
||
@testable import damus
|
||
|
||
class DraftTests: XCTestCase {
|
||
func testRoundtripNIP37Draft() {
|
||
let test_note =
|
||
NostrEvent(
|
||
content: "Test",
|
||
keypair: test_keypair_full.to_keypair(),
|
||
createdAt: UInt32(Date().timeIntervalSince1970 - 100)
|
||
)!
|
||
let draft = try! NIP37Draft(unwrapped_note: test_note, draft_id: "test", keypair: test_keypair_full)!
|
||
XCTAssertEqual(draft.unwrapped_note, test_note)
|
||
}
|
||
}
|