From 6d4a694aeb4d89c9d6d07196a8d2415f1b571a5d Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Tue, 21 Apr 2020 14:58:37 -0400 Subject: [PATCH] t groups + contacts: make removes completely clean up state --- pkg/arvo/app/contact-hook.hoon | 64 +++++++++---------- pkg/arvo/app/contact-store.hoon | 2 +- pkg/arvo/app/contact-view.hoon | 4 +- pkg/arvo/app/group-hook.hoon | 50 ++++++--------- pkg/interface/groups/src/js/api.js | 11 +--- .../src/js/components/lib/contact-card.js | 3 +- 6 files changed, 58 insertions(+), 76 deletions(-) diff --git a/pkg/arvo/app/contact-hook.hoon b/pkg/arvo/app/contact-hook.hoon index ad7b53c8c..e34b2ad8b 100644 --- a/pkg/arvo/app/contact-hook.hoon +++ b/pkg/arvo/app/contact-hook.hoon @@ -19,7 +19,7 @@ +$ state-zero [%0 state-base] +$ state-one [%1 state-base] +$ state-base - $: synced=(map path ship) + $: =synced invite-created=_| == -- @@ -125,31 +125,29 @@ ++ poke-contact-action |= act=contact-action ^- (quip card _state) - |^ :_ state ?+ -.act !! %edit (handle-contact-action path.act ship.act act) %add (handle-contact-action path.act ship.act act) %remove (handle-contact-action path.act ship.act act) == - :: - ++ handle-contact-action - |= [=path =ship act=contact-action] - ^- (list card) - :: local - ?: (team:title our.bol src.bol) - ?. (~(has by synced) path) ~ - =/ shp ?:(=(path /~/default) our.bol (~(got by synced) path)) - =/ appl ?:(=(shp our.bol) %contact-store %contact-hook) - [%pass / %agent [shp appl] %poke %contact-action !>(act)]~ - :: foreign - =/ shp (~(got by synced) path) - ?. |(=(shp our.bol) =(src.bol ship)) ~ - :: scry group to check if ship is a member - =/ =group (need (group-scry path)) - ?. (~(has in group) shp) ~ - [%pass / %agent [our.bol %contact-store] %poke %contact-action !>(act)]~ - -- +:: +++ handle-contact-action + |= [=path =ship act=contact-action] + ^- (list card) + :: local + ?: (team:title our.bol src.bol) + ?. (~(has by synced) path) ~ + =/ shp ?:(=(path /~/default) our.bol (~(got by synced) path)) + =/ appl ?:(=(shp our.bol) %contact-store %contact-hook) + [%pass / %agent [shp appl] %poke %contact-action !>(act)]~ + :: foreign + =/ shp (~(got by synced) path) + ?. |(=(shp our.bol) =(src.bol ship)) ~ + :: scry group to check if ship is a member + =/ =group (need (group-scry path)) + ?. (~(has in group) shp) ~ + [%pass / %agent [our.bol %contact-store] %poke %contact-action !>(act)]~ :: ++ poke-hook-action |= act=contact-hook-action @@ -163,7 +161,7 @@ =. synced (~(put by synced) path.act our.bol) :_ state :~ [%pass contact-path %agent [our.bol %contact-store] %watch contact-path] - [%give %fact ~ %contact-hook-update !>([%initial synced])] + [%give %fact [/synced]~ %contact-hook-update !>([%initial synced])] == :: %add-synced @@ -173,7 +171,7 @@ =/ contact-path [%contacts path.act] :_ state :~ [%pass contact-path %agent [ship.act %contact-hook] %watch contact-path] - [%give %fact ~ %contact-hook-update !>([%initial synced])] + [%give %fact [/synced]~ %contact-hook-update !>([%initial synced])] == :: %remove @@ -185,16 +183,19 @@ %- zing :~ (pull-wire [%contacts path.act]) [%give %kick ~[[%contacts path.act]] ~]~ - [%give %fact ~ %contact-hook-update !>([%initial synced])]~ + [%give %fact [/synced]~ %contact-hook-update !>([%initial synced])]~ == ?. |(=(u.ship src.bol) (team:title our.bol src.bol)) :: if neither ship = source or source = us, do nothing [~ state] :: delete a foreign ship's path + =/ cards + (handle-contact-action path.act our.bol [%remove path.act our.bol]) :_ state(synced (~(del by synced) path.act)) %- zing :~ (pull-wire [%contacts path.act]) - [%give %fact ~ %contact-hook-update !>([%initial synced])]~ + [%give %fact [/synced]~ %contact-hook-update !>([%initial synced])]~ + cards == == :: @@ -207,10 +208,7 @@ =/ =group (need (group-scry pax)) ?> (~(has in group) src.bol) =/ contacts (need (contacts-scry pax)) - :~ :* - %give %fact ~ %contact-update - !>([%contacts pax contacts]) - == == + [%give %fact ~ %contact-update !>([%contacts pax contacts])]~ :: ++ watch-synced |= pax=path @@ -324,13 +322,15 @@ == :: %add - =/ owner (~(got by synced) path.fact) - ?> |(=(owner src.bol) =(src.bol ship.fact)) + =/ owner (~(get by synced) path.fact) + ?~ owner ~ + ?> |(=(u.owner src.bol) =(src.bol ship.fact)) ~[(contact-poke [%add path.fact ship.fact contact.fact])] :: %remove - =/ owner (~(got by synced) path.fact) - ?> |(=(owner src.bol) =(src.bol ship.fact)) + =/ owner (~(get by synced) path.fact) + ?~ owner ~ + ?> |(=(u.owner src.bol) =(src.bol ship.fact)) %+ welp :~ (group-poke [%remove [ship.fact ~ ~] path.fact]) (contact-poke [%remove path.fact ship.fact]) diff --git a/pkg/arvo/app/contact-store.hoon b/pkg/arvo/app/contact-store.hoon index 7792e7918..398ef15b0 100644 --- a/pkg/arvo/app/contact-store.hoon +++ b/pkg/arvo/app/contact-store.hoon @@ -142,7 +142,7 @@ |= [=path =ship] ^- (quip card _state) =/ contacts (~(got by rolodex) path) - ?> (~(has by contacts) ship) + ?. (~(has by contacts) ship) [~ state] =. contacts (~(del by contacts) ship) :- (send-diff path [%remove path ship]) state(rolodex (~(put by rolodex) path contacts)) diff --git a/pkg/arvo/app/contact-view.hoon b/pkg/arvo/app/contact-view.hoon index 9c85c135d..1bfd5a69a 100644 --- a/pkg/arvo/app/contact-view.hoon +++ b/pkg/arvo/app/contact-view.hoon @@ -147,9 +147,9 @@ :: %delete %+ weld - :~ (group-poke [%unbundle path.act]) + :~ (contact-hook-poke [%remove path.act]) + (group-poke [%unbundle path.act]) (contact-poke [%delete path.act]) - (contact-hook-poke [%remove path.act]) == (delete-metadata path.act) :: diff --git a/pkg/arvo/app/group-hook.hoon b/pkg/arvo/app/group-hook.hoon index 47ccc1d42..7cfc83188 100644 --- a/pkg/arvo/app/group-hook.hoon +++ b/pkg/arvo/app/group-hook.hoon @@ -38,18 +38,12 @@ ^- (quip card _this) =/ old !<(state-zero vase) :_ this(state old) - %+ murn - ~(tap by synced.old) + %+ murn ~(tap by synced.old) |= [=path =ship] ^- (unit card) - =/ =wire - [(scot %p ship) %group path] - =/ =term - ?: =(our.bowl ship) - %group-store - %group-hook - ?: (~(has by wex.bowl) [wire ship term]) - ~ + =/ =wire [(scot %p ship) %group path] + =/ =term ?:(=(our.bowl ship) %group-store %group-hook) + ?: (~(has by wex.bowl) [wire ship term]) ~ `[%pass wire %agent [ship term] %watch [%group path]] :: ++ on-leave on-leave:def @@ -173,10 +167,9 @@ %remove [(update-subscribers [%group pax.diff] diff) state] :: %unbundle - :_ state(synced (~(del by synced.state) pax.diff)) - %+ snoc - (update-subscribers [%group pax.diff] diff) - [%give %kick [%group pax.diff]~ ~] + =/ ship (~(get by synced.state) pax.diff) + ?~ ship [~ state] + (poke-group-hook-action [%remove pax.diff]) == :: ++ handle-foreign @@ -185,7 +178,6 @@ ?- -.diff %keys [~ state] %bundle [~ state] - :: %path :_ state ?~ pax.diff ~ @@ -219,23 +211,24 @@ [(group-poke pax.diff diff)]~ :: %remove - :_ state - ?~ pax.diff ~ + ?~ pax.diff [~ state] =/ ship (~(get by synced.state) pax.diff) - ?~ ship ~ - ?. =(src.bol u.ship) ~ - [(group-poke pax.diff diff)]~ + ?~ ship [~ state] + ?. =(src.bol u.ship) [~ state] + ?. (~(has in members.diff) our.bol) [~ state] + =/ changes (poke-group-hook-action [%remove pax.diff]) + :_ +.changes + %+ welp -.changes + :~ (group-poke pax.diff diff) + (group-poke pax.diff [%unbundle pax.diff]) + == :: %unbundle - ?~ pax.diff - [~ state] + ?~ pax.diff [~ state] =/ ship (~(get by synced.state) pax.diff) - ?~ ship - [~ state] - ?. =(src.bol u.ship) - [~ state] - :_ state(synced (~(del by synced.state) pax.diff)) - [(group-poke pax.diff diff)]~ + ?~ ship [~ state] + ?. =(src.bol u.ship) [~ state] + (poke-group-hook-action [%remove pax.diff]) == :: ++ group-poke @@ -262,5 +255,4 @@ ?: =(u.shp our.bol) [%pass wir %agent [our.bol %group-store] %leave ~]~ [%pass wir %agent [u.shp %group-hook] %leave ~]~ -:: -- diff --git a/pkg/interface/groups/src/js/api.js b/pkg/interface/groups/src/js/api.js index 6e56ca9ac..70a6a69b9 100644 --- a/pkg/interface/groups/src/js/api.js +++ b/pkg/interface/groups/src/js/api.js @@ -11,8 +11,7 @@ class UrbitApi { this.bindPaths = []; this.contactHook = { - edit: this.contactEdit.bind(this), - remove: this.contactRemove.bind(this) + edit: this.contactEdit.bind(this) }; this.contactView = { @@ -108,14 +107,6 @@ class UrbitApi { return this.action("contact-hook", "contact-action", data); } - contactRemove(path, ship) { - return this.contactHookAction({ - remove: { - path, ship - } - }); - } - contactEdit(path, ship, editField) { /* editField can be... {nickname: ''} diff --git a/pkg/interface/groups/src/js/components/lib/contact-card.js b/pkg/interface/groups/src/js/components/lib/contact-card.js index dff7b4aa4..de3189918 100644 --- a/pkg/interface/groups/src/js/components/lib/contact-card.js +++ b/pkg/interface/groups/src/js/components/lib/contact-card.js @@ -317,13 +317,12 @@ export class ContactCard extends Component { ); this.setState({awaiting: true, type: "Removing from group"}, (() => { - api.contactHook.remove(props.path, `~${props.ship}`).then(() => { + api.contactView.delete(props.path).then(() => { let destination = (props.ship === window.ship) ? "" : props.path; this.setState({awaiting: false}); props.history.push(`/~groups${destination}`); }); - api.contactView.delete(props.path); })) }