Skip to content

Commit

Permalink
contacts: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Sep 24, 2024
1 parent c99da6b commit 5b7ed34
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
56 changes: 28 additions & 28 deletions desk/app/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -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
::
Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
::
Expand All @@ -591,31 +591,31 @@
?+ 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)
::
[%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)
Expand Down
34 changes: 17 additions & 17 deletions desk/lib/contacts.hoon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/- *contacts, legacy=contacts-0
/- *contacts, c0=contacts-0
|%
::
+| %contact
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -193,7 +193,7 @@
:: +contact: convert legacy to contact
::
++ contact
|= o=contact-0:legacy
|= o=contact-0:c0
^- ^contact
=/ c=^contact
%- malt
Expand All @@ -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))]
::
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -370,16 +370,16 @@
:: .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]
::
:: 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]
Expand All @@ -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)
Expand All @@ -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 ~]
Expand Down
26 changes: 13 additions & 13 deletions desk/tests/app/contacts.hoon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/- *contacts, x=contacts-0
/- *contacts, c0=contacts-0
/+ *test-agent
/+ c=contacts
/= contacts-agent /app/contacts
Expand Down Expand Up @@ -29,16 +29,16 @@
;< 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'
::
=/ con-1=contact
%- 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'
==
Expand All @@ -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)) ~]
Expand All @@ -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 ~)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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'
::
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5b7ed34

Please sign in to comment.