Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contacts: fix incorrect profile timestamp after migration #294

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 74 additions & 49 deletions desk/app/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
::
+| %types
+$ card card:agent:gall
+$ state-1 $: %1
+$ state-2 $: %2
rof=profile
=book
=peers
Expand All @@ -30,7 +30,7 @@
%- agent:dbug
%+ verb |
^- agent:gall
=| state-1
=| state-2
=* state -
=< |_ =bowl:gall
+* this .
Expand Down Expand Up @@ -132,7 +132,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 +211,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 +241,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 @@ -442,6 +446,7 @@
+| %implementation
::
++ init
=. wen.rof now.bowl
(emit %pass /migrate %agent [our dap]:bowl %poke noun+!>(%migrate))
::
++ load
Expand All @@ -451,60 +456,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
Loading