Merge pull request #3986 from urbit/la/archive-graph-on-leave

observe-hook: add new thread to leave graphs upon removing a group
This commit is contained in:
L 2020-12-01 18:12:05 -06:00 committed by GitHub
commit 41074e3742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 146 additions and 33 deletions

View File

@ -181,22 +181,7 @@
~[(add-pending rid ship.act)]
::
%delete
=/ rid=resource
(de-path:resource path.act)
=/ group-pokes=(list card)
?: =(our.bol entity.rid)
~[(group-push-poke %remove rid)]
:~ (group-proxy-poke %remove-members rid (sy our.bol ~))
(group-pull-poke %remove rid)
==
;: weld
group-pokes
:~ (contact-hook-poke [%remove path.act])
(group-poke [%remove-group rid ~])
(contact-poke [%delete path.act])
==
(delete-metadata path.act)
==
~
::
%remove
=/ rid=resource
@ -357,13 +342,6 @@
(metadata-hook-poke [%add-owned path])
==
::
++ delete-metadata
|= =path
^- (list card)
:~ (metadata-poke [%remove path [%contacts path]])
(metadata-hook-poke [%remove path])
==
::
++ all-scry
^- rolodex
.^(rolodex %gx /(scot %p our.bol)/contact-store/(scot %da now.bol)/all/noun)

View File

@ -10,10 +10,13 @@
+$ card card:agent:gall
+$ versioned-state
$% state-0
state-1
==
::
+$ serial @uv
+$ state-0 [%0 observers=(map serial observer:sur)]
+$ state-1 [%1 observers=(map serial observer:sur)]
::
++ got-by-val
|= [a=(map serial observer:sur) b=observer:sur]
^- serial
@ -24,7 +27,7 @@
--
::
%- agent:dbug
=| state-0
=| state-1
=* state -
::
^- agent:gall
@ -35,8 +38,14 @@
++ on-init
|^ ^- (quip card _this)
:_ this
:_ ~
(act /inv-gra [%watch %invite-store /invitatory/graph %invite-accepted-graph])
:~ %+ act
/inv-gra
[%watch %invite-store /invitatory/graph %invite-accepted-graph]
::
%+ act
/grp-gra
[%watch %group-store /groups %group-on-leave]
==
::
++ act
|= [=wire =action:sur]
@ -56,7 +65,17 @@
++ on-load
|= old-vase=vase
^- (quip card _this)
`this(state !<(state-0 old-vase))
=/ old-state !<(versioned-state old-vase)
?- -.old-state
%1 `this(state old-state)
::
%0
=. state [%1 observers.old-state]
%+ on-poke
%observe-action
!> ^- action:sur
[%watch %group-store /groups %group-on-leave]
==
::
++ on-poke
|= [=mark =vase]

View File

@ -417,6 +417,7 @@
::
++ remove-group
|= =json
^- [resource ~]
?> ?=(%o -.json)
=/ rid=resource
(dejs:resource (~(got by p.json) 'resource'))

View File

@ -219,6 +219,25 @@
;< ~ bind:m (send-raw-card card)
(take-poke-ack /poke)
::
++ raw-poke
|= [=dock =cage]
=/ m (strand ,~)
^- form:m
=/ =card:agent:gall [%pass /poke %agent dock %poke cage]
;< ~ bind:m (send-raw-card card)
=/ m (strand ,~)
^- form:m
|= tin=strand-input:strand
?+ in.tin `[%skip ~]
~
`[%wait ~]
::
[~ %agent * %poke-ack *]
?. =(/poke wire.u.in.tin)
`[%skip ~]
`[%done ~]
==
::
++ poke-our
|= [=term =cage]
=/ m (strand ,~)

View File

@ -0,0 +1,94 @@
/- spider, grp=group-store, gra=graph-store, met=metadata-store, con=contact-store
/+ strandio, res=resource
::
=* strand strand:spider
=* raw-poke raw-poke:strandio
=* scry scry:strandio
::
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=+ !<([=update:grp ~] arg)
?. ?=(%remove-group -.update)
(pure:m !>(~))
;< =bowl:spider bind:m get-bowl:strandio
:: tell group host to remove us as member
::
;< ~ bind:m
%+ raw-poke
[entity.resource.update %group-push-hook]
:- %group-update
!> ^- update:grp
[%remove-members resource.update (silt [our.bowl ~])]
:: stop serving or syncing group updates
::
;< ~ bind:m
%+ raw-poke
[our.bowl %group-push-hook]
:- %push-hook-action
!>([%remove resource.update])
;< ~ bind:m
%+ raw-poke
[our.bowl %group-pull-hook]
:- %pull-hook-action
!>([%remove resource.update])
:: stop serving or syncing contacts associated with group
::
;< ~ bind:m
%+ raw-poke
[our.bowl %contact-hook]
:- %contact-hook-action
!>([%remove (en-path:res resource.update)])
:: remove contact data associated with group
::
;< ~ bind:m
%+ raw-poke
[our.bowl %contact-store]
:- %contact-action
!> ^- contact-action:con
[%delete (en-path:res resource.update)]
:: stop serving or syncing metadata associated with group
::
;< ~ bind:m
%+ raw-poke
[our.bowl %metadata-hook]
:- %metadata-hook-action
!>([%remove (en-path:res resource.update)])
:: get metadata associated with group
::
;< =associations:met bind:m
%+ scry associations:met
;: weld
/gx/metadata-store/group
(en-path:res resource.update)
/noun
==
=/ entries=(list [g=group-path:met m=md-resource:met])
~(tap in ~(key by associations))
|- ^- form:m
=* loop $
?~ entries
(pure:m !>(~))
:: remove metadata associated with group
::
;< ~ bind:m
%+ raw-poke
[our.bowl %metadata-store]
:- %metadata-action
!> ^- metadata-action:met
[%remove g.i.entries m.i.entries]
:: archive graph associated with group
::
;< ~ bind:m
%+ raw-poke
[our.bowl %graph-store]
:- %graph-update
!> ^- update:gra
[%0 now.bowl [%archive-graph (de-path:res app-path.m.i.entries)]]
;< ~ bind:m
%+ raw-poke
[our.bowl %graph-pull-hook]
:- %pull-hook-action
!>([%remove (de-path:res app-path.m.i.entries)])
loop(entries t.entries)

View File

@ -32,10 +32,6 @@ export default class ContactsApi extends BaseApi<StoreState> {
});
}
delete(path: Path) {
return this.viewAction({ delete: { path } });
}
remove(path: Path, ship: Patp) {
return this.viewAction({ remove: { path, ship } });
}

View File

@ -26,6 +26,10 @@ export default class GroupsApi extends BaseApi<StoreState> {
return this.proxyAction({ addMembers: { resource, ships } });
}
removeGroup(resource: Resource) {
return this.storeAction({ removeGroup: { resource } });
}
changePolicy(resource: Resource, diff: Enc<GroupPolicyDiff>) {
return this.proxyAction({ changePolicy: { resource, diff } });
}
@ -35,6 +39,7 @@ export default class GroupsApi extends BaseApi<StoreState> {
}
private storeAction(action: GroupAction) {
return this.action('group-store', 'group-action', action);
console.log(action);
return this.action('group-store', 'group-update', action);
}
}

View File

@ -38,7 +38,8 @@ function DeleteGroup(props: {
const shouldDelete = (prompt(`To confirm deleting this group, type ${name}`) === name);
if (!shouldDelete) return;
}
await props.api.contacts.delete(props.association["group-path"]);
const resource = resourceFromPath(props.association["group-path"])
await props.api.groups.removeGroup(resource);
history.push("/");
};