diff --git a/desk/app/diary.hoon b/desk/app/diary.hoon index 134501b4aa..54fb0ab478 100644 --- a/desk/app/diary.hoon +++ b/desk/app/diary.hoon @@ -1,7 +1,7 @@ /- d=diary, g=groups, ha=hark /- meta /- e=epic -/+ default-agent, verb, dbug +/+ default-agent, verb, dbug, sparse /+ not=notes /+ qup=quips /+ epos-lib=saga @@ -251,6 +251,7 @@ :: [%diary ship=@ name=@ rest=*] =/ =ship (slav %p ship.pole) + ?> =(our ship) di-abet:(di-watch:(di-abed:di-core ship name.pole) rest.pole) :: [%said host=@ name=@ %note time=@ quip=?(~ [@ ~])] @@ -485,6 +486,7 @@ :: =/ =update:d [now.bowl command] =. log.diary (put:log-on:d log.diary update) + =. di-core (di-give-ui update) (di-give-updates update) :: only accept commands for diaries we own :: @@ -834,14 +836,16 @@ out (~(put in out) [ship path]) :: + ++ di-give-ui + |= =update:d + (give %fact ~[/ui] act:mar:d !>([flag diff.update])) + :: ++ di-give-updates |= =update:d ^+ di-core =/ paths=(set path) %- ~(gas in *(set path)) (turn ~(tap in di-subscriptions) tail) - =. paths (~(put in paths) (snoc di-area %ui)) - =. cor (give %fact ~[/ui] act:mar:d !>([flag diff.update])) =/ cag=cage [upd:mar:d !>(update)] =. cor (give %fact ~(tap in paths) cag) @@ -901,33 +905,32 @@ |= update:d ?> di-from-host ^+ di-core - =. di-core (di-give-updates time diff) - ?- -.diff - %sort di-core(sort.diary sort.diff) - %view di-core(view.diary view.diff) - %order di-core(arranged-notes.diary notes.diff) - %create di-core(perm.diary [writers group]:create.diff) - :: - %notes - =. notes.diary (reduce:di-notes time [id delta]:diff) - =. cor (give-brief flag di-brief) - =/ cons=(list (list content:ha)) - (hark:di-notes our.bowl +.diff) - =. cor - %- emil - %+ turn cons - |= cs=(list content:ha) - (pass-hark (di-spin /note/(rsh 4 (scot %ui id.diff)) cs ~)) - di-core + =. di-core (di-give-ui time diff) + =^ miss global.diary + (apply-diffs:diary global.diary diff) + =. diffs.future.local.diary + %+ roll miss + |= [[=id:notes:d =diff:notes:d] =_diffs.future.local.diary] + :: if the item affected by the diff is not in the window we care about, + :: then ignore it. otherwise, put it in the pending diffs set. + :: + ?. (~(has as:sparse window.future.local.diary) id) + diffs + (~(put ju diffs) id diff) + :: emit notifications if we need to :: - ?(%add-writers %del-writers) - =* writers writers.perm.diary - =. writers - ?- -.diff - %add-writers (~(uni in writers) sects.diff) - %del-writers (~(dif in writers) sects.diff) - == - di-core - == + |- + ?~ diff di-core + =* dd=diff:diary i.diff + ?. ?=(%notes -.dd) $(diff t.diff) + =. cor (give-brief flag di-brief) + =/ cons=(list (list content:ha)) + (hark:di-notes our.bowl +.dd) + =. cor + %- emil + %+ turn cons + |= cs=(list content:ha) + (pass-hark (di-spin /note/(rsh 4 (scot %ui id.dd)) cs ~)) + $(diff t.diff) -- -- diff --git a/desk/lib/sparse.hoon b/desk/lib/sparse.hoon new file mode 100644 index 0000000000..26593e6f4a --- /dev/null +++ b/desk/lib/sparse.hoon @@ -0,0 +1,89 @@ +:: sparse sets: sets of numbers, minimally specified +:: +:: provides types & utilities for working with sparse sets of numbers, +:: implemented as ordered lists ($sass) of number ranges ($span). +:: +:: TODO path to full genericity: +:: 1. use a single comparator everywhere (lte?) +:: 2. don't assume we're working on numbers +:: 3. type constructors, wet gates, comparator arg +:: 4. rewrite in terms of trees for performance +:: 5. jet it +:: +|% ++$ span [fro=@ til=@] :: range (inclusive) ++$ sass (list span) :: sparse set +:: +++ fat :: inside or next to? + |= [span a=@] + &((lte (dec fro) a) (lte a +(til))) +:: +::TODO optimize, can we do just three of these? +++ lap :: have overlap? + |= [a=span b=span] + ?| (fat a fro.b) + (fat a til.b) + (fat b fro.a) + (fat b til.a) + == +:: +++ wed :: merge + |= [a=span b=span] + ^- span + [(min fro.a fro.b) (max til.a til.b)] +:: +++ cut :: remove b from a + |= [a=span b=span] + ^- sass + ?: =(a b) ~ + ?: (lth til.b fro.a) + [a]~ :: no overlap (early) + ?: (lte fro.b fro.a) + ?: (lth til.b til.a) + [+(til.b) til.a]~ :: head overlap + ~ :: full overlap + ?: (lth til.b til.a) + :~ [fro.a (dec fro.b)] :: middle overlap + [+(til.b) til.a] + == + ?: (lte fro.b til.a) + [fro.a (dec fro.b)]~ :: tail overlap + [a]~ :: no overlap (late) +:: +++ as :: sass engine + |_ a=sass + ++ put :: insert + |= b=$@(@ span) + =? b ?=(@ b) [b b] + ?> ?=(^ b) + |- ^+ a + ?> (lte fro.b til.b) + ?~ a [b]~ + ?: (gth fro.i.a til.b) + [b a] + ?: (lap i.a b) + $(b (wed i.a b), a t.a) + [i.a $(a t.a)] + :: + ++ has :: existence check + |= b=@ + ^- ? + ?~ a | + ?: (lth b fro.i.a) | + ?: (lte b til.i.a) & + $(a t.a) + :: + ++ del :: remove + |= b=$@(@ span) + =? b ?=(@ b) [b b] + ?> ?=(^ b) + |- ^+ a + ?> (lte fro.b til.b) + ?~ a ~ + ?: (gth fro.i.a til.b) + a + ?: (lap i.a b) + (welp (cut i.a b) $(a t.a)) + [i.a $(a t.a)] + -- +-- \ No newline at end of file diff --git a/desk/sur/diary.hoon b/desk/sur/diary.hoon index 57ca264779..64b4d92913 100644 --- a/desk/sur/diary.hoon +++ b/desk/sur/diary.hoon @@ -77,6 +77,7 @@ :: :: $window: sparse set of time ranges :: + ::TODO populate this +$ window (list [from=time to=time]) :: :: .window: time range for requested notes that we haven't received @@ -95,10 +96,10 @@ =future == :: - :: $diff: can be applied to global + :: $diffs: can be applied to global :: + +$ diffs (list diff) +$ diff - %- list $% [%notes =id:notes =diff:notes] [%order (rev order=arranged-notes)] [%view (rev =view)] @@ -106,24 +107,24 @@ [%perm (rev =perm)] == :: - ++ apply-diff - |= [=global =diff] - ^- (each global id) - ?~ diff - global - =. global - ?- -.i.diff - %order &+global(order (apply-rev order.global +.i.diff)) - %view &+global(view (apply-rev view.global +.i.diff)) - %sort &+global(sort (apply-rev sort.global +.i.diff)) - %perm &+global(perm (apply-rev perm.global +.i.diff)) + ++ apply-diffs + |= [=global =diffs] + ^- [(list [id:notes diff:notes]) _global] + ?~ diffs [~ global] + =^ hed global + ?- -.i.diffs + %order [~ global(order (apply-rev order.global +.i.diffs))] + %view [~ global(view (apply-rev view.global +.i.diffs))] + %sort [~ global(sort (apply-rev sort.global +.i.diffs))] + %perm [~ global(perm (apply-rev perm.global +.i.diffs))] %notes - =/ res (apply-diff:notes notes.global +.i.diff) + =/ res (apply-diff:notes notes.global +.i.diffs) ?~ res - |+id.i.diff - &+global(notes u.res) + [[id.i.diffs diff.i.diffs]~ global] + [~ global(notes u.res)] == - $(diff t.diff) + =^ tal global $(diffs t.diffs) + [(weld hed tal) global] -- :: :: $notes: a set of time ordered diary posts @@ -379,7 +380,7 @@ command == :: -+$ remark-action ++$ remark-action $~ [%read ~] $>(?(%read %read-at %watch %unwatch) action) :: @@ -401,7 +402,7 @@ :: :: $diff: the full suite of modifications that can be made to a diary :: -+$ diff diff:diary ++$ diff diffs:diary :: :: $net: an indicator of whether I'm a host or subscriber ::