urbit/app/collections.hoon

439 lines
14 KiB
Plaintext
Raw Normal View History

2017-12-02 21:45:47 +03:00
:: /app/collection/hoon
::
/- hall
/+ hall
2017-12-13 05:48:57 +03:00
:: =/ cols
:: /: /===/web/collections
:: /_ /. /= conf /coll-config/
:: /= tops
:: /; (rekey %da) :: XX add /_ @foo back maybe
:: /_ /. /coll-topic/
:: /= comt
2017-12-14 03:04:45 +03:00
:: /: %/coments
2017-12-13 05:48:57 +03:00
:: /; (rekey %da) :: XX add /_ @foo back maybe
:: /_ /coll-comment/
:: ==
2017-12-02 21:45:47 +03:00
::
:: things to keep in sync:
2017-12-14 03:04:45 +03:00
:: collections: state, files, hall unique by name
:: topics: state, files, hall, notify unique by date
:: comments: state, files, notify unique by date
::
:: filepaths:
:: /web/collections/my-coll.config
:: /web/collections/my-coll/some.topic
:: /web/collections/my-coll/some/1.comment
::
:: notification circles:
2017-12-14 03:04:45 +03:00
:: ~.collections_blog-date new/changed post notifications
:: ~.collections_blog-date__post-date new/changed comments notifications
2017-12-02 21:45:47 +03:00
::
2017-12-14 03:04:45 +03:00
::
::::
::
:: XX belongs back in zuse
|%
++ pack :: light path encoding
|= {a/term b/path} ^- knot
%+ rap 3 :- (wack a)
(turn b |=(c/knot (cat 3 '_' (wack c))))
::
++ pick :: light path decoding
=+ fel=(most cab (sear wick urt:ab))
|=(a/knot `(unit {p/term q/path})`(rush a fel))
::
--
2017-12-02 21:45:47 +03:00
=> |%
++ state ::
2017-12-14 03:04:45 +03:00
$: cols/(map time collection) :: collections by name
2017-12-02 21:45:47 +03:00
== ::
++ collection ::
$: conf/config :: configuration
tops/(map @da topic) :: parent-level content
== ::
++ topic ::
$: tit/cord :: title
comment ::
2017-12-02 21:45:47 +03:00
== ::
++ comment ::
$: who/ship :: author
wen/@da :: created
wed/@da :: editted
wat/wain :: content
== ::
++ config ::
$: desc/cord :: description
publ/? :: public or private
visi/? :: visible or hidden
mems/(set ship) :: ships on list
== ::
++ action ::
$% $: $create :: create a collection
wat/kind :: collection kind
des/cord :: name
pub/? :: public or private
vis/? :: visible or hidden
ses/(set ship) :: black/whitelist
== ::
::TODO probably want to specify @da here too.
2017-12-14 03:04:45 +03:00
{$submit col/time tit/cord wat/wain} :: submit a post/note
{$comment col/time top/@da com/@da wat/wain} :: submit a comment
{$delete col/time} :: delete a collection
== ::
++ kind ?($blog $fora $note) ::
++ move (pair bone card) :: all actions
++ lime :: diff fruit
2017-12-02 21:45:47 +03:00
$% {$hall-prize prize:hall} ::
{$hall-rumor rumor:hall} ::
== ::
++ poke ::
$% {$hall-action action:hall} ::
== ::
++ card ::
$% {$diff lime} ::
{$info wire ship term nori:clay} ::
{$peer wire dock path} ::
{$poke wire dock poke} ::
{$pull wire dock $~} ::
{$warp wire sock riff:clay} ::
2017-12-02 21:45:47 +03:00
{$quit $~} ::
== ::
--
::
2017-12-14 03:04:45 +03:00
::::
::
=, wired
=, space:userlib
2017-12-02 21:45:47 +03:00
|_ {bol/bowl:gall state}
::
++ prep ::< prepare state
::> adapts state.
::
|= old/(unit *)
^- (quip move _..prep)
::?~ old
[~ ..prep] ::TODO init, start clay subs
::[~ ..prep(+<+ u.old)]
2017-12-02 21:45:47 +03:00
::
++ poke-noun
|= a/@
^- (quip move _+>)
~& %poked
2017-12-14 03:04:45 +03:00
ta-done:(ta-write-config:ta now.bol ['a description' pub=& vis=& [~palzod ~ ~]])
2017-12-02 21:45:47 +03:00
::
++ writ
|= {wir/wire rit/riot:clay}
^- (quip move _+>)
[~ +>]
::TODO watch for file changes. create on new files, update on change, delete
:: on remove. we want to watch /web/collections recursively if possible,
:: or /web/collections/[col] for each collection and then
:: /web/collections/[col]/[top] for each topic as they get created.
::
2017-12-13 05:48:57 +03:00
++ ignore-action
|= act/action ^- ?
?- -.act
?($create $delete)
?: (team:title our.bol src.bol) |
~|([%unauthorized -.act src.bol] !!)
::
?($submit $comment)
=/ col (~(get by cols) col.act)
?~ col &
?: publ.conf.u.col
(~(has in mems.conf.u.col) src.bol) :: not on blacklist
!(~(has in mems.conf.u.col) src.bol) :: is on whitelist
==
::
2017-12-02 21:45:47 +03:00
++ poke-collections-action
|= act/action
2017-12-13 05:48:57 +03:00
^- (quip move _+>)
?: (ignore-action act)
2017-12-05 00:47:41 +03:00
[~ +>]
=< ta-done
2017-12-02 21:45:47 +03:00
?- -.act
$create (ta-create:ta +.act)
$submit (ta-submit:ta +.act)
$comment (ta-comment:ta +.act)
$delete (ta-delete:ta +.act)
2017-12-02 21:45:47 +03:00
==
::
++ diff-hall-prize
|= {wir/wire piz/prize:hall}
^- (quip move _+>)
[~ +>]
::
2017-12-14 03:04:45 +03:00
++ diff-hall-rumor-hall
2017-12-02 21:45:47 +03:00
|= {wir/wire rum/rumor:hall}
^- (quip move _+>)
2017-12-14 03:04:45 +03:00
=/ nom (raid wir /[%da])
2017-12-02 21:45:47 +03:00
?> ?=({$circle $config *} rum)
ta-done:(ta-apply-config-diff:ta nom dif.rum.rum)
::
++ ta
|_ moves/(list move)
2017-12-13 05:48:57 +03:00
++ ta-done [(flop moves) +>]
++ ta-emit |=(mov/move %_(+> moves [mov moves]))
++ ta-emil |=(mos/(list move) %_(+> moves (welp (flop mos) moves)))
2017-12-02 21:45:47 +03:00
++ ta-hall-action
2017-12-13 05:48:57 +03:00
|= act=action:hall
2017-12-02 21:45:47 +03:00
%- ta-emit
:^ ost.bol %poke / ::TODO wire, handle ++coup.
2017-12-02 21:45:47 +03:00
:+ [our.bol %hall] %hall-action
act
::
2017-12-13 05:48:57 +03:00
++ ta-hall-actions
|= act=(list ?(~ action:hall)) ^+ +>
?~ act +>
?~ i.act $(act t.act)
$(act t.act, +> (ta-hall-action i.act)) ::TODO group at all?
::
:: %performing-actions
2017-12-02 21:45:47 +03:00
::
++ ta-create
2017-12-13 05:48:57 +03:00
|= {wat/kind cof/config}
2017-12-02 21:45:47 +03:00
^+ +>
2017-12-13 05:48:57 +03:00
::XX unhandled kind
2017-12-14 03:04:45 +03:00
(ta-change-config now.bol cof %poke)
2017-12-02 21:45:47 +03:00
::
++ ta-submit
2017-12-14 03:04:45 +03:00
|= {col/time tit/cord wat/wain}
2017-12-13 05:48:57 +03:00
=/ top/topic [tit src.bol now.bol now.bol wat]
(ta-change-topic col top %poke)
::
++ ta-comment
2017-12-14 03:04:45 +03:00
|= {col/time top/@da com/@da wat/wain}
^+ +>
2017-12-13 05:48:57 +03:00
?. (~(has by cols) col) +>.$
=/ cos=collection (~(got by cols) col)
?. (~(has by tops.cos) top) +>.$
=/ old/comment
%+ fall (get-comment col top com)
[src.bol now.bol now.bol wat]
2017-12-13 05:48:57 +03:00
?. =(who.old src.bol) +>.$ :: error?
%^ ta-write-comment col top
2017-12-13 05:48:57 +03:00
[who.old wen.old now.bol wat]
::
++ ta-delete
2017-12-14 03:04:45 +03:00
|= col/time
^+ +>
+>
::TODO - delete files
:: - unsubscribe from clay
:: - unsubscribe from hall
:: - send delete action to hall
:: - remove from state
::
:: %applying-changes
::
2017-12-02 21:45:47 +03:00
++ ta-apply-config-diff
2017-12-14 03:04:45 +03:00
|= {col/time dif/diff-config:hall}
2017-12-02 21:45:47 +03:00
^+ +>
=+ cof=conf:(~(got by cols) col)
2017-12-05 00:59:53 +03:00
=; new/(unit config)
?~ new +>.$
(ta-change-config col u.new %hall)
2017-12-05 00:59:53 +03:00
?+ -.dif ~
$caption
`cof(desc cap.dif)
::
$permit
%- some
%_ cof
mems
%. mems.cof
?: add.dif
~(dif in sis.dif)
~(int in sis.dif)
==
::
$remove
`cof ::TODO/REVIEW ignore/recreate? *don't* remove files.
==
2017-12-02 21:45:47 +03:00
::
++ ta-change-config
2017-12-14 03:04:45 +03:00
|= {col/time new/config src/?($file $hall $poke)}
2017-12-02 21:45:47 +03:00
^+ +>
2017-12-13 05:48:57 +03:00
::
::REVIEW I think clay writes are idempotent?
2017-12-02 21:45:47 +03:00
:: if not changed on disk, update the file.
2017-12-13 05:48:57 +03:00
=? +> !?=($file src)
(ta-write-config col new)
=+ ole=(~(get by cols) col)
2017-12-02 21:45:47 +03:00
:: if we don't have it yet, add to state and hall.
?~ ole
=. cols (~(put by cols) col new ~)
2017-12-13 05:48:57 +03:00
(ta-hall-create col new)
=/ old conf.u.ole
:: make sure publ stays unchanged.
=. +>.$
2017-12-13 05:48:57 +03:00
?: =(publ.new publ.old) +>.$
=. publ.new publ.old
(ta-write-config col new)
2017-12-02 21:45:47 +03:00
:: update config in state.
=. cols (~(put by cols) col u.ole(conf new))
:: update config in hall.
2017-12-13 05:48:57 +03:00
=/ nam (circle-for col)
%- ta-hall-actions :~
?: =(desc.old desc.new) ~
[%depict nam desc.new]
::
2017-12-02 21:45:47 +03:00
?: =(visi.old visi.new) ~
2017-12-13 05:48:57 +03:00
[%public visi.new our.bol nam]
::
(hall-permit nam | (~(dif in mems.old) mems.new))
(hall-permit nam & (~(dif in mems.new) mems.old))
==
2017-12-02 21:45:47 +03:00
::
++ ta-change-topic
2017-12-14 03:04:45 +03:00
|= {col/time top/topic src/?($file $poke)}
^+ +>
2017-12-13 05:48:57 +03:00
=/ old (get-topic col wen.top)
:: only original poster and host can edit.
2017-12-13 05:48:57 +03:00
?. |(?=(~ old) =(who.u.old src.bol) ?=($file src)) +>.$
::
::REVIEW this was just set in ta-submit?
=? who.top ?=($poke src) src.bol :: ensure legit author
=. wed.top now.bol :: change last edit date
:: store in state
=/ cos (~(got by cols) col)
=. tops.cos (~(put by tops.cos) wen.top top)
=. cols (~(put by cols) col cos)
::
=/ new =(~ old)
=? +>.$ new
2017-12-13 05:48:57 +03:00
(ta-hall-create-topic col wen.top conf.cos)
=. +>.$ (ta-write-topic col top)
(ta-hall-notify col wen.top ~ new wat.top)
::
2017-12-13 05:48:57 +03:00
::REVIEW never called
::++ ta-change-comment
2017-12-14 03:04:45 +03:00
:: |= {col/time top/@da com/comment src/?($file $poke)}
2017-12-13 05:48:57 +03:00
:: ^+ +>
:: =/ old (get-comment col top wen.com)
:: :: only original poster and host can edit.
:: ?. |(?=(~ old) =(who.u.old src.bol) ?=($file src))
:: +>.$
:: =? who.com ?=($poke src) src.bol :: ensure legit author
:: =. wed.com now.bol :: change last edit date.
:: ::
:: =. +>.$ (ta-write-comment col top com)
:: (ta-hall-notify col top `wen.com =(~ old) wat.com)
::
:: %writing-files
::
2017-12-13 05:48:57 +03:00
++ ta-write
|= [wir=[term ~] pax=path cay=cage] ^+ +>
=/ pax=path
2017-12-14 03:04:45 +03:00
:(weld base-path pax /[p.cay])
2017-12-13 05:48:57 +03:00
%+ ta-emit ost.bol
[%info (weld wir pax) our.bol (foal pax cay)]
::
++ ta-write-config
2017-12-14 03:04:45 +03:00
|= {col/time cof/config}
2017-12-02 21:45:47 +03:00
^+ +>
2017-12-13 05:48:57 +03:00
%^ ta-write /config
2017-12-14 03:04:45 +03:00
(dray /[%da] col)
2017-12-13 05:48:57 +03:00
[%collections-config !>(cof)]
::
++ ta-write-topic
2017-12-14 03:04:45 +03:00
|= {col/time top/topic}
^+ +>
2017-12-13 05:48:57 +03:00
%^ ta-write /topic
2017-12-14 03:04:45 +03:00
(dray /[%da]/[%da] col wen.top)
2017-12-13 05:48:57 +03:00
[%collections-topic !>(top)]
::
++ ta-write-comment
2017-12-14 03:04:45 +03:00
|= {col/time top/@da com/comment}
^+ +>
2017-12-13 05:48:57 +03:00
%^ ta-write /comment
2017-12-14 03:04:45 +03:00
(dray /[%da]/[%da]/[%da] col top wen.com)
2017-12-13 05:48:57 +03:00
[%collections-comment !>(com)]
::
:: %hall-changes
::
++ ta-hall-create
2017-12-14 03:04:45 +03:00
|= {col/time cof/config}
^+ +>
2017-12-13 05:48:57 +03:00
=+ nam=(circle-for col)
=. +>.$ (ta-hall-configure nam cof)
%- ta-emit
:* 0 ::REVIEW bone 0?
%peer
2017-12-14 03:04:45 +03:00
hall+(dray /[%da] col)
2017-12-13 05:48:57 +03:00
[our.bol %hall]
/circle/[nam]/config-l
==
2017-12-02 21:45:47 +03:00
::
2017-12-13 05:48:57 +03:00
++ ta-hall-create-topic
2017-12-14 03:04:45 +03:00
|= {col/time top/@da cof/config}
2017-12-02 21:45:47 +03:00
^+ +>
2017-12-13 05:48:57 +03:00
=+ nam=(circle-for-topic col top)
=. +>.$ (ta-hall-configure nam cof)
2017-12-02 21:45:47 +03:00
%- ta-hall-action
2017-12-13 05:48:57 +03:00
::NOTE %source also subs to local config & presence, but
:: that generally won't result in visible notifications.
:^ %source (circle-for col) &
(sy `source:hall`[our.bol nam]~ ~)
2017-12-02 21:45:47 +03:00
::
2017-12-13 05:48:57 +03:00
++ ta-hall-configure
|= [nam=term cof=config] ^+ +>
2017-12-02 21:45:47 +03:00
^+ +>
2017-12-13 05:48:57 +03:00
%- ta-hall-actions :~
[%create nam desc.cof ?:(publ.cof %journal %village)]
?.(visi.cof ~ [%public & our.bol nam])
(hall-permit nam & mems.cof)
==
2017-12-02 21:45:47 +03:00
::
::
++ ta-hall-notify
2017-12-14 03:04:45 +03:00
|= {col/time top/@da com/(unit @da) new/? wat/wain}
^+ +>
%- ta-hall-action
=- :+ %phrase [[our.bol tar] ~ ~]
[%fat [%text wat] [%lin | msg]]~
^- {tar/naem:hall msg/cord}
::TODO
2017-12-13 05:48:57 +03:00
[(circle-for col) 'TODO']
2017-12-02 21:45:47 +03:00
--
::
2017-12-13 05:48:57 +03:00
++ hall-permit
|= [nam=term inv=? sis=(set ship)]
?~ sis ~
[%permit nam inv sis]
2017-12-02 21:45:47 +03:00
::
2017-12-13 05:48:57 +03:00
::
++ circle-for
2017-12-14 03:04:45 +03:00
|=(col/time (pack %collection (dray /[%da] col)))
2017-12-13 05:48:57 +03:00
::
++ circle-for-topic
2017-12-14 03:04:45 +03:00
|=({col/time top/time} (pack %collection (dray /[%da]/[%da] col top)))
::
2017-12-14 03:04:45 +03:00
++ base-path (en-beam:format byk.bol(r da+now.bol) /collections/web)
::
++ get-config
2017-12-14 03:04:45 +03:00
|= col/time
^- (unit config)
2017-12-14 03:04:45 +03:00
=/ pax :(weld base-path (dray /[%da] col) /collections-config)
2017-12-13 05:48:57 +03:00
::
2017-12-14 03:04:45 +03:00
?~ (file pax) ~
`.^(config %cx pax)
::
++ get-topic
2017-12-14 03:04:45 +03:00
|= {col/time top/@da}
^- (unit topic)
2017-12-14 03:04:45 +03:00
=/ pax :(weld base-path (dray /[%da]/[%da] col top) /collections-topic)
2017-12-13 05:48:57 +03:00
::
2017-12-14 03:04:45 +03:00
?~ (file pax) ~
`.^(topic %cx pax)
::
++ get-comment
2017-12-14 03:04:45 +03:00
|= {col/time top/@da com/@da}
^- (unit comment)
2017-12-14 03:04:45 +03:00
=/ pax
:(weld base-path (dray /[%da]/[%da]/[%da] col top com) /collections-comment)
2017-12-13 05:48:57 +03:00
::
2017-12-14 03:04:45 +03:00
?~ (file pax) ~
`.^(comment %cx pax)
2017-12-02 21:45:47 +03:00
--