diff --git a/pkg/arvo/app/chat-hook.hoon b/pkg/arvo/app/chat-hook.hoon index 7cf15774bb..622ce92275 100644 --- a/pkg/arvo/app/chat-hook.hoon +++ b/pkg/arvo/app/chat-hook.hoon @@ -3,64 +3,25 @@ :: allow sending chat messages to foreign paths based on write perms :: /- inv=invite-store, *metadata-store, *group-store, - hook=chat-hook, view=chat-view, *group, - push-hook, pull-hook -/+ default-agent, verb, dbug, store=chat-store, group-store, grpl=group, + hook=chat-hook, *group, push-hook, pull-hook, store=chat-store +/+ default-agent, verb, dbug, group-store, grpl=group, resource, graph-store, *migrate -~% %chat-hook-top ..part ~ |% +$ card card:agent:gall :: +$ versioned-state - $% state-0 - state-1 - state-2 - state-3 - state-4 - state-5 - state-6 - state-7 - state-8 - state-9 - state-10 + $% state-10 state-11 == :: -+$ migration-state - (map resource @ud) -:: ++$ migration-state (map resource @ud) +$ state-11 [%11 state-base migrate=migration-state] +$ state-10 [%10 state-base] -+$ state-9 [%9 state-base] -+$ state-8 [%8 state-base] -+$ state-7 [%7 state-base] -+$ state-6 [%6 state-base] -+$ state-5 [%5 state-base] -+$ state-4 [%4 state-base] -+$ state-3 [%3 state-base] -+$ state-2 [%2 state-base] -:: -+$ state-1 - $: %1 - loaded-cards=* - state-base - == -+$ state-0 [%0 state-base] +$ state-base $: =synced:hook invite-created=_| allow-history=(map path ?) == -:: -+$ poke - $% [%chat-action action:store] - [%invite-action action:inv] - [%chat-view-action action:view] - == -:: -+$ fact - $% [%chat-update update:store] - == -- =| state-11 =* state - @@ -69,7 +30,6 @@ %+ verb | ^- agent:gall =< - ~% %chat-hook-agent-core ..poke-json ~ |_ bol=bowl:gall +* this . chat-core +> @@ -90,231 +50,22 @@ |- ?: ?=(%11 -.old) [cards this(state old)] - ?: ?=(%10 -.old) - =. cards - :_ cards - =- [%pass /self-poke %agent [our.bol %chat-hook] %poke -] - noun+!>(%migrate-graph) - $(old [%11 +.old ~]) - :: - ?: ?=(%9 -.old) - =. cards - :_ cards - [%pass /self-poke %agent [our.bol %chat-hook] %poke %noun !>(%run-upg9)] - $(-.old %10) - ?: ?=(%8 -.old) - $(-.old %9) - ?: ?=(%7 -.old) - =. cards - :_ cards - [%pass /self-poke %agent [our.bol %chat-hook] %poke %noun !>(%run-upg7)] - $(-.old %8) - ?: ?=(%6 -.old) - =. cards - %+ weld cards - ^- (list card) - [%pass /s %agent [our.bol %chat-hook] %poke %noun !>(%fix-out-of-sync)]~ - $(-.old %7) - ?: ?=(?(%3 %4 %5) -.old) - =. cards - %+ weld cards - ^- (list card) - [%pass /pokeme %agent [our.bol %chat-hook] %poke %noun !>(%fix-dm)]~ - $(-.old %6) - ?: ?=(%2 -.old) - =. cards - %+ weld cards - :~ watch-groups:cc - == - =^ new-cards=(list card) old - =| crds=(list card) - =/ syncs - ~(tap by synced.old) - |- - ?~ syncs - [crds old] - =/ [pax=path =ship] - i.syncs - ?> ?=(^ pax) - ?. =('~' i.pax) - $(syncs t.syncs) - =/ new-path=path - t.pax - =. synced.old - (~(del by synced.old) pax) - ?. =(ship our.bol) - =. synced.old - (~(put by synced.old) new-path ship) - $(syncs t.syncs) - =/ history=? - (~(gut by allow-history.old) pax %.y) - =. allow-history.old - (~(del by allow-history.old) pax) - =. allow-history.old - (~(put by allow-history.old) new-path history) - =. crds - %+ weld crds - :- (add-owned new-path history) - (kick-old-subs pax) - $(syncs t.syncs) - =. cards - (weld cards new-cards) - $(-.old %3) - :: - ?: ?=(%1 -.old) - =. cards - %+ welp cards - ^- (list card) - %+ murn ~(tap by wex.bol) - |= [[=wire =ship =term] *] - ^- (unit card) - ?. &(?=([%mailbox *] wire) =(our.bol ship) =(%chat-store term)) - ~ - `[%pass wire %agent [our.bol %chat-store] %leave ~] - $(old [%2 +>.old]) - :: path structure ugprade logic - :: - =/ keys=(set path) (scry:cc (set path) %chat-store /keys) - %= $ - -.old %2 - :: - cards - %- zing - ^- (list (list card)) - (turn ~(tap in keys) generate-cards) - == - :: - ++ scry-for - |* [=mold app=term =path] - .^ mold - %gx - (scot %p our.bol) - app - (scot %da now.bol) - (snoc `^path`path %noun) - == - :: - ++ kick-old-subs - |= old-path=path - ^- (list card) - ?> ?=(^ old-path) - ?. =('~' i.old-path) - ~ - [%give %kick ~[mailbox+old-path] ~]~ - :: - ++ add-members-group - |= [=path ships=(set ship)] - ^- card - ?> ?=([@ @ ~] path) - =/ rid=resource - [(slav %p i.path) i.t.path] - =- [%pass / %agent [our.bol %group-store] %poke %group-action -] - !>(`action:group-store`[%add-members rid ships]) - :: - ++ add-synced - |= [=ship =path] - ^- card - =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action -] - !>(`action:hook`[%add-synced ship path %.y]) - :: - ++ add-owned - |= [=path history=?] - ^- card - =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action -] - !>(`action:hook`[%add-owned path history]) - :: - ++ generate-cards - |= old-chat=path - ^- (list card) - =/ host=ship (slav %p (snag 0 old-chat)) - =/ new-chat [%'~' old-chat] - =/ old-group=path [%chat old-chat] - %- zing - :~ :~ (delete-group host (snoc old-group %read)) - (delete-group host (snoc old-group %write)) - == - :: - [(record-group new-chat new-chat)]~ - (recreate-chat host old-chat new-chat) - == - :: - ++ recreate-chat - |= [host=ship chat=path new-chat=path] - ^- (list card) - =/ old-mailbox=mailbox:store - (need (scry:cc (unit mailbox:store) %chat-store [%mailbox chat])) - =* enves envelopes.old-mailbox - :~ (chat-poke:cc [%delete new-chat]) - (chat-poke:cc [%delete chat]) - (chat-poke:cc [%create new-chat]) - (chat-poke:cc [%messages new-chat enves]) - (chat-poke:cc [%read new-chat]) - %^ make-poke %chat-hook %chat-hook-action - !> ^- action:hook - ?: =(our.bol host) [%add-owned new-chat %.y] - [%add-synced host new-chat %.y] - == - :: - ++ make-poke - |= [app=term =mark =vase] - ^- card - [%pass /on-load/[app]/[mark] %agent [our.bol app] %poke mark vase] - :: - ++ delete-group - |= [host=ship group=path] - ^- card - %^ make-poke %group-store - %group-action - !> ^- action:group-store - [%remove-group (de-path:resource group) ~] - :: - ++ create-group - |= [group=path who=(set ship)] - ^- (list card) - =/ rid=resource - (de-path:resource group) - :~ %^ make-poke %group-store - %group-action - !> ^- action:group-store - [%add-group rid *invite:policy %.n] - :: - %^ make-poke %group-store - %group-action - !> ^- action:group-store - [%add-members rid who] - == - :: - ++ record-group - |= [group=path chat=path] - ^- card - =/ =metadata - ~| [%weird-chat-path chat] - %* . *metadata - title (snag 2 chat) - date-created now.bol - creator (slav %p (snag 1 chat)) - == - %^ make-poke %metadata-store - %metadata-action - !> ^- metadata-action - [%add group [%chat chat] metadata] + =. cards + :_ cards + =- [%pass /self-poke %agent [our.bol %chat-hook] %poke -] + noun+!>(%migrate-graph) + $(old [%11 +.old ~]) -- :: ++ on-poke - ~/ %chat-hook-poke |= [=mark =vase] ^- (quip card _this) =^ cards state ?+ mark (on-poke:def mark vase) - %json (poke-json:cc !<(json vase)) - %chat-action (poke-chat-action:cc !<(action:store vase)) %noun %- poke-noun:cc - !< ?(%fix-dm %fix-out-of-sync %run-upg7 %run-upg9 %migrate-graph) + !< ?(%migrate-graph) vase - :: - %chat-hook-action - (poke-chat-hook-action:cc !<(action:hook vase)) :: %import ?> (team:title our.bol src.bol) @@ -322,18 +73,9 @@ == [cards this] :: - ++ on-watch - ~/ %chat-hook-watch - |= =path - ^- (quip card _this) - ?+ path (on-watch:def path) - [%backlog *] [(watch-backlog:cc t.path) this] - [%mailbox *] [(watch-mailbox:cc t.path) this] - [%synced *] [(watch-synced:cc t.path) this] - == + ++ on-watch on-watch:def :: ++ on-agent - ~/ %chat-hook-agent |= [=wire =sign:agent:gall] ^- (quip card _this) |^ @@ -365,13 +107,7 @@ -- :: ++ on-leave on-leave:def - ++ on-peek - |= =path - ^- (unit (unit cage)) - ?+ path (on-peek:def path) - [%x %export ~] - ``noun+!>(state) - == + ++ on-peek on-peek:def ++ on-arvo |= [=wire =sign-arvo] ^- (quip card _this) @@ -384,23 +120,10 @@ "behn errored in backoff timers, continuing anyway" :_ this ~[(watch-graph:cc rid)] - :: - [%try-rejoin @ @ *] - :: TODO: check whether we have migrated to graph yet?? - =/ nack-count=@ud (slav %ud i.t.wire) - =/ who=@p (slav %p i.t.t.wire) - =/ pax t.t.t.wire - ?> ?=([%behn %wake *] sign-arvo) - ~? ?=(^ error.sign-arvo) - "behn errored in backoff timers, continuing anyway" - :_ this - [(try-rejoin:cc who pax +(nack-count))]~ == ++ on-fail on-fail:def -- :: -:: -~% %chat-hook-library ..card ~ |_ bol=bowl:gall ++ grp ~(. grpl bol) ++ watch-graph @@ -411,14 +134,10 @@ [%pass migrate-graph+path %agent [entity.rid %graph-push-hook] %watch resource+path] :: ++ poke-noun - |= a=?(%fix-dm %fix-out-of-sync %run-upg7 %run-upg9 %migrate-graph) + |= a=?(%migrate-graph) ^- (quip card _state) |^ ?- a - %fix-dm [(fix-dm %fix-dm) state] - %fix-out-of-sync [(fix-out-of-sync %fix-out-of-sync) state] - %run-upg7 run-7-to-8 - %run-upg9 run-9-to-10 %migrate-graph migrate-graph == :: @@ -437,6 +156,21 @@ ^- card (poke-our %graph-store %graph-update !>(update)) :: + ++ nobody + ^- @p + (bex 128) + :: + ++ path-to-resource + |= =path + ^- resource + ?. ?=([@ @ ~] path) + nobody^(spat path) + =/ m-ship=(unit ship) + (slaw %p i.path) + ?~ m-ship + nobody^(spat path) + [u.m-ship i.t.path] + :: ++ migrate-graph ^- (quip card _state) =/ syncs=(list [=path =ship]) @@ -446,10 +180,10 @@ ?~ syncs [cards state] =, i.syncs =/ rid=resource - (path-to-resource:store path) + (path-to-resource path) ~& migrating+path ~& to+rid - ?: =(nobody:store entity.rid) + ?: =(nobody entity.rid) %_ $ syncs t.syncs :: @@ -469,246 +203,8 @@ syncs t.syncs migrate (~(put by migrate) rid 0) == - :: - ++ scry-for - |* [=mold app=term =path] - .^ mold - %gx - (scot %p our.bol) - app - (scot %da now.bol) - (snoc `^path`path %noun) - == - :: - ++ add-synced - |= [=ship =path] - ^- card - =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action -] - !>(`action:hook`[%add-synced ship path %.y]) - :: - ++ add-owned - |= [=path history=?] - ^- card - =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action -] - !>(`action:hook`[%add-owned path history]) - :: - ++ run-7-to-8 - ^- (quip card _state) - :_ state - =/ subscribers=(jug path ship) - %+ roll ~(val by sup.bol) - |= [[=ship =path] out=(jug path ship)] - :: /(mailbox|backlog)/~ship/resource.name - :: - ?. ?=([@ @ @ *] path) out - =/ pax=^path [i.t.path i.t.t.path ~] - (~(put ju out) pax ship) - =/ group ~(. grpl bol) - ^- (list card) - %+ murn ~(tap in ~(key by synced.state)) - |= =path - ^- (unit card) - ?> ?=([@ @ ~] path) - =/ group-paths (groups-of-chat path) - ?~ group-paths ~ - =/ members (members-from-path:group i.group-paths) - ?: (is-managed-path:group i.group-paths) ~ - =/ ships=(set ship) (~(get ju subscribers) path) - %- some - =+ [%invite path (~(dif in members) ships)] - [%pass /inv %agent [our.bol %chat-view] %poke %chat-view-action !>(-)] - :: - ++ run-9-to-10 - ^- (quip card _state) - :_ - =/ list-paths=(list path) - %+ murn ~(tap in ~(key by synced.state)) - |= =app=path - ^- (unit path) - ?~ (groups-of-chat app-path) - `app-path - ~ - |- - ?~ list-paths - state - =. synced.state (~(del by synced.state) i.list-paths) - $(list-paths t.list-paths) - %+ weld - ^- (list card) - %+ roll ~(tap in ~(key by wex.bol)) - |= [[=wire =ship =term] out=(list card)] - ?> ?=([@ *] wire) - ?. ?&(=(ship our.bol) =(term %chat-hook)) - out - :_ out - =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action !>(-)] - [%remove t.wire] - =/ chat-keys=(set path) (scry-for (set path) %chat-store [%keys ~]) - ^- (list card) - %+ turn ~(tap in chat-keys) - |= =app=path - ^- card - ?> ?=([@ @ ~] app-path) - =/ =ship (slav %p i.app-path) - ?: =(ship our.bol) - (add-owned app-path %.y) - (add-synced ship app-path) - :: - ++ fix-out-of-sync - |= b=%fix-out-of-sync - ^- (list card) - %- zing - %+ turn ~(tap by synced) - |= [=path host=ship] - ^- (list card) - ?: =(host our.bol) ~ - ?> ?=([@ @ ~] path) - =/ =ship (slav %p i.path) - :~ =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action -] - !> ^- action:hook - [%remove path] - :: - =- [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action -] - !> ^- action:hook - [%add-synced ship path %.y] - == - :: - ++ fix-dm - |= b=%fix-dm - ^- (list card) - %- zing - %+ turn - ~(tap by synced) - |= [=path host=ship] - ^- (list card) - ?> ?=([@ @ *] path) - =/ =ship (slav %p i.path) - ?: =(ship our.bol) - :: local dm, no need to do cleanup - ~ - ?: ?=(^ (groups-of-chat path)) - :: correctly initialized, no need to do cleanup - :: - ~ - ?. =((end [3 4] i.t.path) 'dm--') - ~ - :- =- [%pass /fixdm %agent [our.bol %chat-view] %poke %chat-view-action -] - !> ^- action:view - [%delete path] - =/ new-dm /(scot %p our.bol)/(crip (weld "dm--" (trip (scot %p ship)))) - =/ mailbox=(unit mailbox:store) (chat-scry path) - ?~ mailbox - ~ - :~ =- [%pass /fixdm %agent [our.bol %chat-view] %poke %chat-view-action -] - !> ^- action:view - :* %create - %- crip - (zing [(trip (scot %p our.bol)) " <-> " (trip (scot %p ship)) ~]) - '' - new-dm - ship+new-dm - [%invite (silt ~[ship])] - (silt ~[ship]) - %.y - %.n - == - :: - =- [%pass /fixdm %agent [our.bol %chat-store] %poke %chat-action -] - !> ^- action:store - [%messages new-dm envelopes.u.mailbox] - == -- :: -++ poke-json - |= jon=json - ^- (quip card _state) - (poke-chat-action (action:dejs:store jon)) -:: -++ poke-chat-action - |= act=action:store - ^- (quip card _state) - ?> ?=(%message -.act) - :: local - :_ state - ?: (team:title our.bol src.bol) - ?. (~(has by synced) path.act) - ~ - =* letter letter.envelope.act - =? letter &(?=(%code -.letter) ?=(~ output.letter)) - =/ =hoon (ream expression.letter) - letter(output (eval:store bol hoon)) - =/ ship (~(got by synced) path.act) - =/ appl ?:(=(ship our.bol) %chat-store %chat-hook) - [%pass / %agent [ship appl] %poke %chat-action !>(act)]~ - :: foreign - =/ ship (~(get by synced) path.act) - ?~ ship ~ - ?. =(u.ship our.bol) ~ - :: check if write is permitted - ?. (is-member:grp src.bol (group-from-chat path.act)) ~ - =: author.envelope.act src.bol - when.envelope.act now.bol - == - [%pass / %agent [our.bol %chat-store] %poke %chat-action !>(act)]~ -:: -++ poke-chat-hook-action - |= act=action:hook - ^- (quip card _state) - ?- -.act - %add-owned - ?> (team:title our.bol src.bol) - =/ chat-path [%mailbox path.act] - =/ chat-wire [%store path.act] - ?: (~(has by synced) path.act) [~ state] - =: synced (~(put by synced) path.act our.bol) - allow-history (~(put by allow-history) path.act allow-history.act) - == - :_ state - :~ [%pass chat-wire %agent [our.bol %chat-store] %watch chat-path] - [%give %fact [/synced]~ %chat-hook-update !>([%initial synced])] - == - :: - %add-synced - ?> (team:title our.bol src.bol) - ?< =(ship.act our.bol) - ?: (~(has by synced) path.act) [~ state] - =. synced (~(put by synced) path.act ship.act) - ?. ask-history.act - =/ chat-path [%mailbox path.act] - :_ state - [%pass chat-path %agent [ship.act %chat-hook] %watch chat-path]~ - =/ mailbox=(unit mailbox:store) (chat-scry path.act) - =/ chat-history=path - :- %backlog - %+ weld path.act - ?~(mailbox /0 /(scot %ud (lent envelopes.u.mailbox))) - :_ state - :~ [%pass chat-history %agent [ship.act %chat-hook] %watch chat-history] - [%give %fact [/synced]~ %chat-hook-update !>([%initial synced])] - == - :: - %remove - =/ ship=(unit ship) - =/ ship (~(get by synced) path.act) - ?^ ship ship - =? path.act ?=([%'~' *] path.act) t.path.act - ?~ path.act ~ - (slaw %p i.path.act) - ?~ ship - ~& [dap.bol %unknown-host-cannot-leave path.act] - [~ state] - ?: &(!=(u.ship src.bol) ?!((team:title our.bol src.bol))) - [~ state] - =. synced (~(del by synced) path.act) - :_ state - :* [%give %kick ~[[%mailbox path.act]] ~] - [%give %fact [/synced]~ %chat-hook-update !>([%initial synced])] - (pull-wire u.ship [%mailbox path.act]) - (pull-wire u.ship [%store path.act]) - (pull-backlog-subscriptions u.ship path.act) - == - == -:: ++ poke-import |= arc=* ^- (quip card _state) @@ -723,345 +219,8 @@ =- [%pass /self-poke %agent [our.bol %chat-hook] %poke -] noun+!>(%migrate-graph) :: -++ try-rejoin - |= [who=@p pax=path nack-count=@ud] - ^- card - =/ =wire - [%try-rejoin (scot %ud nack-count) (scot %p who) pax] - [%pass wire %agent [who %chat-hook] %watch pax] -:: -++ watch-synced - |= pax=path - ^- (list card) - ?> (team:title our.bol src.bol) - [%give %fact ~ %chat-hook-update !>([%initial synced])]~ -:: -++ watch-mailbox - |= pax=path - ^- (list card) - ?> ?=(^ pax) - ?> (~(has by synced) pax) - :: check if read is permitted - ?> (is-member:grp src.bol (group-from-chat pax)) - =/ box (chat-scry pax) - ?~ box !! - [%give %fact ~ %chat-update !>([%create pax])]~ -:: -++ watch-backlog - |= pax=path - ^- (list card) - ?> ?=(^ pax) - =/ last (dec (lent pax)) - =/ backlog-latest=(unit @ud) (rush (snag last `(list @ta)`pax) dem:ag) - =/ pas `path`(oust [last 1] `(list @ta)`pax) - ?> ?=([* ^] pas) - ?> (is-member:grp src.bol (group-from-chat pas)) - =/ envs envelopes:(need (chat-scry pas)) - =/ length (lent envs) - =/ latest - ?~ backlog-latest length - ?: (gth u.backlog-latest length) 0 - (sub length u.backlog-latest) - =. envs (scag latest envs) - =/ =vase !>([%messages pas 0 latest envs]) - %- zing - :~ [%give %fact ~ %chat-update !>([%create pas])]~ - ?. ?&(?=(^ backlog-latest) (~(has by allow-history) pas)) ~ - ?: =(0 latest) ~ - [%give %fact ~ %chat-update vase]~ - [%give %kick [%backlog pax]~ `src.bol]~ - == -:: -++ fact-invite-update - |= [wir=wire fact=update:inv] - ^- (quip card _state) - :_ state - ?+ -.fact ~ - %accepted - =* resource resource.invite.fact - =/ =path [(scot %p entity.resource) name.resource ~] - :_ ~ - %- chat-view-poke - :^ %join ship.invite.fact - path - ?=(~ (chat-scry path)) -== -:: -++ fact-group-update - |= [wir=wire =update:group-store] - ^- (quip card _state) - :_ state - ?. ?=(%remove-members -.update) - ~ - =/ =path - (en-path:resource resource.update) - =/ chats - (chats-of-group path) - %- zing - %+ turn - chats - |= chat=^path - ^- (list card) - =/ owner - (~(get by synced) chat) - ?~ owner ~ - ?. =(u.owner our.bol) - ~ - %+ turn - ~(tap in ships.update) - |= =ship - [%give %kick [%mailbox chat]~ `ship] -:: -++ fact-chat-update - |= [wir=wire =update:store] - ^- (quip card _state) - ?: (team:title our.bol src.bol) - (handle-local update) - (handle-foreign update) -:: -++ handle-local - |= =update:store - ^- (quip card _state) - ?+ -.update [~ state] - %delete - ?. (~(has by synced) path.update) [~ state] - =. synced (~(del by synced) path.update) - :_ state - :~ [%pass [%mailbox path.update] %agent [our.bol %chat-store] %leave ~] - [%give %fact [/synced]~ %chat-hook-update !>([%initial synced])] - == - :: - %message - :_ state - [%give %fact [%mailbox path.update]~ %chat-update !>(update)]~ - :: - %messages - :_ state - [%give %fact [%mailbox path.update]~ %chat-update !>(update)]~ - == -:: -++ handle-foreign - |= =update:store - ^- (quip card _state) - ?+ -.update [~ state] - %create - :_ state - ?> ?=([* ^] path.update) - =/ shp (~(get by synced) path.update) - ?~ shp ~ - ?. =(src.bol u.shp) ~ - [(chat-poke [%create path.update])]~ - :: - %delete - ?> ?=([* ^] path.update) - =/ shp (~(get by synced) path.update) - ?~ shp [~ state] - ?. =(u.shp src.bol) [~ state] - =. synced (~(del by synced) path.update) - :_ state - :- (chat-poke [%delete path.update]) - :~ [%pass [%mailbox path.update] %agent [src.bol %chat-hook] %leave ~] - [%give %fact [/synced]~ %chat-hook-update !>([%initial synced])] - == - :: - %message - :_ state - ?> ?=([* ^] path.update) - =/ shp (~(get by synced) path.update) - ?~ shp ~ - ?. =(src.bol u.shp) ~ - [(chat-poke [%message path.update envelope.update])]~ - :: - %messages - :_ state - ?> ?=([* ^] path.update) - =/ shp (~(get by synced) path.update) - ?~ shp ~ - ?. =(src.bol u.shp) ~ - [(chat-poke [%messages path.update envelopes.update])]~ - == -:: -++ kick - |= wir=wire - ^- (quip card _state) - ?+ wir !! - [%try-rejoin @ @ *] - $(wir t.t.t.wir) - :: - [%groups ~] [~[watch-groups] state] - :: - [%store @ *] - ~& store-kick+wir - ?: =('~' i.t.wir) - (migrate-store t.t.wir) - ?. (~(has by synced) t.wir) [~ state] - ~& %chat-store-resubscribe - =/ mailbox=(unit mailbox:store) - (chat-scry t.wir) - :_ state - [%pass wir %agent [our.bol %chat-store] %watch [%mailbox t.wir]]~ - :: - [%mailbox @ *] - ~& mailbox-kick+wir - ?: =('~' i.t.wir) - (migrate-listen t.t.wir) - ?. (~(has by synced) t.wir) [~ state] - ~& %chat-hook-resubscribe - =/ =ship (~(got by synced) t.wir) - =/ mailbox=(unit mailbox:store) (chat-scry t.wir) - =/ chat-history - %+ welp backlog+t.wir - ?~(mailbox /0 /(scot %ud (lent envelopes.u.mailbox))) - :_ state - [%pass chat-history %agent [ship %chat-hook] %watch chat-history]~ - :: - [%backlog @ @ *] - =/ chat=path (oust [(dec (lent t.wir)) 1] `(list @ta)`t.wir) - ?: =('~' i.t.wir) - ?> ?=(^ chat) - (migrate-listen t.chat) - ?. (~(has by synced) chat) [~ state] - =/ =ship - ?: =('~' i.t.wir) - (slav %p i.t.t.wir) - (slav %p i.t.wir) - =/ =path ?~((chat-scry chat) wir [%mailbox chat]) - :_ state - [%pass path %agent [ship %chat-hook] %watch path]~ - == -++ migrate-listen - |= =wire - ^- (quip card _state) - ~& listen-migrate+wire - ?> ?=([@ @ ~] wire) - =/ =ship - (slav %p i.wire) - :_ state - ~[(chat-view-poke %join ship wire %.y)] -:: -++ migrate-store - |= =wire - ^- (quip card _state) - ~& store-migrate+wire - (kick store+wire) -:: -++ chat-poke - |= act=action:store - ^- card - [%pass / %agent [our.bol %chat-store] %poke %chat-action !>(act)] -:: -++ chat-view-poke - |= act=action:view - ^- card - [%pass / %agent [our.bol %chat-view] %poke %chat-view-action !>(act)] -:: ++ invite-poke |= =action:inv ^- card [%pass / %agent [our.bol %invite-store] %poke %invite-action !>(action)] -:: -++ chat-scry - |= pax=path - ^- (unit mailbox:store) - %^ scry (unit mailbox:store) - %chat-store - [%mailbox pax] -:: -++ invite-scry - |= uid=serial:inv - ^- (unit invite:inv) - %^ scry (unit invite:inv) - %invite-store - /invite/chat/(scot %uv uid) -:: -++ chats-of-group - |= =group-path - ^- (list path) - :: if metadata-store isn't running yet, we're still in the upgrade ota phase. - :: we can't get chats from the metadata-store, but can make assumptions - :: about group path shape, and the chat that would match it. - ::TODO remove me at some point. - :: - ?. .^(? %gu (scot %p our.bol) %metadata-store (scot %da now.bol) ~) ~ - %+ murn - ^- (list md-resource) - =; resources - %~ tap in - %+ ~(gut by resources) - group-path - *(set md-resource) - .^ (jug path md-resource) - %gy - (scot %p our.bol) - %metadata-store - (scot %da now.bol) - /group-indices - == - |= md-resource - ^- (unit path) - ?. =(%chat app-name) ~ - `app-path -:: -++ groups-of-chat - |= chat=path - ^- (list group-path) - :: if metadata-store isn't running yet, we're still in the upgrade ota phase. - :: we can't get groups from the metadata-store, but can make assumptions - :: about chat path shape, and the chat that would match it. - ::TODO remove me at some point. - :: - ?. .^(? %gu (scot %p our.bol) %metadata-store (scot %da now.bol) ~) ~ - =; resources - %~ tap in - %+ ~(gut by resources) - [%chat chat] - *(set group-path) - .^ (jug md-resource group-path) - %gy - (scot %p our.bol) - %metadata-store - (scot %da now.bol) - /resource-indices - == -:: -++ group-from-chat - |= app-path=path - ^- group-path - =/ groups=(list group-path) - (groups-of-chat app-path) - ?> ?=(^ groups) - i.groups -:: -++ scry - |* [=mold app=term =path] - .^ mold - %gx - (scot %p our.bol) - app - (scot %da now.bol) - (snoc `^path`path %noun) - == -:: -++ pull-backlog-subscriptions - |= [target=ship chat=path] - ^- (list card) - %+ murn ~(tap by wex.bol) - |= [[=wire =ship =term] [acked=? =path]] - ^- (unit card) - ?. ?& =(ship target) - ?=([%backlog *] wire) - =(`1 (find chat wire)) - == - ~ - `(pull-wire target wire) -:: -++ pull-wire - |= [=ship =wire] - ^- card - ?: =(ship our.bol) - [%pass wire %agent [our.bol %chat-store] %leave ~] - [%pass wire %agent [ship %chat-hook] %leave ~] -++ watch-groups - ^- card - [%pass /groups %agent [our.bol %group-store] %watch /groups] -- diff --git a/pkg/arvo/app/chat-store.hoon b/pkg/arvo/app/chat-store.hoon index e221bbc8b1..a21211cfcb 100644 --- a/pkg/arvo/app/chat-store.hoon +++ b/pkg/arvo/app/chat-store.hoon @@ -2,8 +2,8 @@ :: :: data store that holds linear sequences of chat messages :: -/- *group -/+ store=chat-store, default-agent, verb, dbug, group-store, +/- *group, store=chat-store +/+ default-agent, verb, dbug, group-store, graph-store, resource, *migrate, grpl=group, mdl=metadata ~% %chat-store-top ..part ~ |% @@ -102,36 +102,12 @@ ?> (team:title our.bowl src.bowl) =^ cards state ?+ mark (on-poke:def mark vase) - %json (poke-json:cc !<(json vase)) - %chat-action (poke-chat-action:cc !<(action:store vase)) %noun (poke-noun:cc !<(admin-action vase)) %import (poke-import:cc q.vase) == [cards this] :: - ++ on-watch - ~/ %chat-store-watch - |= =path - ^- (quip card _this) - |^ - ?> (team:title our.bowl src.bowl) - =/ cards=(list card) - ?+ path (on-watch:def path) - [%keys ~] (give %chat-update !>([%keys ~(key by inbox)])) - [%all ~] (give %chat-update !>([%initial inbox])) - [%updates ~] ~ - [%mailbox @ *] - ?> (~(has by inbox) t.path) - (give %chat-update !>([%create t.path])) - == - [cards this] - :: - ++ give - |= =cage - ^- (list card) - [%give %fact ~ cage]~ - -- - :: + ++ on-watch on-watch:def ++ on-leave on-leave:def ++ on-peek ~/ %chat-store-peek @@ -163,13 +139,11 @@ ++ on-fail on-fail:def -- :: -:: ~% %chat-store-library ..card ~ |_ bol=bowl:gall ++ met ~(. mdl bol) ++ grp ~(. grpl bol) :: -:: ++ peek-x-envelopes |= pax=path ^- (unit (unit [%noun vase])) @@ -238,27 +212,6 @@ [[len len] (flop out)] == :: -++ poke-json - |= jon=json - ^- (quip card _state) - (poke-chat-action (action:dejs:store jon)) -:: -++ poke-chat-action - |= =action:store - ^- (quip card _state) - ?- -.action - %create (handle-create action) - %delete (handle-delete action) - %read (handle-read action) - %messages (handle-messages action) - %message - ?. =(our.bol author.envelope.action) - (handle-message action) - =^ message-moves state (handle-message action) - =^ read-moves state (handle-read [%read path.action]) - [(weld message-moves read-moves) state] - == -:: ++ poke-import |= arc=* ^- (quip card _state) @@ -266,89 +219,6 @@ :_ sty (migrate-inbox inbox.sty) :: -++ handle-create - |= =action:store - ^- (quip card _state) - ?> ?=(%create -.action) - ?: (~(has by inbox) path.action) [~ state] - :- (send-diff path.action action) - state(inbox (~(put by inbox) path.action *mailbox:store)) -:: -++ handle-delete - |= =action:store - ^- (quip card _state) - ?> ?=(%delete -.action) - =/ mailbox=(unit mailbox:store) - (~(get by inbox) path.action) - ?~ mailbox [~ state] - :- (send-diff path.action action) - state(inbox (~(del by inbox) path.action)) -:: -++ handle-message - |= =action:store - ^- (quip card _state) - ?> ?=(%message -.action) - =/ mailbox=(unit mailbox:store) - (~(get by inbox) path.action) - ?~ mailbox - [~ state] - =. letter.envelope.action (evaluate-letter [author letter]:envelope.action) - =^ envelope u.mailbox (prepend-envelope u.mailbox envelope.action) - :_ state(inbox (~(put by inbox) path.action u.mailbox)) - (send-diff path.action action(envelope envelope)) -:: -++ handle-messages - |= act=action:store - ^- (quip card _state) - ?> ?=(%messages -.act) - =/ mailbox=(unit mailbox:store) - (~(get by inbox) path.act) - ?~ mailbox - [~ state] - =. envelopes.act (flop envelopes.act) - =| evaluated-envelopes=(list envelope:store) - |- ^- (quip card _state) - ?~ envelopes.act - :_ state(inbox (~(put by inbox) path.act u.mailbox)) - %+ send-diff path.act - [%messages path.act 0 (lent evaluated-envelopes) evaluated-envelopes] - =. letter.i.envelopes.act (evaluate-letter [author letter]:i.envelopes.act) - =^ envelope u.mailbox (prepend-envelope u.mailbox i.envelopes.act) - =. evaluated-envelopes [envelope evaluated-envelopes] - $(envelopes.act t.envelopes.act) -:: -++ handle-read - |= act=action:store - ^- (quip card _state) - ?> ?=(%read -.act) - =/ mailbox=(unit mailbox:store) (~(get by inbox) path.act) - ?~ mailbox - [~ state] - =. read.config.u.mailbox length.config.u.mailbox - :- (send-diff path.act act) - state(inbox (~(put by inbox) path.act u.mailbox)) -:: -++ evaluate-letter - |= [author=ship =letter:store] - ^- letter:store - =? letter - ?& ?=(%code -.letter) - ?=(~ output.letter) - (team:title our.bol author) - == - =/ =hoon (ream expression.letter) - letter(output (eval:store bol hoon)) - letter -:: -++ prepend-envelope - |= [=mailbox:store =envelope:store] - ^+ [envelope mailbox] - =. number.envelope +(length.config.mailbox) - =: length.config.mailbox +(length.config.mailbox) - envelopes.mailbox [envelope envelopes.mailbox] - == - [envelope mailbox] -:: ++ update-subscribers |= [pax=path =update:store] ^- (list card) @@ -387,13 +257,28 @@ %- poke-graph-store [%0 now.bol %archive-graph rid] :: +++ nobody + ^- @p + (bex 128) +:: +++ path-to-resource + |= =path + ^- resource + ?. ?=([@ @ ~] path) + nobody^(spat path) + =/ m-ship=(unit ship) + (slaw %p i.path) + ?~ m-ship + nobody^(spat path) + [u.m-ship i.t.path] +:: ++ mailbox-to-updates |= [=path =mailbox:store] ^- (list card) =/ app-rid=resource - (path-to-resource:store path) + (path-to-resource path) =/ group-rid=resource - (fall (group-from-app-resource:met %graph app-rid) [nobody:store %bad-group]) + (fall (group-from-app-resource:met %graph app-rid) [nobody %bad-group]) =/ group=(unit group) (scry-group:grp group-rid) :- (add-graph app-rid mailbox) diff --git a/pkg/arvo/app/chat-view.hoon b/pkg/arvo/app/chat-view.hoon index b22728a475..a2943d4bf2 100644 --- a/pkg/arvo/app/chat-view.hoon +++ b/pkg/arvo/app/chat-view.hoon @@ -1,545 +1,35 @@ -:: chat-view [landscape]: +:: chat-view [landscape]: deprecated :: -:: sets up chat JS client, paginates data, and combines commands -:: into semantic actions for the UI -:: -/- *group, - inv=invite-store, - *metadata-store, - *chat-hook, - *metadata-hook, - hook=chat-hook, - contact-view, - pull-hook -/+ *server, default-agent, verb, dbug, - store=chat-store, - view=chat-view, - group-store, - grpl=group, - resource, - mdl=metadata -:: -~% %chat-view-top ..part ~ +/+ default-agent |% -+$ versioned-state - $% state-0 - == -:: -+$ state-0 - $: %0 - ~ - == -+$ poke - $% [%chat-action action:store] - [%group-action action:group-store] - [%chat-hook-action action:hook] - == -:: +$ card card:agent:gall -- :: -=| state-0 -=* state - -:: -%+ verb | -%- agent:dbug ^- agent:gall -=< - ~% %chat-view-agent-core ..poke-handle-http-request ~ - |_ bol=bowl:gall - +* this . - chat-core +> - cc ~(. chat-core bol) - def ~(. (default-agent this %|) bol) - :: - ++ on-init - ^- (quip card _this) - :_ this - :~ :* %pass /srv %agent [our.bol %file-server] - %poke %file-server-action - !>([%serve-dir /'~chat' /app/landscape %.n %.y]) - == - [%pass / %arvo %e %connect [~ /'chat-view'] %chat-view] - [%pass /updates %agent [our.bol %chat-store] %watch /updates] - == - :: - ++ on-poke - ~/ %chat-view-poke - |= [=mark =vase] - ^- (quip card _this) - ?> (team:title our.bol src.bol) - ?+ mark (on-poke:def mark vase) - %handle-http-request - =+ !<([eyre-id=@ta =inbound-request:eyre] vase) - :_ this - %+ give-simple-payload:app eyre-id - %+ require-authorization:app inbound-request - poke-handle-http-request:cc - :: - %json - :_ this - (poke-chat-view-action:cc (action:dejs:view !<(json vase))) - :: - %chat-view-action - :_ this - (poke-chat-view-action:cc !<(action:view vase)) - == - :: - ++ on-watch - ~/ %chat-view-watch - |= =path - ^- (quip card _this) - ?> (team:title our.bol src.bol) - |^ - ?: ?=([%http-response *] path) - [~ this] - ?: =(/primary path) - :: create inbox with 20 messages max per mailbox and send that along - :: then quit the subscription - :_ this - [%give %fact ~ %json !>((update:enjs:store [%initial truncated-inbox]))]~ - (on-watch:def path) - :: - ++ message-limit 20 - :: - ++ truncated-inbox - ^- inbox:store - =/ =inbox:store - =/ our (scot %p our.bol) - =/ now (scot %da now.bol) - .^(inbox:store %gx /[our]/chat-store/[now]/all/noun) - %- ~(run by inbox) - |= =mailbox:store - ^- mailbox:store - [config.mailbox (scag message-limit envelopes.mailbox)] - -- - :: - ++ on-agent - ~/ %chat-view-agent - |= [=wire =sign:agent:gall] - ^- (quip card _this) - ?+ -.sign (on-agent:def wire sign) - %poke-ack - ?. ?=([%join-group @ @ @ @ @ ~] wire) - (on-agent:def wire sign) - ?^ p.sign - (on-agent:def wire sign) - =/ =ship - (slav %p i.t.wire) - =/ ask-history=? - =('y' i.t.t.wire) - =/ rid=resource - (de-path:resource t.t.t.wire) - :_ this - (joined-group:cc rid ship ask-history) - :: - %kick - :_ this - [%pass / %agent [our.bol %chat-store] %watch /updates]~ - :: - %fact - ?+ p.cage.sign (on-agent:def wire sign) - %chat-update - :_ this - (diff-chat-update:cc !<(update:store q.cage.sign)) - == - == - :: - ++ on-arvo - ~/ %chat-view-arvo - |= [=wire =sign-arvo] - ^- (quip card _this) - ?: ?=(%bound +<.sign-arvo) [~ this] - (on-arvo:def wire sign-arvo) - :: - ++ on-save !>(state) - ++ on-load - |= old-vase=vase - ^- (quip card _this) - =/ old ((soft state-0) q.old-vase) - ?^ old [~ this] - :_ this(state [%0 ~]) - :~ [%pass / %arvo %e %disconnect [~ /'~chat']] - [%pass / %arvo %e %connect [~ /'chat-view'] %chat-view] - :* %pass /srv %agent [our.bol %file-server] - %poke %file-server-action - !>([%serve-dir /'~chat' /app/landscape %.n %.y]) - == - == - :: - ++ on-leave on-leave:def - ++ on-peek on-peek:def - ++ on-fail on-fail:def - -- -:: -:: -~% %chat-view-library ..card ~ |_ bol=bowl:gall -++ grp ~(. grpl bol) -++ md ~(. mdl bol) ++* this . + def ~(. (default-agent this %|) bol) :: -++ poke-handle-http-request - |= =inbound-request:eyre - ^- simple-payload:http - =+ url=(parse-request-line url.request.inbound-request) - ?+ site.url not-found:gen - [%'chat-view' %paginate @t @t *] - =/ start (need (rush i.t.t.site.url dem)) - =/ end (need (rush i.t.t.t.site.url dem)) - =/ pax t.t.t.t.site.url - =/ envelopes (envelope-scry [(scot %ud start) (scot %ud end) pax]) - %- json-response:gen - %- update:enjs:store - [%messages pax start end envelopes] +++ on-init + ^- (quip card _this) + :_ this + :~ :* %pass /srv %agent [our.bol %file-server] + %poke %file-server-action + !>([%serve-dir /'~chat' /app/landscape %.n %.y]) + == == :: -++ poke-json - |= jon=json - ^- (list card) - ?> (team:title our.bol src.bol) - (poke-chat-view-action (action:dejs:view jon)) +++ on-poke on-poke:def +++ on-watch on-watch:def +++ on-agent on-agent:def +++ on-arvo on-arvo:def +++ on-save !>(~) +++ on-load + |= old-vase=vase + ^- (quip card _this) + [~ this] :: -++ poke-chat-view-action - |= act=action:view - ^- (list card) - |^ - ?> (team:title our.bol src.bol) - ?- -.act - %create - ?> ?=(^ app-path.act) - ?> ?| =(+:group-path.act app-path.act) - =(~(tap in members.act) ~) - == - ?^ (chat-scry app-path.act) - ~& %chat-already-exists - ~ - %- zing - :~ %- create-group - :* group-path.act - app-path.act - policy.act - members.act - title.act - description.act - managed.act - == - (create-metadata title.act description.act group-path.act app-path.act) - (create-chat app-path.act allow-history.act) - == - :: - %delete - ?> ?=(^ app-path.act) - :: always just delete the chat from chat-store - :: - :+ (chat-hook-poke [%remove app-path.act]) - (chat-poke [%delete app-path.act]) - :: if we still have metadata for the chat, remove it, and the associated - :: group if it's unmanaged. - :: - :: we aren't guaranteed to have metadata: the chat might have been - :: deleted by the host, which pushes metadata deletion down to us. - :: - =/ maybe-group-path - (maybe-group-from-chat app-path.act) - ?~ maybe-group-path - ~ - =* group-path u.maybe-group-path - =/ rid=resource - (de-path:resource group-path) - =/ maybe-group - (scry-group:grp rid) - =/ hidden - ?~ maybe-group - %.n - hidden.u.maybe-group - %- zing - :~ ?. (is-creator group-path %chat app-path.act) - ~ - [(metadata-poke [%remove group-path [%chat app-path.act]])]~ - :: - ?. hidden - ~ - :~ (group-proxy-poke %remove-members rid (sy our.bol ~)) - (group-poke [%remove-group rid ~]) - (metadata-hook-poke [%remove group-path]) - (metadata-store-poke [%remove group-path [%chat app-path.act]]) - == - == - :: - %invite - =/ =group-path - (need (maybe-group-from-chat app-path.act)) - =/ rid=resource - (de-path:resource group-path) - =/ =group - (need (scry-group:grp rid)) - ?> ?=(%invite -.policy.group) - :- (group-poke %change-policy rid %invite %add-invites ships.act) - %+ turn - ~(tap in ships.act) - |= =ship - (send-invite group-path app-path.act ship) - :: - %join - =/ group-path - (maybe-group-from-chat app-path.act) - =/ group - ?~ group-path - ~ - (scry-group-path:grp u.group-path) - ?: &(?=(^ group) =(hidden.u.group %.n)) - ~[(chat-hook-poke %add-synced ship.act app-path.act ask-history.act)] - =/ rid=resource - (de-path:resource ship+app-path.act) - ?: =(our.bol entity.rid) ~ - =/ =cage - :- %group-update - !> ^- action:group-store - [%add-members rid (sy our.bol ~)] - :: we need this info in the wire to continue the flow after the - :: poke ack - =/ =wire - :- %join-group - [(scot %p ship.act) ?:(ask-history.act %y %n) ship+app-path.act] - [%pass wire %agent [entity.rid %group-push-hook] %poke cage]~ - :: - %groupify - =* app-path app-path.act - =/ group-path - (snag 0 (groups-from-resource:md %chat app-path)) - =/ scry-pax=path - /metadata/[(scot %t (spat group-path))]/chat/[(scot %t (spat app-path))] - =/ =metadata - (need (scry-for (unit metadata) %metadata-store scry-pax)) - =/ old-rid=resource - (de-path:resource group-path) - ?< (is-managed:grp old-rid) - ?~ existing.act - :: just create contacts object for group - ~[(contact-view-poke %groupify old-rid title.metadata description.metadata)] - :: change associations - =* group-path group-path.u.existing.act - =/ rid=resource - (de-path:resource group-path) - =/ old-group=group - (need (scry-group:grp old-rid)) - =/ =group - (need (scry-group:grp rid)) - =/ ships=(set ship) - (~(dif in members.old-group) members.group) - :* (metadata-store-poke %remove ship+app-path %chat app-path) - (metadata-store-poke %add group-path [%chat app-path] metadata) - (group-poke %remove-group old-rid ~) - ?. inclusive.u.existing.act - ~ - :- (group-poke %add-members rid ships) - %+ turn - ~(tap in ships) - |= =ship - (send-invite group-path app-path ship) - == - == - :: - ++ create-chat - |= [=path history=?] - ^- (list card) - :~ (chat-poke [%create path]) - (chat-hook-poke [%add-owned path history]) - == - :: - ++ create-group - |= [=path app-path=path =policy ships=(set ship) title=@t desc=@t managed=?] - ^- (list card) - ?^ (scry-group-path:grp path) ~ - =/ rid=resource - (de-path:resource path) - ?> =(our.bol entity.rid) - :: do not create a contacts object if this is unmanaged - :: - :- - ?. managed - (group-poke %add-group rid policy %.y) - (contact-view-poke %create name.rid policy title desc) - %+ murn ~(tap in ships) - |= =ship - ^- (unit card) - ?: =(ship our.bol) ~ - `(send-invite path app-path ship) - :: - ++ create-metadata - |= [title=@t description=@t group-path=path app-path=path] - ^- (list card) - =/ =metadata - %* . *metadata - title title - description description - date-created now.bol - creator - (slav %p (snag 0 app-path)) - == - :~ (metadata-poke [%add group-path [%chat app-path] metadata]) - (metadata-hook-poke [%add-owned group-path]) - == - :: - ++ contact-view-poke - |= act=contact-view-action:contact-view - ^- card - [%pass / %agent [our.bol %contact-view] %poke %contact-view-action !>(act)] - :: - ++ metadata-poke - |= act=metadata-action - ^- card - [%pass / %agent [our.bol %metadata-hook] %poke %metadata-action !>(act)] - :: - ++ metadata-store-poke - |= act=metadata-action - ^- card - [%pass / %agent [our.bol %metadata-store] %poke %metadata-action !>(act)] - :: - ++ send-invite - |= [group-path=path app-path=path =ship] - ^- card - =/ managed=? - !=(ship+app-path group-path) - =/ =invite:inv - :* our.bol - ?:(managed %contact-hook %chat-hook) - (de-path:resource ?:(managed group-path ship+app-path)) - ship '' - == - =/ act=action:inv - [%invite ?:(managed %contacts %chat) (shaf %msg-uid eny.bol) invite] - [%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)] - :: - ++ chat-scry - |= pax=path - ^- (unit mailbox:store) - =. pax - ;: weld - /(scot %p our.bol)/chat-store/(scot %da now.bol)/mailbox - pax - /noun - == - .^((unit mailbox:store) %gx pax) - :: - ++ maybe-group-from-chat - |= app-path=path - ^- (unit path) - ?. .^(? %gu (scot %p our.bol) %metadata-store (scot %da now.bol) ~) - ?: ?=([@ ^] app-path) - ~& [%assuming-ported-legacy-chat app-path] - `[%'~' app-path] - ~& [%weird-chat app-path] - !! - =/ resource-indices - .^ (jug md-resource group-path) - %gy - (scot %p our.bol) - %metadata-store - (scot %da now.bol) - /resource-indices - == - =/ groups=(set path) - %+ fall - (~(get by resource-indices) [%chat app-path]) - *(set path) - ?~ groups ~ - `n.groups - :: - ++ group-from-chat - (cork maybe-group-from-chat need) - :: - ++ is-managed - |= =path - ^- ? - ?> ?=(^ path) - !=(i.path '~') - :: - ++ is-creator - |= [group-path=path app-name=@ta app-path=path] - ^- ? - =/ meta=(unit metadata) - .^ (unit metadata) - %gx - (scot %p our.bol) - %metadata-store - (scot %da now.bol) - %metadata - (scot %t (spat group-path)) - app-name - (scot %t (spat app-path)) - /noun - == - ?~ meta !! - =(our.bol creator.u.meta) - -- -:: +joined-group: Successfully joined unmanaged group, continue flow -:: -++ joined-group - |= [rid=resource =ship ask-history=?] - ^- (list card) - =/ =path - (en-path:resource rid) - ?> ?=(^ path) - :~ (group-pull-hook-poke %add ship rid) - (metadata-hook-poke %add-synced ship path) - (chat-hook-poke %add-synced ship t.path ask-history) - == -:: -++ diff-chat-update - |= upd=update:store - ^- (list card) - [%give %fact ~[/primary] %json !>((update:enjs:store upd))]~ -:: -:: +utilities -:: -++ chat-poke - |= act=action:store - ^- card - [%pass / %agent [our.bol %chat-store] %poke %chat-action !>(act)] -:: -++ group-poke - |= upd=update:group-store - ^- card - [%pass / %agent [our.bol %group-store] %poke %group-update !>(upd)] -++ group-pull-hook-poke - |= act=action:pull-hook - ^- card - [%pass / %agent [our.bol %group-pull-hook] %poke %pull-hook-action !>(act)] -:: -++ group-proxy-poke - |= act=action:group-store - ^- card - [%pass / %agent [entity.resource.act %group-push-hook] %poke %group-update !>(act)] -:: -++ chat-hook-poke - |= act=action:hook - ^- card - [%pass / %agent [our.bol %chat-hook] %poke %chat-hook-action !>(act)] -:: -++ metadata-hook-poke - |= act=metadata-hook-action - ^- card - :* %pass / %agent - [our.bol %metadata-hook] - %poke %metadata-hook-action - !>(act) - == -:: -++ envelope-scry - |= pax=path - ^- (list envelope:store) - (scry-for (list envelope:store) %chat-store [%envelopes pax]) -:: - -:: -++ scry-for - |* [=mold app=term =path] - .^ mold - %gx - (scot %p our.bol) - app - (scot %da now.bol) - (snoc `^path`path %noun) - == +++ on-leave on-leave:def +++ on-peek on-peek:def +++ on-fail on-fail:def -- diff --git a/pkg/arvo/lib/chat-hook.hoon b/pkg/arvo/lib/chat-hook.hoon deleted file mode 100644 index 4cf6ffcd96..0000000000 --- a/pkg/arvo/lib/chat-hook.hoon +++ /dev/null @@ -1,51 +0,0 @@ -/- sur=chat-hook -^? -=< [sur .] -=, sur -|% -:: -++ enjs - |% - ++ update - |= upd=^update - =, enjs:format - ^- json - %+ frond %chat-hook-update - %- pairs - %+ turn ~(tap by synced.upd) - |= [pax=^path shp=^ship] - ^- [cord json] - [(spat pax) s+(scot %p shp)] - -- -++ dejs - |% - :: - ++ action - |= jon=json - ^- ^action - =, dejs:format - =< (parse-json jon) - |% - :: - ++ parse-json - %- of - :~ [%add-owned add-owned] - [%add-synced add-synced] - [%remove pa] - == - :: - ++ add-owned - %- ot - :~ [%path pa] - [%allow-history bo] - == - :: - ++ add-synced - %- ot - :~ [%ship (su ;~(pfix sig fed:ag))] - [%path pa] - [%ask-history bo] - == - -- - -- --- diff --git a/pkg/arvo/lib/chat-store.hoon b/pkg/arvo/lib/chat-store.hoon deleted file mode 100644 index f58ba2ef0e..0000000000 --- a/pkg/arvo/lib/chat-store.hoon +++ /dev/null @@ -1,242 +0,0 @@ - -/- sur=chat-store -/+ resource -^? -=< [sur .] -=, sur -|% -:: -++ nobody - ^- @p - (bex 128) -:: -++ path-to-resource - |= =path - ^- resource - ?. ?=([@ @ ~] path) - nobody^(spat path) - =/ m-ship=(unit ship) - (slaw %p i.path) - ?~ m-ship - nobody^(spat path) - [u.m-ship i.t.path] -:: -++ enjs - =, enjs:format - |% - :: - ++ letter - |= =^letter - ^- json - ?- -.letter - %text - (frond %text s+text.letter) - :: - %me - (frond %me s+narrative.letter) - :: - %url - (frond %url s+url.letter) - :: - %code - %+ frond %code - %- pairs - :- [%expression s+expression.letter] - :_ ~ - :- %output - :: virtualize output rendering, +tank:enjs:format might crash - :: - =/ result=(each (list json) tang) - (mule |.((turn output.letter tank))) - ?- -.result - %& a+p.result - %| a+[a+[%s '[[output rendering error]]']~]~ - == - == - :: - ++ envelope - |= =^envelope - ^- json - %- pairs - :~ [%uid s+(scot %uv uid.envelope)] - [%number (numb number.envelope)] - [%author (ship author.envelope)] - [%when (time when.envelope)] - [%letter (letter letter.envelope)] - == - :: - ++ config - |= =^config - ^- json - %- pairs - :~ [%length (numb length.config)] - [%read (numb read.config)] - == - :: - ++ update - |= upd=^update - ^- json - %+ frond %chat-update - %- pairs - :_ ~ - ?- -.upd - %initial - :- %initial - %- pairs - %+ turn ~(tap by inbox.upd) - |= [pax=^path =mailbox] - ^- [cord json] - :- (spat pax) - %- pairs - :~ [%envelopes [%a (turn envelopes.mailbox envelope)]] - [%config (config config.mailbox)] - == - :: - %message - :- %message - %- pairs - :~ [%path (path path.upd)] - [%envelope (envelope envelope.upd)] - == - :: - %messages - :- %messages - %- pairs - :~ [%path (path path.upd)] - [%start (numb start.upd)] - [%end (numb end.upd)] - [%envelopes [%a (turn envelopes.upd envelope)]] - == - :: - %read - [%read (pairs [%path (path path.upd)]~)] - :: - %create - [%create (pairs [%path (path path.upd)]~)] - :: - %delete - [%delete (pairs [%path (path path.upd)]~)] - :: - %keys - :- %keys - :- %a - %+ turn ~(tap by keys.upd) - |= pax=^path (path pax) - == - -- -++ dejs - =, dejs:format - |% - :: - ++ action - |= jon=json - ^- ^action - =< (parse-json jon) - |% - ++ parse-json - %- of - :~ [%create create] - [%delete delete] - [%message message] - [%messages messages] - [%read read] - == - :: - ++ create - (ot [%path pa]~) - :: - ++ delete - (ot [%path pa]~) - :: - ++ message - %- ot - :~ [%path pa] - [%envelope envelope] - == - :: - ++ messages - %- ot - :~ [%path pa] - [%envelopes (ar envelope)] - == - :: - ++ read - (ot [%path pa] ~) - :: - ++ envelope - %- ot - :~ [%uid serial] - [%number ni] - [%author (su ;~(pfix sig fed:ag))] - [%when di] - [%letter letter] - == - :: - ++ letter - %- of - :~ [%text so] - [%url so] - [%code eval] - [%me so] - == - :: - ++ serial - ^- $-(json ^serial) - (cu (cury slav %uv) so) - :: - ++ re :: recursive reparsers - |* [gar=* sef=_|.(fist:dejs-soft:format)] - |= jon=json - ^- (unit _gar) - =- ~! gar ~! (need -) - - ((sef) jon) - :: - ++ dank :: tank - ^- $-(json (unit tank)) - =, ^? dejs-soft:format - %+ re *tank |. ~+ - %- of :~ - leaf+sa - palm+(ot style+(ot mid+sa cap+sa open+sa close+sa ~) lines+(ar dank) ~) - rose+(ot style+(ot mid+sa open+sa close+sa ~) lines+(ar dank) ~) - == - :: %exp speech - ++ eval - ::: extract contents of an %exp speech, evaluating - ::: the {exp} if there is no {res} yet. - :: - |= a=json - ^- [cord (list tank)] - =, ^? dejs-soft:format - =+ exp=((ot expression+so ~) a) - %- need - ?~ exp [~ '' ~] - :+ ~ u.exp - ::NOTE when sending, if output is an empty list, chat-store will evaluate - (fall ((ot output+(ar dank) ~) a) ~) - :: - -- - -- -:: -++ eval - |= [=bowl:gall =hoon] - ^- (list tank) - =/ fowl=[our=@p now=@da eny=@uvJ] - :+ our.bowl - now.bowl - (shaz (cat 3 (mix [now eny]:bowl) %eny)) - :: - =/ subject [fowl ..zuse] - =/ minted=(each [=type =nock] (list tank)) - %- mule |. - (~(mint ut -:!>(subject)) %noun hoon) - ?: ?=(%| -.minted) p.minted - =/ =toon - (mock [subject nock.p.minted] |=(^ ~)) - ?- -.toon - %0 [(sell type.p.minted p.toon) ~] - %1 :- leaf+".^ unsupported in chat eval" - (turn ;;((list path) p.toon) smyt) - %2 [leaf+"crash!" p.toon] - == --- diff --git a/pkg/arvo/lib/chat-view.hoon b/pkg/arvo/lib/chat-view.hoon deleted file mode 100644 index 2d2baff0d0..0000000000 --- a/pkg/arvo/lib/chat-view.hoon +++ /dev/null @@ -1,56 +0,0 @@ -/- sur=chat-view, *rw-security -/+ group-store -^? -=< [sur .] -=, sur -|% -++ dejs - |% - ++ action - |= jon=json - ^- ^action - =, dejs:format - =< (parse-json jon) - |% - ++ parse-json - %- of - :~ [%create create] - [%delete delete] - [%join join] - [%groupify groupify] - [%invite invite] - == - :: - ++ create - %- ot - :~ [%title so] - [%description so] - [%app-path pa] - [%group-path pa] - [%policy policy:dejs:group-store] - [%members (as (su ;~(pfix sig fed:ag)))] - [%allow-history bo] - [%managed bo] - == - :: - ++ delete - (ot [%app-path pa]~) - :: - ++ join - %- ot - :~ [%ship (su ;~(pfix sig fed:ag))] - [%app-path pa] - [%ask-history bo] - == - :: - ++ groupify - =- (ot [%app-path pa] [%existing -] ~) - (mu (ot [%group-path pa] [%inclusive bo] ~)) - ++ invite - %- ot - :~ app-path+pa - ships+(as (su ;~(pfix sig fed:ag))) - == - -- - -- --- diff --git a/pkg/arvo/mar/chat/action.hoon b/pkg/arvo/mar/chat/action.hoon deleted file mode 100644 index 9f9565eb84..0000000000 --- a/pkg/arvo/mar/chat/action.hoon +++ /dev/null @@ -1,13 +0,0 @@ -/+ *chat-store -|_ act=action -++ grad %noun -++ grow - |% - ++ noun act - -- -++ grab - |% - ++ noun action - ++ json action:dejs - -- --- diff --git a/pkg/arvo/mar/chat/hook-action.hoon b/pkg/arvo/mar/chat/hook-action.hoon deleted file mode 100644 index 03564a41b3..0000000000 --- a/pkg/arvo/mar/chat/hook-action.hoon +++ /dev/null @@ -1,14 +0,0 @@ -/+ *chat-hook -|_ act=action -++ grad %noun -++ grow - |% - ++ noun act - -- -++ grab - |% - ++ noun action - ++ json action:dejs - -- --- - diff --git a/pkg/arvo/mar/chat/hook-update.hoon b/pkg/arvo/mar/chat/hook-update.hoon deleted file mode 100644 index b5e31a9ef0..0000000000 --- a/pkg/arvo/mar/chat/hook-update.hoon +++ /dev/null @@ -1,15 +0,0 @@ -/+ *chat-hook -|_ upd=update -++ grad %noun -++ grow - |% - ++ noun upd - ++ json (update:enjs upd) - -- -:: -++ grab - |% - ++ noun update - -- -:: --- diff --git a/pkg/arvo/mar/chat/update.hoon b/pkg/arvo/mar/chat/update.hoon deleted file mode 100644 index b5dab99552..0000000000 --- a/pkg/arvo/mar/chat/update.hoon +++ /dev/null @@ -1,15 +0,0 @@ -/+ *chat-store -|_ upd=update -++ grad %noun -++ grow - |% - ++ noun upd - ++ json (update:enjs upd) - -- -:: -++ grab - |% - ++ noun update - -- -:: --- diff --git a/pkg/arvo/mar/chat/view-action.hoon b/pkg/arvo/mar/chat/view-action.hoon deleted file mode 100644 index cc33eb67bd..0000000000 --- a/pkg/arvo/mar/chat/view-action.hoon +++ /dev/null @@ -1,13 +0,0 @@ -/+ *chat-view -|_ act=action -++ grad %noun -++ grow - |% - ++ noun act - -- -++ grab - |% - ++ noun action - ++ json action:dejs - -- ---