Skip to content

Commit

Permalink
Merge branch 'develop' into promote-11-26
Browse files Browse the repository at this point in the history
  • Loading branch information
arthyn committed Nov 26, 2024
2 parents d3fdb15 + 781d87a commit 95769b1
Show file tree
Hide file tree
Showing 4 changed files with 507 additions and 51 deletions.
165 changes: 114 additions & 51 deletions desk/app/contacts.hoon
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/- activity
/+ default-agent, dbug, verb, neg=negotiate
/+ *contacts
::
Expand All @@ -16,7 +17,7 @@
::
+| %types
+$ card card:agent:gall
+$ state-1 $: %1
+$ state-2 $: %2
rof=profile
=book
=peers
Expand All @@ -30,7 +31,7 @@
%- agent:dbug
%+ verb |
^- agent:gall
=| state-1
=| state-2
=* state -
=< |_ =bowl:gall
+* this .
Expand Down Expand Up @@ -100,6 +101,12 @@
::
+| %operations
::
++ pass-activity
|= [who=ship field=(pair @tas value)]
^- card
=/ =cage activity-action+!>(`action:activity`[%add %contact who field])
[%pass /activity %agent [our.bowl %activity] %poke cage]
::
:: +pub: publication management
::
:: - /v1/news: local updates to our profile and rolodex
Expand Down Expand Up @@ -132,7 +139,10 @@
++ subs
^- (set path)
%- ~(rep by sup.bowl)
|= [[duct ship pat=path] acc=(set path)]
:: default .acc prevents invalid empty fact path in the case
:: of no subscribers
::
|= [[duct ship pat=path] acc=_(sy `path`/v1/contact ~)]
?.(?=([%v1 %contact *] pat) acc (~(put in acc) pat))
++ fact
|= [pat=(set path) u=update]
Expand Down Expand Up @@ -208,7 +218,6 @@
|= con=contact
=/ p=profile [(mono wen.rof now.bowl) con]
=. rof p
::
=. cor
(p-news-0 our.bowl (contact:to-0 con))
=. cor
Expand Down Expand Up @@ -239,8 +248,10 @@
++ p-init
|= wen=(unit @da)
?~ wen (give (fact ~ full+rof))
?: (gte u.wen wen.rof) cor
(give (fact ~ full+rof))
?: =(u.wen wen.rof) cor
::
:: no future subs
?>((lth u.wen wen.rof) (give (fact ~ full+rof)))
:: +p-news-0: [legacy] publish news
::
++ p-news-0
Expand Down Expand Up @@ -340,15 +351,43 @@
cor =. cor
(p-news-0:pub who (contact:to-0 con.u))
=/ page=(unit page) (~(get by book) who)
:: update peer contact page
:: update contact book and send notification
::
=? cor ?=(^ page)
?: =(con.u.page con.u) cor
=. book (~(put by book) who u.page(con con.u))
=. cor (emil (send-activity u con.u.page))
(p-response:pub %page who con.u mod.u.page)
(p-response:pub %peer who con.u)
==
::
++ send-activity
|= [u=update con=contact]
^- (list card)
?. .^(? %gu /(scot %p our.bowl)/activity/(scot %da now.bowl)/$)
~
%- ~(rep by con.u)
|= [field=(pair @tas value) cards=(list card)]
?> ?=(^ q.field)
:: do not broadcast empty changes
::
?: (is-value-empty q.field)
cards
::
=/ val=(unit value) (~(get by con) p.field)
?~ val
[(pass-activity who field) cards]
?< ?=(~ u.val)
::NOTE currently shouldn't happen in practice
?. =(-.q.field -.u.val) cards
?: =(p.q.field p.u.val) cards
?. ?=(%set -.q.field)
[(pass-activity who field) cards]
=/ diff=(set value)
(~(dif in p.q.field) ?>(?=(%set -.u.val) p.u.val))
?~ diff cards
[(pass-activity who p.field set+diff) cards]
::
++ si-meet
^+ si-cor
::
Expand Down Expand Up @@ -442,6 +481,7 @@
+| %implementation
::
++ init
=. wen.rof now.bowl
(emit %pass /migrate %agent [our dap]:bowl %poke noun+!>(%migrate))
::
++ load
Expand All @@ -451,60 +491,80 @@
=? 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)
%2
=. state old
inflate-io
::
%0
=. rof ?~(rof.old *profile (profile:from-0 rof.old))
:: migrate peers. for each peer
:: 1. leave /epic, if any
:: 2. subscribe if desired
:: 3. put into peers
%1
=. state old(- %2)
:: fix incorrectly bunted timestamp for
:: an empty profile migrated from %0
::
=? cor &(=(*@da wen.rof) ?=(~ con.rof))
(p-commit-self:pub ~)
inflate-io
::
=^ caz=(list card) peers
%+ roll ~(tap by rol.old)
|= [[who=ship foreign-0:c0] caz=(list card) =_peers]
:: leave /epic if any
%0
=. rof ?~(rof.old *profile (profile:from-0 rof.old))
:: migrate peers. for each peer
:: 1. leave /epic, if any
:: 2. subscribe if desired
:: 3. put into peers
::
=? caz (~(has by wex.bowl) [/epic who dap.bowl])
=^ caz=(list card) peers
%+ roll ~(tap by rol.old)
|= [[who=ship foreign-0:c0] caz=(list card) =_peers]
:: leave /epic if any
::
=? caz (~(has by wex.bowl) [/epic who dap.bowl])
:_ caz
[%pass /epic %agent [who dap.bowl] %leave ~]
=/ fir=$@(~ profile)
?~ for ~
(profile:from-0 for)
:: no intent to connect
::
?: =(~ sag)
:- caz
(~(put by peers) who fir ~)
:_ (~(put by peers) who fir %want)
?: (~(has by wex.bowl) [/contact who dap.bowl])
caz
=/ =path [%v1 %contact ?~(fir / /at/(scot %da wen.fir))]
:_ caz
[%pass /epic %agent [who dap.bowl] %leave ~]
=/ fir=$@(~ profile)
?~ for ~
(profile:from-0 for)
:: no intent to connect
::
?: =(~ sag)
:- caz
(~(put by peers) who fir ~)
:_ (~(put by peers) who fir %want)
?: (~(has by wex.bowl) [/contact who dap.bowl])
caz
=/ =path [%v1 %contact ?~(fir / /at/(scot %da wen.fir))]
:_ caz
[%pass /contact %agent [who dap.bowl] %watch path]
(emil caz)
[%pass /contact %agent [who dap.bowl] %watch path]
(emil caz)
==
+$ state-0 [%0 rof=$@(~ profile-0:c0) rol=rolodex:c0]
+$ state-1 $: %1
rof=profile
=^book
=^peers
retry=(map ship @da) :: retry sub at time
==
+$ versioned-state
$% state-0
$% state-2
state-1
state-0
==
::
++ l-epic (give %fact [/epic ~] epic+!>(okay))
::
++ inflate-io
^+ cor
=/ 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)
--
::
++ poke
Expand Down Expand Up @@ -710,7 +770,7 @@
++ agent
|= [=wire =sign:agent:gall]
^+ cor
?+ wire ~|(evil-agent+wire !!)
?+ wire ~|(evil-agent+wire !!)
[%contact ~]
si-abet:(si-take:(sub src.bowl) wire sign)
::
Expand All @@ -719,6 +779,9 @@
?~ p.sign cor
%- (slog leaf/"{<wire>} failed" u.p.sign)
cor
::
[%activity ~]
cor
::
[%epic ~]
cor
Expand Down
10 changes: 10 additions & 0 deletions desk/lib/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
|%
::
+| %contact
:: +is-value-empty: is value considered empty
::
++ is-value-empty
|= val=value
^- ?
?+ -.val |
%text =('' p.val)
%look =('' p.val)
%set ?=(~ p.val)
==
:: +cy: contact map engine
::
++ cy
Expand Down
Loading

0 comments on commit 95769b1

Please sign in to comment.