From f7bfef70fde0fa9fd0d1e579bb85a6cdff93414a Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 14 Feb 2019 17:58:42 -0800 Subject: [PATCH 1/4] App for sending Apple Push Notifications --- app/tiebout.hoon | 185 +++++++++++++++++++++++++++++++++++++++++++++++ lib/tiebout.hoon | 69 ++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 app/tiebout.hoon create mode 100644 lib/tiebout.hoon diff --git a/app/tiebout.hoon b/app/tiebout.hoon new file mode 100644 index 000000000..3f9d755f8 --- /dev/null +++ b/app/tiebout.hoon @@ -0,0 +1,185 @@ +:: +:::: /app/tiebout/hoon + :: +/- hall +/+ tiebout +:: +=, tiebout +=, eyre +:: +:: state: +:: +~% %tiebout ..^is ~ +|_ [bol=bowl:gall sta=state] +:: +:: +this: app core subject +:: +++ this . +:: +:: +prep: +:: +++ prep + ~/ %tie-prep + |= old=(unit state) + ^- (quip move _this) + ?~ old + :_ this ~ +:: :~ [ost.bol %peer /circles [our.bol %hall] /circles/[(scot %p our.bol)]] +:: [ost.bol %peer /inbox [our.bol %hall] /circle/inbox/config/grams] +:: == + ?- -.u.old + %0 + :_ this ~ + == +++ poke-noun + |= act=action + ^- (quip move _this) + (poke-tiebout-action act) +:: +:: +poke-tiebout-action: main action handler +:: +++ poke-tiebout-action + ~/ %tie-poke-tiebout-action + |= act=action + ^- (quip move _this) + ?- -.act + $king + (set-king +.act) + $token + (set-token +.act) + $baseurl + (set-baseurl +.act) + $notify + (send-notify +.act) + == +:: +:: +set-king: set king @p +:: +++ set-king + |= kng=@p + ^- (quip move _this) + =/ newtie tie.sta.this(king kng) + =/ newstate sta.this(tie newtie) + :_ this(sta newstate) ~ +:: +:: +set-token: set token @t +:: +++ set-token + |= tok=@t + ^- (quip move _this) + =/ newtie tie.sta.this(token tok) + =/ newstate sta.this(tie newtie) + :_ this(sta newstate) ~ +:: +:: +set-baseurl: set base url @t +:: +++ set-baseurl + |= burl=@t + ^- (quip move _this) + =/ newtie tie.sta.this(baseurl burl) + =/ newstate sta.this(tie newtie) + :_ this(sta newstate) ~ +:: +:: +send-notify: if king, send hiss. if not king, send to king. +:: +++ send-notify + |= not=notification + ^- (quip move _this) + ?: =(king.tie.sta our.bol) + :_ this + [ost.bol %hiss /request [~ ~] %httr %hiss (create-hiss not)]~ + :_ this + =/ doc/dock [king.tie.sta %tiebout] + [ost.bol %poke /ask-king doc [%tiebout-action [%notify not=not]]]~ +:: +++ create-hiss + |= not=notification + ^- hiss + =/ furl=@t (crip (weld (trip baseurl.tie.sta) (trip token.tie.sta))) + =/ url=purl (need (de-purl:html furl)) + =/ jon=json :- %o %- my :~ + aps+o+payload.not + == + :^ url %post + %- my :~ + apns-topic+[topic.not ~] :: generate map from raw noun + == + (some (as-octt:mimes:html (en-json:html jon))) + +-- +:: +coup: recieve acknowledgement for poke, print error if it failed +:: +::++ coup +:: |= [wir=wire err=(unit tang)] +:: ^- (quip move _this) +:: ?~ err +:: [~ this] +:: (mean u.err) +:: +:: +sigh-httr: receive result of http request +:: +::++ sigh-httr +:: |= [wir=wire code=@ud headers=mess:eyre body=(unit octs)] +:: ^- [(list move) _this] +:: ?: &((gte code 200) (lth code 300)) +:: ~& [%all-is-well code] +:: ~& [%headers headers] +:: ~& [%body body] +:: [~ this] +:: ~& [%we-have-a-problem code] +:: ~& [%headers headers] +:: ~& [%body body] +:: [~ this] +:: +:: +reap: recieve acknowledgement for peer, retry on failure +:: +::++ reap +:: |= [wir=wire err=(unit tang)] +:: ^- (quip move _this) +:: ::~& reap+[wir =(~ err)] +:: ?~ err +:: :: XX send message to users inbox +:: [~ this] +:: ?~ wir +:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) +:: ?+ i.wir +:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) +:: :: +:: %circles +:: :_ this +:: [ost.bol %peer /circles [our.bol %hall] /circles/[(scot %p our.bol)]]~ +:: :: +:: %inbox +:: :_ this +:: [ost.bol %peer /inbox [our.bol %hall] /circle/inbox/config/grams]~ +:: :: +:: %our +:: ?< ?=(~ t.wir) +:: :_ this +:: [ost.bol %peer /our/[i.t.wir] [our.bol %hall] /circle/[i.t.wir]/config]~ +:: == +:::: +:::: +quit: +:::: +::++ quit +:: |= wir=wire +:: ^- (quip move _this) +:: ?~ wir +:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) +:: ?+ i.wir +:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) +:: :: +:: %circles +:: :_ this +:: [ost.bol %peer /circles [our.bol %hall] /circles/[(scot %p our.bol)]]~ +:: :: +:: %inbox +:: :_ this +:: [ost.bol %peer /inbox [our.bol %hall] /circle/inbox/config/grams]~ +:: :: +:: %our +:: ?< ?=(~ t.wir) +:: :_ this +:: [ost.bol %peer /our/[i.t.wir] [our.bol %hall] /circle/[i.t.wir]/config]~ +:: == + diff --git a/lib/tiebout.hoon b/lib/tiebout.hoon new file mode 100644 index 000000000..19af3bcb7 --- /dev/null +++ b/lib/tiebout.hoon @@ -0,0 +1,69 @@ +:: +:::: /hoon/tiebout/lib + :: +/? 309 +/- hall +=, eyre +:: :: +~% %tiebout-lib ..is ~ +|% ++$ move [bone card] +:: ++$ card + $% [%poke wire dock poke] + [%peer wire dock path] + [%diff diff] + [%hiss wire [~ ~] %httr %hiss hiss] + == +:: ++$ diff + $% [%hall-rumor rumor:hall] + == +:: ++$ poke + $% [%tiebout-action action] + == +:: ++$ state + $% [%0 tie=tiebout-zero] + == +:: ++$ tiebout-zero + $: + token=@t + king=@p + baseurl=@t + :: names and configs of all circles we know about + :: + circles=(map circle:hall (unit config:hall)) + :: names and last read message of all circles we know about + :: + sequence=(map circle:hall @) + :: names of all circles we own + :: + our-circles=(set name:hall) + == +:: ++$ prize + $: :: names and configs of all circles we know about + :: + circles=(map circle:hall (unit config:hall)) + :: names and last read message of all circles we know about + :: + sequence=(map circle:hall @) + :: names of all circles we own + :: + our-circles=(set name:hall) + == +:: ++$ notification + $: topic=@t + payload=(map @t json) + == ++$ action + $% [%token tok=@t] + [%king kng=@p] + [%baseurl bur=@t] + [%notify not=notification] + == +-- From 00fe3eba525b680ffde3c7b4fe0ed646c87f650d Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 21 Feb 2019 15:45:51 -0800 Subject: [PATCH 2/4] First pass at Hall subscription logic --- app/tiebout.hoon | 191 ++++++++++++++++++++++++++--------------------- lib/tiebout.hoon | 28 ++----- 2 files changed, 114 insertions(+), 105 deletions(-) diff --git a/app/tiebout.hoon b/app/tiebout.hoon index 3f9d755f8..6f67bccf9 100644 --- a/app/tiebout.hoon +++ b/app/tiebout.hoon @@ -23,18 +23,24 @@ |= old=(unit state) ^- (quip move _this) ?~ old - :_ this ~ -:: :~ [ost.bol %peer /circles [our.bol %hall] /circles/[(scot %p our.bol)]] -:: [ost.bol %peer /inbox [our.bol %hall] /circle/inbox/config/grams] -:: == + :_ this(king.tie.sta.this ~bus) ~ ?- -.u.old %0 :_ this ~ == +:: +:: +poke-noun: debugging +:: ++ poke-noun |= act=action ^- (quip move _this) (poke-tiebout-action act) +:: +:: +:: + +:: +poke-json: action handler for web events + :: :: +poke-tiebout-action: main action handler :: @@ -49,18 +55,36 @@ (set-token +.act) $baseurl (set-baseurl +.act) + $add-circle + (add-circle +.act) + $del-circle + (del-circle +.act) $notify (send-notify +.act) == :: +:: +add-circle: add circle and subscribe for updates +:: +++ add-circle + |= nom=name:hall + ^- (quip move _this) + :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom 0)) + [ost.bol %peer /our/[nom] [our.bol %hall] /circle/[nom]/config]~ +:: +:: +del-circle: delete circle and unsubscribe from updates +:: +++ del-circle + |= nom=name:hall + ^- (quip move _this) + :_ this(circles.tie.sta (~(del by circles.tie.sta.this) nom)) + [ost.bol %pull /our/[nom] [our.bol %hall] ~]~ +:: :: +set-king: set king @p :: ++ set-king |= kng=@p ^- (quip move _this) - =/ newtie tie.sta.this(king kng) - =/ newstate sta.this(tie newtie) - :_ this(sta newstate) ~ + :_ this(king.tie.sta kng) ~ :: :: +set-token: set token @t :: @@ -95,7 +119,7 @@ ++ create-hiss |= not=notification ^- hiss - =/ furl=@t (crip (weld (trip baseurl.tie.sta) (trip token.tie.sta))) + =/ furl=@t (crip (weld (trip baseurl.tie.sta) (trip token.not))) =/ url=purl (need (de-purl:html furl)) =/ jon=json :- %o %- my :~ aps+o+payload.not @@ -105,81 +129,80 @@ apns-topic+[topic.not ~] :: generate map from raw noun == (some (as-octt:mimes:html (en-json:html jon))) +:: +:: +diff-hall-prize: +:: +++ diff-hall-prize + |= [wir=wire piz=prize:hall] + ^- (quip move _this) + ~& prize+[wir piz] + ?~ wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + ?+ wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + :: + :: %our: set config of circle and iterate through messages, sending + :: notifications for all messages where number is higher than our last-read + :: + {%our @ @} + ?> ?=(%circle -.piz) + =/ nom/name:hall i.t.wir + =/ red/@ud red.loc.cos.piz + :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom red)) ~ + == +++ helper + |= [red=@ud env=envelope:hall] + ^- (list move) + ~& env + =/ pay %- my :~ + alert+s+'New message' + == + =/ not/notification :+ + token.tie.sta + 'com.tlon.urbit-client' + pay + ?: (gth num.env red) + [ost.bol %poke /me [our.bol dap.bol] [%tiebout-action [%notify not]]]~ + ~ +:: +:: +diff-hall-rumor: +:: +++ diff-hall-rumor + |= [wir=wire rum=rumor:hall] + ^- (quip move _this) + ~& rumor+[wir rum] + ?~ wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + ?+ wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + :: + :: %our: set config of circle and iterate through messages, sending + :: notifications for all messages where number is higher than our last-read + :: + {%our @ @} + ?> ?=(%circle -.rum) + =/ nom/name:hall i.t.wir + :: get new read number if possible from config change + :: if not a read event, then use previous read number + :: then, generate a list of moves based on the messages in the rumor + :: that are higher in number than the read number + ?+ -.rum.rum + :_ this ~ + %gram + =/ red/@ (need (~(get by circles.tie.sta.this) nom)) + ?: (gth num.nev.rum.rum red) + :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom red)) + (helper red nev.rum.rum) + :_ this + (helper red nev.rum.rum) + %config + ?+ -.dif.rum.rum + [~ this] + %read + =/ red/@ud red.dif.rum.rum + :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom red)) ~ + == + == + == -- -:: +coup: recieve acknowledgement for poke, print error if it failed -:: -::++ coup -:: |= [wir=wire err=(unit tang)] -:: ^- (quip move _this) -:: ?~ err -:: [~ this] -:: (mean u.err) -:: -:: +sigh-httr: receive result of http request -:: -::++ sigh-httr -:: |= [wir=wire code=@ud headers=mess:eyre body=(unit octs)] -:: ^- [(list move) _this] -:: ?: &((gte code 200) (lth code 300)) -:: ~& [%all-is-well code] -:: ~& [%headers headers] -:: ~& [%body body] -:: [~ this] -:: ~& [%we-have-a-problem code] -:: ~& [%headers headers] -:: ~& [%body body] -:: [~ this] -:: -:: +reap: recieve acknowledgement for peer, retry on failure -:: -::++ reap -:: |= [wir=wire err=(unit tang)] -:: ^- (quip move _this) -:: ::~& reap+[wir =(~ err)] -:: ?~ err -:: :: XX send message to users inbox -:: [~ this] -:: ?~ wir -:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) -:: ?+ i.wir -:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) -:: :: -:: %circles -:: :_ this -:: [ost.bol %peer /circles [our.bol %hall] /circles/[(scot %p our.bol)]]~ -:: :: -:: %inbox -:: :_ this -:: [ost.bol %peer /inbox [our.bol %hall] /circle/inbox/config/grams]~ -:: :: -:: %our -:: ?< ?=(~ t.wir) -:: :_ this -:: [ost.bol %peer /our/[i.t.wir] [our.bol %hall] /circle/[i.t.wir]/config]~ -:: == -:::: -:::: +quit: -:::: -::++ quit -:: |= wir=wire -:: ^- (quip move _this) -:: ?~ wir -:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) -:: ?+ i.wir -:: (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) -:: :: -:: %circles -:: :_ this -:: [ost.bol %peer /circles [our.bol %hall] /circles/[(scot %p our.bol)]]~ -:: :: -:: %inbox -:: :_ this -:: [ost.bol %peer /inbox [our.bol %hall] /circle/inbox/config/grams]~ -:: :: -:: %our -:: ?< ?=(~ t.wir) -:: :_ this -:: [ost.bol %peer /our/[i.t.wir] [our.bol %hall] /circle/[i.t.wir]/config]~ -:: == - diff --git a/lib/tiebout.hoon b/lib/tiebout.hoon index 19af3bcb7..c04cde26c 100644 --- a/lib/tiebout.hoon +++ b/lib/tiebout.hoon @@ -12,6 +12,7 @@ +$ card $% [%poke wire dock poke] [%peer wire dock path] + [%pull wire dock ~] [%diff diff] [%hiss wire [~ ~] %httr %hiss hiss] == @@ -33,31 +34,14 @@ token=@t king=@p baseurl=@t - :: names and configs of all circles we know about + :: names, configs, and last read of all circles we know about :: - circles=(map circle:hall (unit config:hall)) - :: names and last read message of all circles we know about - :: - sequence=(map circle:hall @) - :: names of all circles we own - :: - our-circles=(set name:hall) - == -:: -+$ prize - $: :: names and configs of all circles we know about - :: - circles=(map circle:hall (unit config:hall)) - :: names and last read message of all circles we know about - :: - sequence=(map circle:hall @) - :: names of all circles we own - :: - our-circles=(set name:hall) + circles=(map name:hall @) == :: +$ notification - $: topic=@t + $: token=@t + topic=@t payload=(map @t json) == +$ action @@ -65,5 +49,7 @@ [%king kng=@p] [%baseurl bur=@t] [%notify not=notification] + [%add-circle nom=name:hall] + [%del-circle nom=name:hall] == -- From ac66d9af6b2d4a1b085f53f107d8d474b9a90a44 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Mon, 25 Feb 2019 16:49:56 -0800 Subject: [PATCH 3/4] Tiebout app works end to end, can receive actions via Eyre, and can resubscribe to circles --- app/tiebout.hoon | 199 ++++++++++++++++++++++++---------------- lib/tiebout.hoon | 9 +- mar/tiebout-action.hoon | 40 ++++++++ 3 files changed, 168 insertions(+), 80 deletions(-) create mode 100644 mar/tiebout-action.hoon diff --git a/app/tiebout.hoon b/app/tiebout.hoon index 6f67bccf9..7f72ccd91 100644 --- a/app/tiebout.hoon +++ b/app/tiebout.hoon @@ -1,9 +1,9 @@ :: :::: /app/tiebout/hoon - :: +:: +/? 309 /- hall /+ tiebout -:: =, tiebout =, eyre :: @@ -16,36 +16,41 @@ :: ++ this . :: -:: +prep: +:: +prep: set up app state, upgrade app state :: ++ prep - ~/ %tie-prep |= old=(unit state) ^- (quip move _this) ?~ old - :_ this(king.tie.sta.this ~bus) ~ - ?- -.u.old - %0 - :_ this ~ + :- ~ + %= this + king.tie.sta ~dopzod + baseurl.tie.sta 'https://api.push.apple.com/3/device/' + == + ?- -.u.old + %0 + [~ this(sta u.old)] == :: -:: +poke-noun: debugging +:: +coup: receive acknowledgement for poke, print error if it failed +:: +++ coup + |= [wir=wire err=(unit tang)] + ^- (quip move _this) + ?~ err + [~ this] + (mean u.err) +:: +:: +poke-noun: receive debugging actions :: ++ poke-noun |= act=action ^- (quip move _this) (poke-tiebout-action act) -:: -:: -:: - -:: +poke-json: action handler for web events - :: :: +poke-tiebout-action: main action handler :: ++ poke-tiebout-action - ~/ %tie-poke-tiebout-action |= act=action ^- (quip move _this) ?- -.act @@ -68,15 +73,15 @@ ++ add-circle |= nom=name:hall ^- (quip move _this) - :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom 0)) - [ost.bol %peer /our/[nom] [our.bol %hall] /circle/[nom]/config]~ + :_ this(circles.tie.sta (~(put by circles.tie.sta) nom 0)) + [ost.bol %peer /our/[nom] [our.bol %hall] /circle/[nom]/config/grams]~ :: :: +del-circle: delete circle and unsubscribe from updates :: ++ del-circle |= nom=name:hall ^- (quip move _this) - :_ this(circles.tie.sta (~(del by circles.tie.sta.this) nom)) + :_ this(circles.tie.sta (~(del by circles.tie.sta) nom)) [ost.bol %pull /our/[nom] [our.bol %hall] ~]~ :: :: +set-king: set king @p @@ -84,53 +89,33 @@ ++ set-king |= kng=@p ^- (quip move _this) - :_ this(king.tie.sta kng) ~ + [~ this(king.tie.sta kng)] :: -:: +set-token: set token @t +:: +set-token: set iOS device token @t :: ++ set-token |= tok=@t ^- (quip move _this) - =/ newtie tie.sta.this(token tok) - =/ newstate sta.this(tie newtie) - :_ this(sta newstate) ~ + [~ this(token.tie.sta tok)] :: :: +set-baseurl: set base url @t :: ++ set-baseurl |= burl=@t ^- (quip move _this) - =/ newtie tie.sta.this(baseurl burl) - =/ newstate sta.this(tie newtie) - :_ this(sta newstate) ~ + [~ this(baseurl.tie.sta burl)] :: -:: +send-notify: if king, send hiss. if not king, send to king. +:: +send-notify: if king, send hiss. if not, do nothing. :: ++ send-notify |= not=notification ^- (quip move _this) ?: =(king.tie.sta our.bol) :_ this - [ost.bol %hiss /request [~ ~] %httr %hiss (create-hiss not)]~ - :_ this - =/ doc/dock [king.tie.sta %tiebout] - [ost.bol %poke /ask-king doc [%tiebout-action [%notify not=not]]]~ + [ost.bol %hiss /request [~ ~] %httr %hiss (create-apns-request not)]~ + [~ this] :: -++ create-hiss - |= not=notification - ^- hiss - =/ furl=@t (crip (weld (trip baseurl.tie.sta) (trip token.not))) - =/ url=purl (need (de-purl:html furl)) - =/ jon=json :- %o %- my :~ - aps+o+payload.not - == - :^ url %post - %- my :~ - apns-topic+[topic.not ~] :: generate map from raw noun - == - (some (as-octt:mimes:html (en-json:html jon))) -:: -:: +diff-hall-prize: +:: +diff-hall-prize: receive new circle data :: ++ diff-hall-prize |= [wir=wire piz=prize:hall] @@ -148,61 +133,121 @@ ?> ?=(%circle -.piz) =/ nom/name:hall i.t.wir =/ red/@ud red.loc.cos.piz - :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom red)) ~ + [~ this(circles.tie.sta (~(put by circles.tie.sta) nom red))] == - -++ helper - |= [red=@ud env=envelope:hall] - ^- (list move) - ~& env - =/ pay %- my :~ - alert+s+'New message' +:: +:: +reap: recieve acknowledgement for peer +:: +++ reap + |= [wir=wire err=(unit tang)] + ^- (quip move _this) + ::~& reap+[wir =(~ err)] + ?~ err + :: XX send message to users inbox + [~ this] + ?~ wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + ?+ i.wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + %our + ?< ?=(~ t.wir) + :_ this + ~ == - =/ not/notification :+ - token.tie.sta - 'com.tlon.urbit-client' - pay - ?: (gth num.env red) - [ost.bol %poke /me [our.bol dap.bol] [%tiebout-action [%notify not]]]~ - ~ :: -:: +diff-hall-rumor: +:: +quit: receive subscription failed, resubscribe +:: +++ quit + |= wir=wire + ^- (quip move _this) + ?~ wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + ?+ i.wir + (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) + %our + ?< ?=(~ t.wir) + :_ this + =/ doc/dock [our.bol %hall] + [ost.bol %peer /our/[i.t.wir] doc /circle/[i.t.wir]/config/grams]~ + == + +:: +:: +diff-hall-rumor: receive message or a read event from a hall circle :: ++ diff-hall-rumor |= [wir=wire rum=rumor:hall] ^- (quip move _this) - ~& rumor+[wir rum] + ::~& rumor+[wir rum] ?~ wir (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) ?+ wir (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) :: - :: %our: set config of circle and iterate through messages, sending - :: notifications for all messages where number is higher than our last-read + :: %our :: {%our @ @} ?> ?=(%circle -.rum) =/ nom/name:hall i.t.wir - :: get new read number if possible from config change - :: if not a read event, then use previous read number - :: then, generate a list of moves based on the messages in the rumor - :: that are higher in number than the read number ?+ -.rum.rum - :_ this ~ + [~ this] + :: + :: %gram: send notification if envelope is lower than read number + :: %gram - =/ red/@ (need (~(get by circles.tie.sta.this) nom)) - ?: (gth num.nev.rum.rum red) - :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom red)) - (helper red nev.rum.rum) + =/ red (~(get by circles.tie.sta) nom) + ?~ red + (mean [leaf+"invalid circle for diff: {(spud wir)}"]~) + ?: (gth num.nev.rum.rum u.red) + :_ this(circles.tie.sta (~(put by circles.tie.sta) nom u.red)) + (message-to-notification u.red nev.rum.rum) :_ this - (helper red nev.rum.rum) + (message-to-notification u.red nev.rum.rum) + :: + :: %config: set our read number + :: %config ?+ -.dif.rum.rum [~ this] %read =/ red/@ud red.dif.rum.rum - :_ this(circles.tie.sta (~(put by circles.tie.sta.this) nom red)) ~ + [~ this(circles.tie.sta (~(put by circles.tie.sta) nom red))] == == == +:: +:: generate notification move from hall message +:: +++ message-to-notification + |= [red=@ud env=envelope:hall] + ^- (list move) + ?: =(aut.gam.env our.bol) + ~ + =/ pay %- my :~ + alert+s+'New message from {(cite:title aut.gam.env)}' + == + =/ not/notification :+ + token.tie.sta + 'com.tlon.urbit-client' + pay + ?: (lte num.env red) + ~ + =/ doc/dock [king.tie.sta dap.bol] + [ost.bol %poke /ask-king doc %tiebout-action [%notify not]]~ + +:: +:: +create-apns-request: create hiss with payload for APNs +:: +++ create-apns-request + |= not=notification + ^- hiss + =/ furl=@t (crip (weld (trip baseurl.tie.sta) (trip token.not))) + =/ url=purl (need (de-purl:html furl)) + =/ jon=json :- %o %- my :~ + aps+o+payload.not + == + :^ url %post + %- my :~ + apns-topic+[topic.not ~] :: generate map from raw noun + == + (some (as-octt:mimes:html (en-json:html jon))) -- diff --git a/lib/tiebout.hoon b/lib/tiebout.hoon index c04cde26c..efee2e95f 100644 --- a/lib/tiebout.hoon +++ b/lib/tiebout.hoon @@ -1,10 +1,10 @@ :: -:::: /hoon/tiebout/lib +:::: /lib/tiebout/hoon :: /? 309 /- hall =, eyre -:: :: +:: ~% %tiebout-lib ..is ~ |% +$ move [bone card] @@ -19,6 +19,7 @@ :: +$ diff $% [%hall-rumor rumor:hall] + [%tiebout-action action] == :: +$ poke @@ -34,7 +35,7 @@ token=@t king=@p baseurl=@t - :: names, configs, and last read of all circles we know about + :: name and last read :: circles=(map name:hall @) == @@ -44,6 +45,7 @@ topic=@t payload=(map @t json) == +:: +$ action $% [%token tok=@t] [%king kng=@p] @@ -52,4 +54,5 @@ [%add-circle nom=name:hall] [%del-circle nom=name:hall] == +:: -- diff --git a/mar/tiebout-action.hoon b/mar/tiebout-action.hoon new file mode 100644 index 000000000..8b24c9b85 --- /dev/null +++ b/mar/tiebout-action.hoon @@ -0,0 +1,40 @@ +:: +:::: /hoon/actions/collection/mar + :: +/? 309 +/- hall +/+ tiebout +=, tiebout +=, format +:: +|_ act=action:tiebout +:: +++ grow + |% + ++ tank >act< + -- +:: +++ grab + |% + ++ noun action:tiebout + ++ json + |= jon=^json + ^- action:tiebout + %- (hard action:tiebout) + =< (action jon) + |% + ++ action + %- of:dejs + :~ token+so:dejs + add-circle+sa + del-circle+sa + == + ++ sa :: string as ta + |= jon=^json + ?> ?=([%s *] jon) + (scot %tas p.jon) + -- + -- +:: +-- + From cf0b409db742a40e686338a281670f1eb50b4988 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 28 Feb 2019 13:20:39 -0800 Subject: [PATCH 4/4] style changes for tiebout --- app/tiebout.hoon | 142 ++++++++++++++++++++++------------------ lib/tiebout.hoon | 58 ---------------- mar/tiebout-action.hoon | 9 +-- sur/tiebout.hoon | 21 ++++++ 4 files changed, 101 insertions(+), 129 deletions(-) delete mode 100644 lib/tiebout.hoon create mode 100644 sur/tiebout.hoon diff --git a/app/tiebout.hoon b/app/tiebout.hoon index 7f72ccd91..db93115a1 100644 --- a/app/tiebout.hoon +++ b/app/tiebout.hoon @@ -1,15 +1,50 @@ -:: -:::: /app/tiebout/hoon -:: -/? 309 -/- hall -/+ tiebout +/- hall, tiebout =, tiebout =, eyre +|% ++$ move [bone card] +:: ++$ card + $% [%poke wire dock poke] + [%peer wire dock path] + [%pull wire dock ~] + [%diff diff] + [%hiss wire [~ ~] %httr %hiss hiss] + == +:: ++$ diff + $% [%hall-rumor rumor:hall] + [%tiebout-action action] + == +:: ++$ poke + $% [%tiebout-action action] + == +:: ++$ state + $% [%0 tiebout-zero] + == +:: ++$ tiebout-zero + $: + :: iOS device token + :: + token=@t + :: ship that routes notifications to Apple + :: + king=@p + :: url of Apple server to send notifications to + :: + baseurl=@t + :: name and last read + :: + circles=(map name:hall @) + == +:: +-- :: :: state: :: -~% %tiebout ..^is ~ |_ [bol=bowl:gall sta=state] :: :: +this: app core subject @@ -24,8 +59,8 @@ ?~ old :- ~ %= this - king.tie.sta ~dopzod - baseurl.tie.sta 'https://api.push.apple.com/3/device/' + king.sta ~dabben-larbet + baseurl.sta 'https://api.push.apple.com/3/device/' == ?- -.u.old %0 @@ -54,18 +89,12 @@ |= act=action ^- (quip move _this) ?- -.act - $king - (set-king +.act) - $token - (set-token +.act) - $baseurl - (set-baseurl +.act) - $add-circle - (add-circle +.act) - $del-circle - (del-circle +.act) - $notify - (send-notify +.act) + $king (set-king +.act) + $token (set-token +.act) + $baseurl (set-baseurl +.act) + $add-circle (add-circle +.act) + $del-circle (del-circle +.act) + $notify (send-notify +.act) == :: :: +add-circle: add circle and subscribe for updates @@ -73,7 +102,7 @@ ++ add-circle |= nom=name:hall ^- (quip move _this) - :_ this(circles.tie.sta (~(put by circles.tie.sta) nom 0)) + :_ this(circles.sta (~(put by circles.sta) nom 0)) [ost.bol %peer /our/[nom] [our.bol %hall] /circle/[nom]/config/grams]~ :: :: +del-circle: delete circle and unsubscribe from updates @@ -81,7 +110,7 @@ ++ del-circle |= nom=name:hall ^- (quip move _this) - :_ this(circles.tie.sta (~(del by circles.tie.sta) nom)) + :_ this(circles.sta (~(del by circles.sta) nom)) [ost.bol %pull /our/[nom] [our.bol %hall] ~]~ :: :: +set-king: set king @p @@ -89,28 +118,28 @@ ++ set-king |= kng=@p ^- (quip move _this) - [~ this(king.tie.sta kng)] + [~ this(king.sta kng)] :: :: +set-token: set iOS device token @t :: ++ set-token |= tok=@t ^- (quip move _this) - [~ this(token.tie.sta tok)] + [~ this(token.sta tok)] :: :: +set-baseurl: set base url @t :: ++ set-baseurl |= burl=@t ^- (quip move _this) - [~ this(baseurl.tie.sta burl)] + [~ this(baseurl.sta burl)] :: :: +send-notify: if king, send hiss. if not, do nothing. :: ++ send-notify |= not=notification ^- (quip move _this) - ?: =(king.tie.sta our.bol) + ?: =(king.sta our.bol) :_ this [ost.bol %hiss /request [~ ~] %httr %hiss (create-apns-request not)]~ [~ this] @@ -120,9 +149,6 @@ ++ diff-hall-prize |= [wir=wire piz=prize:hall] ^- (quip move _this) - ~& prize+[wir piz] - ?~ wir - (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) ?+ wir (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) :: @@ -133,7 +159,7 @@ ?> ?=(%circle -.piz) =/ nom/name:hall i.t.wir =/ red/@ud red.loc.cos.piz - [~ this(circles.tie.sta (~(put by circles.tie.sta) nom red))] + [~ this(circles.sta (~(put by circles.sta) nom red))] == :: :: +reap: recieve acknowledgement for peer @@ -141,18 +167,14 @@ ++ reap |= [wir=wire err=(unit tang)] ^- (quip move _this) - ::~& reap+[wir =(~ err)] ?~ err - :: XX send message to users inbox [~ this] - ?~ wir - (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) - ?+ i.wir + ?+ wir (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) - %our + :: + {%our @ @} ?< ?=(~ t.wir) - :_ this - ~ + [~ this] == :: :: +quit: receive subscription failed, resubscribe @@ -160,11 +182,10 @@ ++ quit |= wir=wire ^- (quip move _this) - ?~ wir - (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) - ?+ i.wir + ?+ wir (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) - %our + :: + {%our @ @} ?< ?=(~ t.wir) :_ this =/ doc/dock [our.bol %hall] @@ -177,9 +198,6 @@ ++ diff-hall-rumor |= [wir=wire rum=rumor:hall] ^- (quip move _this) - ::~& rumor+[wir rum] - ?~ wir - (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) ?+ wir (mean [leaf+"invalid wire for diff: {(spud wir)}"]~) :: @@ -194,30 +212,30 @@ :: %gram: send notification if envelope is lower than read number :: %gram - =/ red (~(get by circles.tie.sta) nom) + =/ red (~(get by circles.sta) nom) ?~ red (mean [leaf+"invalid circle for diff: {(spud wir)}"]~) ?: (gth num.nev.rum.rum u.red) - :_ this(circles.tie.sta (~(put by circles.tie.sta) nom u.red)) - (message-to-notification u.red nev.rum.rum) + :_ this(circles.sta (~(put by circles.sta) nom u.red)) + (conditional-msg-to-not u.red nev.rum.rum) :_ this - (message-to-notification u.red nev.rum.rum) + (conditional-msg-to-not u.red nev.rum.rum) :: :: %config: set our read number :: %config ?+ -.dif.rum.rum [~ this] - %read - =/ red/@ud red.dif.rum.rum - [~ this(circles.tie.sta (~(put by circles.tie.sta) nom red))] - == + :: + %read + [~ this(circles.sta (~(put by circles.sta) nom red.dif.rum.rum))] + == == == :: -:: generate notification move from hall message +:: generate notification move from hall message if conditions are met :: -++ message-to-notification +++ conditional-msg-to-not |= [red=@ud env=envelope:hall] ^- (list move) ?: =(aut.gam.env our.bol) @@ -225,13 +243,10 @@ =/ pay %- my :~ alert+s+'New message from {(cite:title aut.gam.env)}' == - =/ not/notification :+ - token.tie.sta - 'com.tlon.urbit-client' - pay + =/ not/notification [token.sta 'com.tlon.urbit-client' pay] ?: (lte num.env red) ~ - =/ doc/dock [king.tie.sta dap.bol] + =/ doc/dock [king.sta dap.bol] [ost.bol %poke /ask-king doc %tiebout-action [%notify not]]~ :: @@ -240,9 +255,10 @@ ++ create-apns-request |= not=notification ^- hiss - =/ furl=@t (crip (weld (trip baseurl.tie.sta) (trip token.not))) + =/ furl=@t (crip (weld (trip baseurl.sta) (trip token.not))) =/ url=purl (need (de-purl:html furl)) - =/ jon=json :- %o %- my :~ + =/ jon=json :- %o + %- my :~ aps+o+payload.not == :^ url %post diff --git a/lib/tiebout.hoon b/lib/tiebout.hoon deleted file mode 100644 index efee2e95f..000000000 --- a/lib/tiebout.hoon +++ /dev/null @@ -1,58 +0,0 @@ -:: -:::: /lib/tiebout/hoon - :: -/? 309 -/- hall -=, eyre -:: -~% %tiebout-lib ..is ~ -|% -+$ move [bone card] -:: -+$ card - $% [%poke wire dock poke] - [%peer wire dock path] - [%pull wire dock ~] - [%diff diff] - [%hiss wire [~ ~] %httr %hiss hiss] - == -:: -+$ diff - $% [%hall-rumor rumor:hall] - [%tiebout-action action] - == -:: -+$ poke - $% [%tiebout-action action] - == -:: -+$ state - $% [%0 tie=tiebout-zero] - == -:: -+$ tiebout-zero - $: - token=@t - king=@p - baseurl=@t - :: name and last read - :: - circles=(map name:hall @) - == -:: -+$ notification - $: token=@t - topic=@t - payload=(map @t json) - == -:: -+$ action - $% [%token tok=@t] - [%king kng=@p] - [%baseurl bur=@t] - [%notify not=notification] - [%add-circle nom=name:hall] - [%del-circle nom=name:hall] - == -:: --- diff --git a/mar/tiebout-action.hoon b/mar/tiebout-action.hoon index 8b24c9b85..f8ce537ee 100644 --- a/mar/tiebout-action.hoon +++ b/mar/tiebout-action.hoon @@ -1,10 +1,4 @@ -:: -:::: /hoon/actions/collection/mar - :: -/? 309 -/- hall -/+ tiebout -=, tiebout +/- hall, tiebout =, format :: |_ act=action:tiebout @@ -20,7 +14,6 @@ ++ json |= jon=^json ^- action:tiebout - %- (hard action:tiebout) =< (action jon) |% ++ action diff --git a/sur/tiebout.hoon b/sur/tiebout.hoon new file mode 100644 index 000000000..af302489e --- /dev/null +++ b/sur/tiebout.hoon @@ -0,0 +1,21 @@ +/- hall +=, eyre +:: +:: +|% ++$ notification + $: token=@t + topic=@t + payload=(map @t json) + == +:: ++$ action + $% [%token tok=@t] :: set device token + [%king kng=@p] :: set ship to route notifications through + [%baseurl bur=@t] :: set url to send notifications to + [%notify not=notification] :: send notification + [%add-circle nom=name:hall] :: send notifications for this circle + [%del-circle nom=name:hall] :: stop sending for this circle + == +:: +--