gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainc028ac61Merge branch 'notes-pr7-kunibert' into mainAtlasmain/lib/drafts.hl

1.8 KB

  1. // Rejected note saves remain server state until accepted or deleted (hybriel#383).
  2. // Each login's draft is separate, so another device's conflict workflow stays unchanged.
  3. // Callers in notes.hl resolve a live, owned note before writing; all table writes are here.
  4. import { MPackDB } from 'hl:mpackdb'
  5. import { storageDir } from './util.hl'
  6. static maxDraftText = 1000000
  7. static draftsTable = new MPackDB(file = storageDir + '/drafts.db', primaryKey = 'key', indexes = ['owner', 'note'])
  8. static draftKey = (String owner, String note, String by) => { return owner + ':' + note + ':' + by }
  9. static draftsFor = (String owner, String by) => {
  10. out = []
  11. if (owner == null || by == null || by == '') { return out }
  12. for (d of draftsTable.find('owner', owner)) {
  13. if (d.by == by) { out.push({ key = d.note text = d.text base = d.base when = d.when }) }
  14. }
  15. return out
  16. }
  17. static keepDraft = (String owner, String note, String by, String text, Number base, Number when) => {
  18. if (owner == null || by == null || by == '') { return null }
  19. if (text.length > maxDraftText) { return 'the draft is too long to keep (at most ' + maxDraftText + ' characters)' }
  20. key = draftKey(owner, note, by)
  21. old = draftsTable.fetch(key)
  22. if (old != null && old.when > when) { return null }
  23. row = { =key =owner =note =by =text =base =when }
  24. stored = old == null ? draftsTable.put(row) : draftsTable.update(key, row)
  25. return stored == null ? 'could not keep the draft' : null
  26. }
  27. // A delayed acceptance must not clear a newer rejected edit.
  28. static acceptDraft = (String owner, String note, String by, Number when) => {
  29. key = draftKey(owner, note, by)
  30. old = draftsTable.fetch(key)
  31. if (old != null && old.owner == owner && old.when <= when) { draftsTable.delete(key) }
  32. }
  33. static deleteDrafts = (String owner, String note) => {
  34. for (d of draftsTable.find('note', note)) {
  35. if (d.owner == owner) { draftsTable.delete(d.key) }
  36. }
  37. }

Branches

Latest commits

  • c028ac61Merge branch 'notes-pr7-kunibert' into mainAtlas
  • 9cc92bdfKeep conflict and history fixes while awaiting queued save supportAtlas
  • a5c27cb6Allow real edits back to earlier text and honor configured identAtlas
  • 15c46ced|||PR Preserve note edits, conflict bases and visible historyAtlas
  • 4c6e0bf6Merge branch 'notes13-day61' into mainAtlas
  • eb51864f|||PR Back/Forward via navigate, server drafts, Hybriel day61Atlas
  • 3537cf7eMerge branch 'vendor-day59' into mainAtlas
  • c13d188b|||PR Vendor Hybriel day59Atlas
  • 24c95433Merge branch 'notes17-ghost-note' into mainAtlas
  • ae1075b2Preserve rejected drafts during note ID adoptionAtlas
  • 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
  • 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
  • 649cef37|||PR Vendor Hybriel day56Atlas
  • aadd0abcMerge branch 'hl-standard-2' into mainAtlas
  • 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
  • 617ee8c0Merge branch 'hl-standard' into mainAtlas
  • 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
  • 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
  • 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre