From 5b7ed3469f2c1eb9de61a18489b38380aa788e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Paraniak?= Date: Tue, 24 Sep 2024 12:17:48 +0800 Subject: [PATCH] contacts: refactoring --- desk/app/contacts.hoon | 56 ++++++++++++++++++------------------ desk/lib/contacts.hoon | 34 +++++++++++----------- desk/tests/app/contacts.hoon | 26 ++++++++--------- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/desk/app/contacts.hoon b/desk/app/contacts.hoon index 17467a8a..f7cbc397 100644 --- a/desk/app/contacts.hoon +++ b/desk/app/contacts.hoon @@ -253,7 +253,7 @@ :: +p-news-0: [legacy] publish news :: ++ p-news-0 - |= n=news-0:legacy + |= n=news-0:c0 (give %fact ~[/news] %contact-news !>(n)) :: +p-response: publish response :: @@ -460,8 +460,24 @@ ^+ cor |^ =+ !<([old=versioned-state cool=epic] old-vase) =? cor !=(okay cool) l-epic - :: ?- -.old + :: + %1 + =. state old + =/ cards + %+ roll ~(tap by peers) + |= [[who=ship foreign] caz=(list card)] + :: intent to connect, resubscribe + :: + ?: ?& =(%want sag) + !(~(has by wex.bowl) [/contact who dap.bowl]) + == + =/ =path [%v1 %contact ?~(for / /at/(scot %da wen.for))] + :_ caz + [%pass /contact %agent [who dap.bowl] %watch path] + caz + (emil cards) + :: %0 =. rof ?~(rof.old *profile (profile:from-0 rof.old)) :: migrate peers. for each peer @@ -471,7 +487,7 @@ :: =^ caz=(list card) peers %+ roll ~(tap by rol.old) - |= [[who=ship foreign-0:legacy] caz=(list card) =_peers] + |= [[who=ship foreign-0:c0] caz=(list card) =_peers] :: leave /epic if any :: =? caz (~(has by wex.bowl) [/epic who dap.bowl]) @@ -492,24 +508,8 @@ :_ caz [%pass /contact %agent [who dap.bowl] %watch path] (emil caz) - :: - %1 - =. state old - =/ cards - %+ roll ~(tap by peers) - |= [[who=ship foreign] caz=(list card)] - :: intent to connect, resubscribe - :: - ?: ?& =(%want sag) - !(~(has by wex.bowl) [/contact who dap.bowl]) - == - =/ =path [%v1 %contact ?~(for / /at/(scot %da wen.for))] - :_ caz - [%pass /contact %agent [who dap.bowl] %watch path] - caz - (emil cards) == - +$ state-0 [%0 rof=$@(~ profile-0:legacy) rol=rolodex:legacy] + +$ state-0 [%0 rof=$@(~ profile-0:c0) rol=rolodex:c0] +$ versioned-state $% state-0 state-1 @@ -536,7 +536,7 @@ :: :: legacy %contact-action ?(%contact-action %contact-action-0) - =/ act-0 !<(action-0:legacy vase) + =/ act-0 !<(action-0:c0 vase) ?. ?=(%edit -.act-0) (to-action act-0) :: v0 %edit needs special handling to evaluate @@ -572,8 +572,8 @@ :: :: v0 scries :: - :: /x/all -> $rolodex:legacy - :: /x/contact/her=@ -> $@(~ contact-0:legacy) + :: /x/all -> $rolodex:c0 + :: /x/contact/her=@ -> $@(~ contact-0:c0) :: :: v1 scries :: @@ -591,16 +591,16 @@ ?+ pat [~ ~] :: [%x %all ~] - =/ rol-0=rolodex:legacy + =/ rol-0=rolodex:c0 %- ~(urn by peers) |= [who=ship far=foreign] - ^- foreign-0:legacy + ^- foreign-0:c0 =/ mod=contact ?~ page=(~(get by book) who) ~ mod.u.page (foreign:to-0 (foreign-mod far mod)) - =/ lor-0=rolodex:legacy + =/ lor-0=rolodex:c0 ?: ?=(~ con.rof) rol-0 (~(put by rol-0) our.bowl (profile:to-0 rof) ~) ``contact-rolodex+!>(lor-0) @@ -608,14 +608,14 @@ [%x %contact her=@ ~] ?~ who=(slaw %p her.pat) [~ ~] - =/ tac=?(~ contact-0:legacy) + =/ tac=?(~ contact-0:c0) ?: =(our.bowl u.who) ?~(con.rof ~ (contact:to-0 con.rof)) =+ far=(~(get by peers) u.who) ?: |(?=(~ far) ?=(~ for.u.far)) ~ (contact:to-0 con.for.u.far) ?~ tac [~ ~] - ``contact+!>(`contact-0:legacy`tac) + ``contact+!>(`contact-0:c0`tac) :: [%x %v1 %self ~] ``contact-1+!>(`contact`con.rof) diff --git a/desk/lib/contacts.hoon b/desk/lib/contacts.hoon index 1e67a1be..27798e62 100644 --- a/desk/lib/contacts.hoon +++ b/desk/lib/contacts.hoon @@ -1,4 +1,4 @@ -/- *contacts, legacy=contacts-0 +/- *contacts, c0=contacts-0 |% :: +| %contact @@ -115,7 +115,7 @@ -- :: ++ do-edit-0 - |= [c=contact-0:legacy f=field-0:legacy] + |= [c=contact-0:c0 f=field-0:c0] ^+ c ?- -.f %nickname c(nickname nickname.f) @@ -193,7 +193,7 @@ :: +contact: convert legacy to contact :: ++ contact - |= o=contact-0:legacy + |= o=contact-0:c0 ^- ^contact =/ c=^contact %- malt @@ -217,7 +217,7 @@ :: +profile: convert legacy to profile :: ++ profile - |= o=profile-0:legacy + |= o=profile-0:c0 ^- ^profile [wen.o ?~(con.o ~ (contact con.o))] :: @@ -230,9 +230,9 @@ :: ++ contact |= c=^contact - ^- $@(~ contact-0:legacy) + ^- $@(~ contact-0:c0) ?~ c ~ - =| o=contact-0:legacy + =| o=contact-0:c0 %_ o nickname (~(gub cy c) %nickname %text) @@ -260,27 +260,27 @@ :: ++ profile |= p=^profile - ^- profile-0:legacy + ^- profile-0:c0 [wen.p (contact:to-0 con.p)] :: +profile-0-mod: convert profile with contact overlay :: to legacy :: ++ profile-mod |= [p=^profile mod=^contact] - ^- profile-0:legacy + ^- profile-0:c0 [wen.p (contact:to-0 (contact-uni con.p mod))] :: +foreign: convert foreign to legacy :: ++ foreign |= f=^foreign - ^- foreign-0:legacy + ^- foreign-0:c0 [?~(for.f ~ (profile:to-0 for.f)) sag.f] :: foreign-mod: convert foreign with contact overlay :: to legacy :: ++ foreign-mod |= [f=^foreign mod=^contact] - ^- foreign-0:legacy + ^- foreign-0:c0 [?~(for.f ~ (profile-mod:to-0 for.f mod)) sag.f] -- :: +contact-uni: merge contacts @@ -308,7 +308,7 @@ :: +$ sole-field-0 $~ nickname+'' - $<(?(%add-group %del-group) field-0:legacy) + $<(?(%add-group %del-group) field-0:c0) :: +to-sole-edit: convert legacy sole field to contact edit :: :: modify any field except for groups @@ -358,7 +358,7 @@ :: +to-self-edit: convert legacy to self edit :: ++ to-self-edit - |= [edit-0=(list field-0:legacy) groups=(set value)] + |= [edit-0=(list field-0:c0) groups=(set value)] ^- contact :: converting v0 profile edit to v1 is non-trivial. :: for field edits other than groups, we derive a contact @@ -370,8 +370,8 @@ :: .gid: only group edit actions :: =* group-type ?(%add-group %del-group) - =* sole-edits (list $<(group-type field-0:legacy)) - =* group-edits (list $>(group-type field-0:legacy)) + =* sole-edits (list $<(group-type field-0:c0)) + =* group-edits (list $>(group-type field-0:c0)) :: sift edits :: =/ [sid=sole-edits gid=group-edits] @@ -379,7 +379,7 @@ :: XX why is casting neccessary here? =- [(flop `sole-edits`-<) (flop `group-edits`->)] %+ roll edit-0 - |= [f=field-0:legacy sid=sole-edits gid=group-edits] + |= [f=field-0:c0 sid=sole-edits gid=group-edits] ^+ [sid gid] ?. ?=(group-type -.f) :- [f sid] @@ -390,7 +390,7 @@ :: =. groups %+ roll gid - |= [ged=$>(group-type field-0:legacy) =_groups] + |= [ged=$>(group-type field-0:c0) =_groups] ?- -.ged %add-group (~(put in groups) flag/flag.ged) @@ -407,7 +407,7 @@ :: access to existing groups to be able to process group edits. :: ++ to-action - |= o=$<(%edit action-0:legacy) + |= o=$<(%edit action-0:c0) ^- action ?- -.o %anon [%anon ~] diff --git a/desk/tests/app/contacts.hoon b/desk/tests/app/contacts.hoon index f46f104a..8b92314b 100644 --- a/desk/tests/app/contacts.hoon +++ b/desk/tests/app/contacts.hoon @@ -1,4 +1,4 @@ -/- *contacts, x=contacts-0 +/- *contacts, c0=contacts-0 /+ *test-agent /+ c=contacts /= contacts-agent /app/contacts @@ -29,7 +29,7 @@ ;< caz=(list card) b (do-init %contacts contacts-agent) ;< =bowl b get-bowl :: - =| con-0=contact-0:x + =| con-0=contact-0:c0 =. nickname.con-0 'Zod' =. bio.con-0 'The first of the galaxies' :: @@ -37,8 +37,8 @@ %- malt ^- (list (pair @tas value)) ~[nickname+text/'Zod' bio+text/'The first of the galaxies'] - =/ edit-0=(list field-0:x) - ^- (list field-0:x) + =/ edit-0=(list field-0:c0) + ^- (list field-0:c0) :~ nickname+'Zod' bio+'The first of the galaxies' == @@ -52,11 +52,11 @@ ;< caz=(list card) b (do-watch /news) :: ;< ~ b (set-src our.bowl) - :: action-0:x profile %edit + :: action-0:c0 profile %edit :: ;< caz=(list card) b (do-poke contact-action+!>([%edit edit-0])) :: - =/ upd-0=update-0:x + =/ upd-0=update-0:c0 [%full (add now.bowl (mul 2 tick)) ~] =/ upd-1=update [%full (add now.bowl (mul 2 tick)) ~] @@ -76,7 +76,7 @@ ;< caz=(list card) b (do-init %contacts contacts-agent) ;< =bowl b get-bowl :: - =| con-0=contact-0:x + =| con-0=contact-0:c0 =. nickname.con-0 'Zod' =. bio.con-0 'The first of the galaxies' =. groups.con-0 (silt ~sampel-palnet^%oranges ~) @@ -89,8 +89,8 @@ groups+set/(silt flag/~sampel-palnet^%oranges ~) == :: - =/ edit-0=(list field-0:x) - ^- (list field-0:x) + =/ edit-0=(list field-0:c0) + ^- (list field-0:c0) :~ nickname+'Zod' bio+'The first of the galaxies' add-group+~sampel-palnet^%apples @@ -111,7 +111,7 @@ ;< caz=(list card) b (do-watch /v1/news) :: ;< ~ b (set-src our.bowl) - :: action-0:x profile %edit + :: action-0:c0 profile %edit :: ;< caz=(list card) b (do-poke %contact-action !>([%edit edit-0])) ;< ~ b @@ -254,7 +254,7 @@ ;< caz=(list card) b (do-init %contacts contacts-agent) ;< =bowl b get-bowl :: - =| con-0=contact-0:x + =| con-0=contact-0:c0 =. nickname.con-0 'Zod' =. bio.con-0 'The first of the galaxies' :: @@ -263,7 +263,7 @@ ^- (list (pair @tas value)) ~[nickname+text/'Zod' bio+text/'The first of the galaxies'] :: - =/ upd-0=update-0:x + =/ upd-0=update-0:c0 [%full (add now.bowl tick) con-0] =/ upd-1=update [%full (add now.bowl tick) con-1] @@ -837,7 +837,7 @@ ;< peek=(unit (unit cage)) b (get-peek /x/all) =/ cag=cage (need (need peek)) ?> ?=(%contact-rolodex p.cag) - =/ rol !<(rolodex:x q.cag) + =/ rol !<(rolodex:c0 q.cag) ;< ~ b %+ ex-equal !> (~(got by rol) ~sun)