shrub/app/talk-guardian.hoon

1812 lines
58 KiB
Plaintext
Raw Normal View History

:: :: ::
2017-03-23 03:34:56 +03:00
:::: /hoon/talk/app :: ::
:: :: ::
2017-03-23 03:34:56 +03:00
::
::TODO master changes
::TODO char57 comments as line comments when regarding code.
2017-03-23 03:34:56 +03:00
::TODO avoid lark where possible
2017-04-25 22:09:20 +03:00
::TODO document what user-facing messages actually mean!
::TODO ::> to :> etc.
2017-04-18 22:33:02 +03:00
::
::TODO we can't do away with the default mailbox because we need it for things
:: like invite notifications etc. can we do better than request that apps
:: don't use it frivolously?
::
2017-04-18 22:33:02 +03:00
::TODO ".. the importance of the CQRS pattern (command-query separation) behind
:: Urbit's separation of %poke and %peer. Pokes (messages) are one-way
:: commands, not queries. Peers (subscriptions) have no effect on the
:: server state."
:: but we *do* change state on-subscribe! is that a problem?
2017-03-23 03:34:56 +03:00
::
::TODO crash on pokes/peers we do not expect
::TODO keep both a folks and nicks maps. (actual profiles and local nicknames.)
::
/? 151 ::< hoon version
/- talk ::< structures
2017-04-21 17:14:11 +03:00
/+ talk, time-to-id ::< libraries
2017-03-23 03:34:56 +03:00
/= seed /~ !>(.)
!:
2017-03-23 03:34:56 +03:00
::::
::
[. talk]
=> ::> ||
::> || %arch
::> ||
::> data structures
::
|%
2017-04-27 13:15:41 +03:00
++ state ::> broker state
$: stories/(map knot story) ::< convercirions
readers/(map bone (set knot)) ::< our message readers
outbox/(pair @ud (map @ud thought)) ::< urbit outbox
log/(map knot @ud) ::< logged to clay
folks/(map ship human) ::< human identities
nik/(map (set partner) char) ::< bound circle glyphs
nak/(jug char (set partner)) ::< circle glyph lookup
2017-03-23 03:34:56 +03:00
== ::
++ story ::> wire content
$: count/@ud ::< (lent grams)
grams/(list telegram) ::< all messages
2017-04-27 00:33:25 +03:00
locals/group ::< local presence
remotes/(map partner group) ::< remote presence
shape/config ::< configuration
mirrors/(map circle config) ::< remote config
::TODO never gets updated. ::
sequence/(map partner @ud) ::< partners heard
known/(map serial @ud) ::< messages heard
followers/(map bone river) ::< subscribers
2017-03-23 03:34:56 +03:00
== ::
++ river (pair point point) ::< stream definition
++ point ::> stream endpoint
$% {$ud p/@ud} ::< by number
{$da p/@da} ::< by date
2017-03-23 03:34:56 +03:00
== ::
++ move (pair bone card) ::< all actions
++ lime ::> diff fruit
2017-03-23 03:34:56 +03:00
$% {$talk-report report} ::
{$talk-lowdown lowdown} ::
{$talk-reaction reaction} ::
2017-03-23 03:34:56 +03:00
== ::
++ pear ::> poke fruit
2017-03-23 03:34:56 +03:00
$% {$talk-command command} ::
{$write-comment spur ship cord} ::
{$write-fora-post spur ship cord cord} ::
== ::
++ card ::> general card
2017-03-23 03:34:56 +03:00
$% {$diff lime} ::
{$info wire ship term nori} ::
2017-03-23 03:34:56 +03:00
{$peer wire dock path} ::
{$poke wire dock pear} ::
{$pull wire dock $~} ::
{$quit $~} ::
== ::
++ weir ::> parsed wire
$% {$repeat num/@ud hos/ship nom/knot} ::< messaging wire
{$friend nom/knot cir/circle} ::< subscription wire
2017-03-23 03:34:56 +03:00
== ::
--
::
::> ||
::> || %work
::> ||
::> functional cores and arms.
::
2017-04-27 13:15:41 +03:00
|_ {bol/bowl state}
::
++ prep ::< prepare state
2017-04-21 17:14:11 +03:00
::> adapts state.
::
2017-04-27 13:15:41 +03:00
|= old/(unit state)
^- (quip move ..prep)
?~ old
ta-done:ta-init:ta
[~ ..prep(+<+ u.old)]
::
::> ||
::> || %utility
::> ||
::> small utility functions.
::+|
::
++ strap |*({k/* v/*} (~(put by *(map _k _v)) k v)) ::< map key-value pair
::
::> ||
::> || %engines
::> ||
::> main cores.
::+|
::
++ ta ::< per transaction
::> for every transaction/event (poke, peer, etc.)
::> talk-guardian receives, the ++ta transaction core
::> is called.
::> in processing transactions, ++ta may modify app
::> state, or create moves. these moves get produced
::> upon finalizing the core's work with ++ta-done.
::> when making changes to stories, the ++so core is
::> used.
2017-03-23 03:34:56 +03:00
::
|_ ::> moves: moves created by core operations.
::
moves/(list move)
::
++ ta-done ::< resolve core
::> produces the moves stored in ++ta's moves.
::> they are produced in reverse order because
::> ++ta-emil and ++ta-emit add them to the head of
::> the {moves}.
::
^- (quip move +>)
[(flop moves) +>]
::
::> ||
::> || %emitters
::> ||
::> arms that create outward changes.
::+|
2017-03-23 03:34:56 +03:00
::
++ ta-emil ::< emit move list
::> adds multiple moves to the head of {moves}.
::> flops to stay consistent with ++ta-emit.
2017-03-23 03:34:56 +03:00
::
|= mol/(list move)
%_(+> moves (welp (flop mol) moves))
::
++ ta-emit ::< emit a move
::> adds a move to the head of {moves}.
2017-03-23 03:34:56 +03:00
::
|= mov/move
%_(+> moves [mov moves])
::
++ ta-inform ::< broadcast lowdown
::> sends a talk-lowdown diff to all readers.
::
|= low/lowdown
%- ta-emil
%- ~(rep by readers)
|= {{b/bone *} l/(list move)}
[[b %diff %talk-lowdown low] l]
::
++ ta-react ::< send reaction
::> sends a talk-reaction diff to a reader.
::
|= {red/bone rac/reaction}
%- ta-emit
[red %diff %talk-reaction rac]
::
++ ta-note ::< tell user
::> sends {msg} as an %app message to the user's
::> inbox.
::
|= msg/cord
2017-04-25 22:09:20 +03:00
%^ ta-action 0 %phrase
:- [[%& our.bol (main our.bol)] ~ ~]
[%app %talk-guardian msg]~
::
++ ta-evil ::< emit error
::> tracing printf and crash.
2017-03-23 03:34:56 +03:00
::
|= msg/cord
~| [%talk-ta-evil msg]
2017-03-23 03:34:56 +03:00
!!
::
::> ||
::> || %data
::> ||
::> utility functions for data retrieval.
::+|
::
++ ta-know ::< story monad
::> produces a gill that takes a gate.
::> if the story {nom} exists, calls the gate with
::> a story core. if it doesn't, does nothing.
::
|= nom/knot
|= fun/$-(_so _ta)
^+ +>+>
=+ pur=(~(get by stories) nom)
?~ pur
::TODO crash instead?
%- ta-note
(crip "unknown story '{(trip nom)}'")
(fun ~(. so nom ~ u.pur))
::
++ ta-human ::< look up person
::> get {her} identity. if we need to, create one.
::
|= her/ship
^- (quid human +>)
=^ who folks
=+ who=(~(get by folks) her)
?^ who [u.who folks]
=+ who=`human`[~ `(scot %p her)] :: XX do right
[who (~(put by folks) her who)]
[who +>.$]
::
::> ||
::> || %interaction-events
::> ||
::> arms that apply events we received.
::+|
::
++ ta-init ::< initialize app
::> populate state on first boot.
::> creates our default mailbox and journal.
2017-03-23 03:34:56 +03:00
::
%+ roll
2017-04-27 00:33:25 +03:00
^- (list {security knot cord})
:~ [%brown (main our.bol) 'default home']
2017-03-23 03:34:56 +03:00
[%green ~.public 'visible activity']
==
2017-04-27 00:33:25 +03:00
|= {{typ/security nom/knot des/cord} _ta}
%+ ta-action ost.bol
[%create nom des typ]
2017-03-23 03:34:56 +03:00
::
++ ta-apply ::< apply command
::> applies the command sent by {src}.
2017-03-23 03:34:56 +03:00
::
|= {src/ship cod/command}
2017-03-23 03:34:56 +03:00
^+ +>
?- -.cod
::> %review commands prompt us (as a circle host)
::> to verify and distribute messages.
$review
(ta-think | src +.cod)
::> %burden commands ask us to add the sender as a
::> federator for the specified story, taking the
::> state it sent into account.
$burden
(ta-burden src +.cod)
::> %relief commands prompt us to relieve the
::> specified federators of their duty.
$relief
(ta-relieve src +.cod)
2017-03-23 03:34:56 +03:00
==
::
++ ta-burden ::< accept federator
::> adds {src} as a federator to story {nom},
::> integrating its state into the story.
::
|= {src/ship nom/knot cof/lobby pes/crowd gaz/(list telegram)}
%- (ta-know nom) |= sor/_so =< so-done
(so-burden:sor src cof pes gaz)
::
++ ta-relieve ::< remove federator
::> removes {who} as federators from story {nom}.
::
|= {src/ship nom/knot who/(set ship)}
%- (ta-know nom) |= sor/_so =< so-done
(so-relieve:sor src who)
::
++ ta-action ::< apply reader action
::> performs action sent by a reader.
::
|= {red/bone act/action}
^+ +>
=< work
::> ||
::> || %actions
::> ||
::> action processing core
::>
::> ++work calls the appropriate action processing
::> arm. most use ++affect to retrieve the affected
::> story, reacting if it doesn't exist.
|%
:: || %utility
::+|
++ work ::< perform action
^+ ..ta-action
?- -.act
:: circle configuration
$create (action-create +.act)
$source (action-source +.act)
$depict (action-depict +.act)
$permit (action-permit +.act)
$delete (action-delete +.act)
$enlist (action-enlist +.act)
$burden (action-burden +.act)
:: messaging
$convey (action-convey +.act)
$phrase (action-phrase +.act)
:: personal metadata
$status (action-status +.act)
:: changing shared ui
$human (action-human +.act)
$glyph (action-glyph +.act)
==
::
++ affect ::< affect story
::> produces a gill that takes a gate.
::> if the story {nom} exists, calls the gate with
::> a story core and the story itself.
::> if it doesn't, reacts accordingly.
2017-04-11 14:00:13 +03:00
::
|= nom/knot
|= fec/$-({_so story} _ta)
^+ ta
=+ pur=(~(get by stories) nom)
?^ pur
(fec ~(. so nom ~ u.pur) u.pur)
%+ ta-react red
[%fail (crip "no story {(trip nom)}") `act]
::
::> || %circle-configuration
::+|
++ action-create ::< create story
::> creates a story with the specified parameters.
2017-04-11 14:00:13 +03:00
::
2017-04-27 00:33:25 +03:00
|= {nom/knot des/cord typ/security}
^+ ..ta-action
?. (~(has in stories) nom)
%+ ta-config nom
:* [[%& our.bol nom] ~ ~]
des
[typ ~]
[[our.bol ~ ~] [our.bol ~ ~]]
==
(ta-react red %fail (crip "{(trip nom)}: already exists") `act)
::
++ action-delete ::< delete + announce
::> delete story {nom}, optionally announcing the
::> event with message {mes}.
::
|= {nom/knot mes/(unit cord)}
^+ ..ta-action
%- (affect nom) |= *
=. ..ta-action ::TODO =?
?~ mes ..ta-action
%+ action-phrase
[[%& our.bol nom] ~ ~]
[%lin | u.mes]~
(ta-unconfig nom)
::
++ action-depict ::< change description
::> change description of story {nom} to {des}.
::
|= {nom/knot des/cord}
^+ ..ta-action
%- (affect nom) |= {sor/_so soy/story}
=. cap.shape.soy des
(ta-config nom shape.soy)
::
++ action-permit ::< invite/banish
::> invite to/banish from story {nom} all {sis}.
::
|= {nom/knot inv/? sis/(set ship)}
^+ ..ta-action
%- (affect nom) |= {sor/_so *} =< so-done
(so-permit:sor inv sis)
::
++ action-source ::< un/sub p to/from r
::> add/remove {pas} as sources for story {nom}.
::
|= {nom/knot sub/? pas/(set partner)}
^+ ..ta-action
%- (affect nom) |= {sor/_so soy/story}
=. src.shape.soy
%. pas
?: sub
~(uni in src.shape.soy)
~(dif in src.shape.soy)
(ta-config nom shape.soy)
::
++ action-enlist ::< dis/allow federation
::> adds {sis} to story {nom}'s list of allowed
::> federators.
::
|= {nom/knot fed/? sis/(set ship)}
^+ ..ta-action
%- (affect nom) |= {sor/_so soy/story}
::TODO maybe so-enlist, with message note and everything
=. may.fed.shape.soy
%. sis
?: fed
~(uni in may.fed.shape.soy)
~(dif in may.fed.shape.soy)
(ta-config nom shape.soy)
::
++ action-burden ::< help federate
::> starts federating the specified circle. create
::> it locally if it doesn't yet exist.
::
|= {hos/ship nom/knot}
^+ ..ta-action
:: update federation config.
=+ soy=(fall (~(get by stories) nom) *story)
=. may.fed.shape.soy
(~(put in may.fed.shape.soy) hos)
=. fes.fed.shape.soy
(~(put in fes.fed.shape.soy) hos)
=. src.shape.soy
(~(put in src.shape.soy) [%& hos nom])
=. ..ta-action
(ta-config nom shape.soy)
:: send %burden command with story's current state.
%- ta-emit
:* ost.bol
%poke
/burden
[hos %talk-guardian]
:* %talk-command
%burden
nom
[shape.soy mirrors.soy]
[locals.soy remotes.soy]
grams.soy
==
==
::
::> || %messaging
::+|
++ action-convey ::< post exact
::> sends the messages provided in the action.
::
|= tos/(list thought)
^+ ..ta-action
(ta-think & our.bol tos)
::
++ action-phrase ::< post easy
::> sends the message contents provided in the
::> action, constructing the audience, generating a
::> serial and setting a timestamp.
::
|= {pas/(set partner) ses/(list speech)}
^+ ..ta-action
=- (ta-think & our.bol tos)
|- ^- tos/(list thought)
?~ ses ~
=^ sir eny.bol (uniq eny.bol)
:_ $(ses t.ses)
:+ sir
%- ~(gas by *audience)
%+ turn (~(tap in pas))
|=(p/partner [p *envelope %pending])
[now.bol ~ i.ses]
::
::> || %personal-metadata
::+|
++ action-status ::< our status update
::> for every story in the set, update our status.
2017-04-11 14:00:13 +03:00
::
|= {nos/(set knot) sat/status}
^+ ..ta-action
%- ~(rep in nos)
|= {k/knot _ta}
%- (affect k) |= {sor/_so *}
so-done:(so-notify:sor our.bol sat)
::
::> || %changing-shared-ui
::+|
++ action-human ::< new identity
::> assigns a new local identity ("nickname") to the
::> target ship.
2017-04-11 14:00:13 +03:00
::
|= {sip/ship nic/human}
^+ ..ta-action
?. =((~(get by folks) sip) `nic) ..ta-action ::< no change
=. folks
?~ han.nic (~(del by folks) sip)
(~(put by folks) sip nic)
%+ ta-inform %names
2017-03-27 13:50:39 +03:00
::TODO think long and hard, do we need unit for delition or is a human
:: with [~ ~] good enough? if the latter, agent's $names will change.
(strap sip ?~(han.nic ~ `nic))
::
++ action-glyph ::< bind a glyph
::> un/bind glyph {lif} to partners {pas}.
2017-04-11 14:00:13 +03:00
::
|= {lif/char pas/(set partner) bin/?}
=. ..ta-action
?: bin
%= ..ta-action ::< bind
nik (~(put by nik) pas lif)
nak (~(put ju nak) lif pas)
==
=/ ole/(set (set partner)) ::< unbind
?. =(pas ~) [pas ~ ~]
(~(get ju nak) lif)
|- ^+ ..ta-action
?~ ole ..ta-action
=. ..ta-action $(ole l.ole)
=. ..ta-action $(ole r.ole)
%= ..ta-action
nik (~(del by nik) pas)
nak (~(del ju nak) lif pas)
==
(ta-inform %glyph nak)
--
::
++ ta-diff-report ::< subscription update
::> process a talk report from {cir} into story {nom}.
::
|= {nom/knot cir/circle ret/report}
%- (ta-know nom) |= sor/_so =< so-done
(so-diff-report:sor cir ret)
::
::> ||
::> || %subscription-events
::> ||
::> arms that react to subscription events.
::+|
::
++ ta-subscribe ::< listen to
::> start {her} susbcription on {pax}.
::> for readers, we forward to ++ta-welcome.
::> for foreign brokers, we check if their desired
::> story exists and if they have permission to
::> subscribe to it, before sending them all data.
2017-03-23 03:34:56 +03:00
::
|= {her/ship pax/path}
2017-03-23 03:34:56 +03:00
^+ +>
:: reader subscription.
?: ?=({$reader *} pax)
?. (team our.bol her)
%- ta-note
(crip "foreign reader {(scow %p her)}")
(ta-welcome ost.bol t.pax)
:: weird subscription path.
?. ?=({@ *} pax)
(ta-evil %bad-path)
=+ pur=(~(get by stories) i.pax)
?~ pur
2017-04-25 22:09:20 +03:00
::TODO send this to the subscriber! make them unsub!
%- ta-note
(crip "bad subscribe story '{(trip i.pax)}'")
=+ soy=~(. so i.pax `(list action)`~ u.pur) :: nest-fail if no cast
:: she needs read permissions to subscribe.
?. (so-visible:soy her)
(ta-evil %no-story)
::TODO? or (so-sauce ost.bol [%quit ~]~) ?
=^ who +>.$ (ta-human her)
:: send current data to bring her up to date.
2017-04-27 00:33:25 +03:00
=. soy (so-report-lobby:soy ost.bol ~ ~)
=. soy (so-report-crowd:soy ost.bol ~ ~)
2017-04-25 22:09:20 +03:00
=. soy (so-start:soy her t.pax) ::< also adds story sub
=. soy (so-notify:soy her %hear who) ::< add her status
so-done:soy ::< apply story changes
2017-03-23 03:34:56 +03:00
::
++ ta-welcome ::< reader subscription
::> brings new reader up to date. susbcribes it to the specified story,
::TODO or shared ui state if no story was specified.
::TODO maybe also send a list of knots again? (basically a %house lowdown)
::
|= {new/bone pax/path}
=/ sor/knot
?: ?=({@tas *} pax) i.pax
(main our.bol) :: default to mailbox
::> new reader? send shared ui state.
=. +>.$ ::TODO =?
?: (~(has by readers) new) +>.$
%- ta-emil
2017-04-21 17:14:11 +03:00
:~ ::> bound glyphs
[new %diff %talk-lowdown %glyph nak]
2017-04-21 17:14:11 +03:00
::> nicknames
[new %diff %talk-lowdown %names (~(run by folks) some)]
==
::> send story state.
=. +>.$ ::TODO =?
?. (~(has by stories) sor) +>.$
=+ soy=(~(got by stories) sor)
%- ta-emil
2017-04-21 17:14:11 +03:00
:~ ::> configurations
:* new %diff %talk-lowdown %confs
`shape.soy (~(run by mirrors.soy) some)
==
2017-04-21 17:14:11 +03:00
::> presences
[new %diff %talk-lowdown %precs locals.soy remotes.soy]
2017-04-21 17:14:11 +03:00
::> messages
[new %diff %talk-lowdown %grams 0 grams.soy]
==
::> add this subscription to {readers}.
%= +>.$
readers
%+ ~(put by readers) new
(~(put in (fall (~(get by readers) new) ~)) sor)
==
::
++ ta-retry ::< subscription resend
::> re-subscribes {cir} to story {nom}.
::
|= {nom/knot cir/circle}
%- (ta-know nom) |= sor/_so =< so-done
(so-acquire:sor [%& cir]~)
::
++ ta-quit ::< subscription failed
::> removes {cir} from story {nom}'s followers.
::
|= {nom/knot cir/circle}
%- (ta-know nom) |= sor/_so =< so-done
(so-quit:sor %& cir)
::
++ ta-cancel ::< unsubscribe
::> drops {src}'s subscription. deduce the right way
::> to do this from the subscription path {pax}.
::
|= {src/ship pax/path}
^+ +>
:: remove a reader subscription.
?: ?=({$reader *} pax)
=/ nom/knot
?: ?=({@tas *} t.pax) i.pax
(main our.bol) ::TODO change when ++ta-welcome changes.
=/ nes/(set knot)
%. nom
~(del in (~(got by readers) ost.bol))
+>.$(readers (~(put by readers) ost.bol nes))
:: weird subscription path.
?. ?=({@ @ *} pax)
%- ta-note
(crip "ta-cancel weird path {~(ram re >pax<)}")
:: remove a regular subscription, set ship status to %gone.
%- (ta-know i.pax) |= sor/_so =< so-done
(so-notify:so-cancel:sor src %gone *human)
::
::> || %fora
::> fora things.
::TODO move outside of guardian...
::+|
::
++ ta-base-hart
2017-03-23 03:34:56 +03:00
::x produces our ship's host desk's web address as a hart.
::
.^(hart %e /(scot %p our.bol)/host/(scot %da now.bol))
2017-03-23 03:34:56 +03:00
::
++ ta-fora-post
2017-03-23 03:34:56 +03:00
::x sends a fora post. if we don't have a channel for posts yet, create one
::
|= {pax/path sup/spur hed/@t txt/@t}
::x tell %hood to submit a fora post.
=. ..ta-emit
%+ ta-emit ost.bol
2017-03-23 03:34:56 +03:00
:* %poke
/fora-post
[our.bol %hood]
[%write-fora-post sup src.bol hed txt]
2017-03-23 03:34:56 +03:00
==
=+ man=%posts
::x if we have a %posts story, go ahead and consume.
?: (~(has by stories) man)
(ta-consume-fora-post man pax hed txt)
2017-03-23 03:34:56 +03:00
::x if we have no %posts story, first create it, then consume.
=; new (ta-consume-fora-post:new man pax hed txt)
=. ..ta-action
%+ ta-action ost.bol
[%create man 'towards a community' %brown]
2017-03-23 03:34:56 +03:00
::x send informative message to our mailbox.
%^ ta-consume & our.bol
:^ (shaf %init eny.bol) ::< serial
(my [[%& our.bol (main our.bol)] *envelope %pending] ~) ::< audience
::> statement
now.bol
2017-03-23 03:34:56 +03:00
[~ %app %tree 'receiving forum posts, ;join %posts for details']
::
++ ta-consume-fora-post
2017-03-23 03:34:56 +03:00
::x add a message for a fora post to the man story.
::
|= {man/knot pax/path hed/@t txt/@t} ^+ +>
=. pax (welp pax /posts/(crip "{<now.bol>}~"))
%^ ta-consume |
src.bol
:* (shaf %comt eny.bol)
(my [[%& our.bol man] *envelope %pending] ~)
now.bol
2017-03-23 03:34:56 +03:00
(sy /fora-post eyre+pax ~)
:- %mor :~
[%fat text+(lore txt) [%url [ta-base-hart `pax ~] ~]]
2017-03-23 03:34:56 +03:00
[%app %tree (crip "forum post: '{(trip hed)}'")]
==
==
::
++ ta-comment
2017-03-23 03:34:56 +03:00
::x sends a comment. if we don't have a channel for them yet, creates one.
::
|= {pax/path sup/spur txt/@t}
=. ..ta-emit
%+ ta-emit ost.bol
2017-03-23 03:34:56 +03:00
:* %poke
/comment
[our.bol %hood]
[%write-comment sup src.bol txt]
2017-03-23 03:34:56 +03:00
==
=+ man=%comments
?: (~(has by stories) man)
(ta-consume-comment man pax sup txt)
=; new (ta-consume-comment:new man pax sup txt)
=. ..ta-action
%+ ta-action ost.bol
[%create man 'letters to the editor' %brown]
%^ ta-consume & our.bol
:^ (shaf %init eny.bol)
(my [[%& our.bol (main our.bol)] *envelope %pending] ~)
now.bol
2017-03-23 03:34:56 +03:00
[~ %app %tree 'receiving comments, ;join %comments for details']
::
++ ta-consume-comment
2017-03-23 03:34:56 +03:00
::x adds a message for a comment to the man story.
::
|= {man/knot pax/path sup/spur txt/@t} ^+ +>
=+ nam=?~(sup "" (trip i.sup)) :: file name
=+ fra=(crip (time-to-id now.bol)) :: url fragment
%^ ta-consume |
src.bol
:* (shaf %comt eny.bol)
(my [[%& our.bol man] *envelope %pending] ~)
now.bol
2017-03-23 03:34:56 +03:00
(sy /comment eyre+pax ~)
:- %mor :~
[%fat text+(lore txt) [%url [ta-base-hart `pax ~] `fra]]
2017-03-23 03:34:56 +03:00
[%app %tree (crip "comment on /{nam}")]
==
==
::
::> ||
::> || %messaging
::> ||
::> arms for sending and processing messages.
::+|
::
++ ta-think ::< publish or review
::> consumes each thought.
2017-03-23 03:34:56 +03:00
::
|= {pub/? aut/ship tos/(list thought)}
2017-03-23 03:34:56 +03:00
^+ +>
?~ tos +>
$(tos t.tos, +> (ta-consume pub aut i.tos))
2017-03-23 03:34:56 +03:00
::
++ ta-sane ::< sanitize
::> sanitize %lin speech, enforce lowercase and no special characters.
::TODO make configurable per-circle.
2017-03-23 03:34:56 +03:00
::
|= tot/thought
2017-03-23 03:34:56 +03:00
^- thought
?. ?=({$lin *} sep.sam.tot) tot
%_ tot
msg.sep.sam
2017-03-23 03:34:56 +03:00
%- crip
%+ scag 64
%- tufa
%+ turn (tuba (trip msg.sep.sam.tot))
2017-03-23 03:34:56 +03:00
|= a/@c
?: &((gte a 'A') (lte a 'Z'))
(add a 32)
?: |((lth a 32) (gth a 126))
`@`'?'
a
==
::
2017-04-21 17:14:11 +03:00
++ ta-consume ::< to each audience
::> conducts thought {tot} to each partner in its audience.
2017-03-23 03:34:56 +03:00
::
|= {pub/? aut/ship tot/thought}
=. tot (ta-sane tot)
=+ aud=(~(tap by aud.tot))
2017-03-23 03:34:56 +03:00
|- ^+ +>.^$
?~ aud +>.^$
$(aud t.aud, +>.^$ (ta-conduct pub aut p.i.aud tot))
2017-03-23 03:34:56 +03:00
::
2017-04-21 17:14:11 +03:00
++ ta-conduct ::< thought to partner
::> either publishes or records a thought.
2017-03-23 03:34:56 +03:00
::
|= {pub/? aut/ship pan/partner tot/thought}
2017-03-23 03:34:56 +03:00
^+ +>
?- -.pan
$& ::< circle partner
?: pub
?. (team our.bol aut)
%- ta-note
(crip "strange author {(scow %p aut)}")
=. aut our.bol
?: =(aut hos.p.pan)
(ta-record nom.p.pan hos.p.pan tot)
(ta-transmit p.pan tot)
?. =(our.bol hos.p.pan) +>
(ta-record nom.p.pan aut tot)
::
$| !! ::< passport partner
2017-03-23 03:34:56 +03:00
==
::
++ ta-record ::< add to story
::> add or update telegram {gam} in story {nom}.
2017-03-23 03:34:56 +03:00
::
|= {nom/knot gam/telegram}
%- (ta-know nom) |= sor/_so =< so-done
(so-learn:sor gam)
2017-03-23 03:34:56 +03:00
::
++ ta-transmit ::< send message
::> sends thought {tot} to {cir}.
::> stores it to the outbox to await confirmation.
2017-03-23 03:34:56 +03:00
::
|= {cir/circle tot/thought}
2017-03-23 03:34:56 +03:00
^+ +>
=. +>
%+ ta-emit ost.bol
2017-03-23 03:34:56 +03:00
:* %poke
/repeat/(scot %ud p.outbox)/(scot %p hos.cir)/[nom.cir]
[hos.cir %talk-guardian]
[%talk-command [%review tot ~]]
2017-03-23 03:34:56 +03:00
==
+>(p.outbox +(p.outbox), q.outbox (~(put by q.outbox) p.outbox tot))
2017-03-23 03:34:56 +03:00
::
++ ta-coup-repeat ::< remove from outbox
::> assemble partner and call ++ta-repeat.
::
|= {{num/@ud src/ship nom/knot} fal/(unit tang)}
(ta-repeat num [%& src nom] fal)
::
++ ta-repeat ::< remove from outbox
::> take message out of outbox, mark it as received
::> or rejected, based on the existence of error
::> message {fal}.
::
|= {num/@ud pan/partner fal/(unit tang)}
=+ oot=(~(get by q.outbox) num)
?~ oot ~|([%ta-repeat-none num] !!)
=. q.outbox (~(del by q.outbox) num)
=. aud.u.oot
=+ olg=(~(got by aud.u.oot) pan)
%+ ~(put by aud.u.oot) pan
:- -.olg
?~ fal %received
~> %slog.[0 u.fal]
%rejected
(ta-think | our.bol u.oot ~)
::
::> ||
::> || %stories
::> ||
::> arms for modifying stories.
::+|
::
++ ta-config ::< configure story
::> configures story {nom}, creating it if needed.
::> if it's a whitelist config, and we're creating
::> the story, makes sure we're in it.
::
|= {nom/knot con/config}
^+ +>
::> neu: is new story
::> pur: the story
::> wyt: will be white
=+ :+ neu=!(~(has by stories) nom)
pur=(fall (~(get by stories) nom) *story)
wyt=?=(?($white $green) sec.con.con)
=. ses.con.con ::TODO =?
?: &(neu wyt) [our.bol ~ ~]
ses.con.con
so-done:(~(so-reform so nom ~ pur) con)
::
++ ta-unconfig ::< delete story
::> calls the story core to delete story {nom}.
::
|= nom/knot
^+ +>
2017-04-21 17:14:11 +03:00
%- (ta-know nom) |= sor/_so =< so-done
so-reform-gone:so
::
++ so ::< story core
::> story core, used for doing work on a story.
::
|_ ::> nom: story name in {stories}.
::> acs: talk actions issued due to changes.
::> story is faceless to ease data access.
2017-03-23 03:34:56 +03:00
::
$: nom/knot
acs/(list action)
2017-03-23 03:34:56 +03:00
story
==
::
++ so-done ::< apply changes
::> put changed story back into the map and apply
::> actions.
2017-03-23 03:34:56 +03:00
::
^+ +>
=. +> +>(stories (~(put by stories) nom +<+>))
=. acs (flop acs)
|- ^+ +>+
?~ acs +>+
=. +>+ (ta-action ost.bol i.acs)
$(acs t.acs)
::
::> ||
::> || %emitters
::> ||
::> arms that create outward changes.
::+|
2017-03-23 03:34:56 +03:00
::
++ so-sauce ::< send backward
::> cards to moves, prepend to {moves} reversed.
2017-03-23 03:34:56 +03:00
::
|= {ost/bone cub/(list card)}
%_ +>.$
moves
(welp (flop (turn cub |=(a/card [ost a]))) moves)
2017-03-23 03:34:56 +03:00
==
::
++ so-act ::< send action
::> stores a talk action.
2017-03-23 03:34:56 +03:00
::
|= act/action
2017-03-23 03:34:56 +03:00
^+ +>
+>(acs [act acs])
2017-03-23 03:34:56 +03:00
::
++ so-note ::< tell user
::> sends {msg} as an %app message to the user's
::> inbox.
::
|= msg/cord
^+ +>
%+ so-act %phrase
:- [[%& our.bol (main our.bol)] ~ ~]
[%app %talk-guardian msg]~
::
++ so-inform ::< send lowdown
::> sends lowdown to all interested readers.
::
|= low/lowdown
=. moves
%+ weld
^- (list move)
%+ murn (~(tap by readers))
|= {b/bone s/(set knot)}
^- (unit move)
?. (~(has in s) nom) ~
`[b %diff %talk-lowdown low]
moves
+>.$
::
++ so-report ::< send update
::> sends report to all bones.
2017-03-23 03:34:56 +03:00
::
|= {bos/(set bone) ret/report}
^+ +>
?~ bos +>
=. +> $(bos l.bos)
=. +> $(bos r.bos)
(so-sauce n.bos [%diff %talk-report ret]~)
2017-03-23 03:34:56 +03:00
::
++ so-report-crowd ::< presence update
::> send local and remote presences in a report.
::
|= bos/(set bone)
2017-04-27 00:33:25 +03:00
(so-report bos %crowd locals so-remotes)
::
2017-04-27 00:33:25 +03:00
++ so-report-lobby ::< config update
::> send local and remote configs in a report.
2017-03-23 03:34:56 +03:00
::
|= bos/(set bone)
2017-04-27 00:33:25 +03:00
(so-report bos %lobby shape mirrors)
::
::> ||
::> || %data
::> ||
::> utility functions for data retrieval.
::+|
2017-03-23 03:34:56 +03:00
::
++ so-followers ::< follower bones
::> turns the keys of {followers} into a set.
2017-03-23 03:34:56 +03:00
::
^- (set bone)
%- ~(gas in *(set bone))
%+ turn (~(tap by followers))
|= {b/bone *} b
2017-03-23 03:34:56 +03:00
::
++ so-unearth ::< ships' bones
::> find the bones in {followers} that belong to
::> a ship in {sis}.
2017-03-23 03:34:56 +03:00
::
|= sis/(set ship)
^- (set bone)
%- ~(rep in sup.bol)
|= {{b/bone s/ship p/path} c/(set bone)}
?. ?& (~(has in sis) s)
(~(has by followers) b)
?=({@tas *} p)
=(i.p nom)
==
c
(~(put in c) b)
2017-03-23 03:34:56 +03:00
::
++ so-remotes ::< remote presences
::> produces {remotes}, with all our local
::> presences replaced by the versions from their
::> stories.
2017-03-23 03:34:56 +03:00
::
%- ~(urn by remotes) :: XX performance
2017-04-27 00:33:25 +03:00
|= {pan/partner gop/group}
^- group
?. &(?=($& -.pan) =(our.bol hos.p.pan)) gop
=+ soy=(~(get by stories) nom.p.pan)
2017-04-27 00:33:25 +03:00
?~ soy gop
locals.u.soy
2017-03-23 03:34:56 +03:00
::
++ so-right ::< is federator?
::> checks whether partner {pan} has authority
::> over this story.
::
|= pan/partner
?& ?=($& -.pan)
=(nom nom.p.pan)
(~(has in fes.fed.shape) hos.p.pan)
==
::
::> ||
::> || %interaction-events
::> ||
::> arms that apply events we received.
::+|
::
++ so-burden ::< accept federator
::> if {src} is allowed to, have it federate this
::> story.
::> starts by assimilating {src}'s state into our
::> own (giving priority to local state), removing
::> redundant data, then sending updated state to
::> all followers.
::
|= {src/ship cof/lobby pes/crowd gaz/(list telegram)}
^+ +>
:: continue if permitted and not yet done.
?. (~(has in may.fed.shape) src) +>
?: (~(has in fes.fed.shape) src) +>
:: assimilate config.
=. +>
=+ nec=shape
:: adopt security list if they're similar.
=. ses.con.nec ::TODO =?
?. .= ?=(?($white $green) sec.con.nec)
?=(?($white $green) sec.con.loc.cof)
ses.con.nec
(~(uni in ses.con.nec) ses.con.loc.cof)
=. fes.fed.nec
(~(put in fes.fed.nec) src)
=. src.nec
(~(put in src.nec) [%& src nom])
(so-reform nec)
:: assimilate presence and remotes.
=. locals (~(uni by loc.pes) locals)
=. remotes (~(uni by rem.pes) remotes)
=. mirrors (~(uni by rem.cof) mirrors)
:: remove redundant remotes.
=. remotes
%- ~(gas by *_remotes)
%+ murn (~(tap by remotes))
|= {p/partner g/group}
^- (unit {partner group})
?: ?& ?=($& -.p)
=(nom.p.p nom)
(~(has in fes.fed.shape) hos.p.p)
==
~
`[p g]
:: remove redundant mirrors.
=. mirrors
%- ~(gas by *_mirrors)
%+ murn (~(tap by mirrors))
|= {c/circle f/config}
^- (unit {circle config})
?: ?& =(nom.c nom)
(~(has in fes.fed.shape) hos.c)
==
~
`[c f]
:: send updates to followers.
=. +>.$ (so-report-crowd so-followers)
=. +>.$ (so-report-lobby so-followers)
:: finally, learn all grams.
(so-lesson gaz)
::
++ so-relieve ::< remove federator
::> if {src} is allowed to, removes {who} as
::> federators from this story.
::
|= {src/ship who/(set ship)}
^+ +>
?. (~(has in fes.fed.shape) src) +>
=+ nes=shape
=. fes.fed.nes
(~(dif in fes.fed.nes) who)
=. src.nes
%- ~(dif in src.nes)
^- (set partner)
%- ~(run in who)
|=(s/ship [%& s nom])
?: =(nes shape) +>.$
::TODO propogate %relief to other federators.
(so-reform nes)
::
++ so-diff-report ::< process update
::> process a talk report from {cir}.
::> if we didn't expect it, ignore.
2017-03-23 03:34:56 +03:00
::
|= {cir/circle ret/report}
^+ +>
?: =(cir [our.bol nom]) +>
?. (~(has in src.shape) [%& cir])
%- so-note
%- crip ;: weld
"so-diff unexpected "
(scow %p hos.cir) "/" (trip nom.cir)
" %" (scow %tas -.ret)
" in " (scow %tas nom)
==
?- -.ret
2017-04-27 00:33:25 +03:00
$lobby (so-lobby cir +.ret)
$crowd (so-remind [%& cir] +.ret)
$grams (so-lesson gaz.ret)
2017-03-23 03:34:56 +03:00
==
::
2017-04-27 00:33:25 +03:00
++ so-lobby ::< update config
::> add circle's config to our remote config map.
2017-03-23 03:34:56 +03:00
::
::TODO when do we care about rem?
|= {cir/circle con/config rem/(map circle config)}
^+ +>
:: if they're a federator, set new shape.
=. +> ::TODO =?
?. ?& =(nom nom.cir)
(~(has in fes.fed.shape) hos.cir)
==
+>
:: to prevent removal of federators during initial setup, only allow
:: federator deletion through explicit action.
=. fes.fed.con (~(uni in fes.fed.con) fes.fed.shape)
=. may.fed.con (~(uni in may.fed.con) may.fed.shape)
=. src.con ::TODO is this needed?
%- ~(uni in src.con)
^- (set partner)
%- ~(run in fes.fed.con)
|= s/ship
^- partner
[%& s nom]
(so-reform con)
=+ old=mirrors
=. mirrors (~(put by mirrors) cir con)
?: =(mirrors old) +>.$
=. +>.$ (so-inform %confs `shape (strap cir `con))
2017-04-27 00:33:25 +03:00
(so-report-lobby so-followers)
2017-03-23 03:34:56 +03:00
::
++ so-remind ::< remote presence
2017-04-27 00:33:25 +03:00
::> adds {tay}'s {loc} to our remote presence map,
::> after merging with {rem}.
::> if this changes anything, send a report.
2017-03-23 03:34:56 +03:00
::
2017-04-27 00:33:25 +03:00
|= {pan/partner loc/group rem/(map partner group)}
:: if they're a federator, set new locals.
=/ buk (~(uni by remotes) rem)
=. buk (~(put by buk) pan loc)
:: seperate federation presences and true remotes.
=/ nep/crowd
%+ roll (~(tap by buk))
|= {{p/partner g/group} c/crowd}
?: (so-right p)
[(~(uni by loc.c) g) rem.c]
[loc.c (~(put by rem.c) p g)]
:: ensure we have the latest.
=. loc.nep
?. (so-right pan) (~(uni by locals) loc.nep)
(~(uni by (~(uni by locals) loc.nep)) loc)
:: if nothing changed, we're done.
?: ?& =(loc.nep locals)
=(rem.nep remotes)
==
+>.$
:: reader update.
=. +>.$ ::TODO =?
%^ so-inform %precs
(~(dif in loc.nep) locals) :: locals
:: per-partner diff for remotes.
%- ~(urn by rem.nep)
2017-04-27 00:33:25 +03:00
|= {p/partner a/group}
=+ o=(~(get by remotes) p)
?~(o a (~(dif in a) u.o))
:: subscriber update.
(so-report-crowd(locals loc.nep, remotes rem.nep) so-followers)
::
::> ||
::> || %changes
::> ||
::> arms that make miscelaneous changes to this story.
::+|
2017-03-23 03:34:56 +03:00
::
++ so-reform ::< reconfigure
2017-04-27 00:33:25 +03:00
::> changes the config of this story and notify
::> our followers.
::> subscribes to new sources, unsubs from removed
::> ones.
2017-03-23 03:34:56 +03:00
::
|= cof/config
?: =(cof shape) +>
=. +>.$ (so-inform %confs `cof ~)
=/ dif/(pair (list partner) (list partner))
=+ old=`(list partner)`(~(tap in src.shape) ~)
=+ new=`(list partner)`(~(tap in src.cof) ~)
:- (skip new |=(a/partner (~(has in src.shape) a)))
(skip old |=(a/partner (~(has in src.cof) a)))
=. +>.$ (so-acquire p.dif)
=. +>.$ (so-abjure q.dif)
2017-03-23 03:34:56 +03:00
=. shape cof
2017-04-27 00:33:25 +03:00
(so-report-lobby so-followers)
2017-03-23 03:34:56 +03:00
::
++ so-reform-gone ::< delete story
::> deletes this story. removes it from {stories}
::> and unsubscribes from all src.
2017-03-23 03:34:56 +03:00
::
=. stories (~(del by stories) nom)
=. . (so-inform %confs ~ ~)
2017-04-27 00:33:25 +03:00
=. . (so-report-lobby so-followers)
(so-abjure (~(tap in src.shape)))
2017-03-23 03:34:56 +03:00
::
++ so-notify ::< local presence
::> add {her} status to this story's presence map.
::> if this changes it, send a report.
2017-03-23 03:34:56 +03:00
::
|= {her/ship sat/status}
2017-03-23 03:34:56 +03:00
^+ +>
=/ nol (~(put by locals) her sat)
2017-03-23 03:34:56 +03:00
?: =(nol locals) +>.$
=. +>.$ (so-inform %precs (strap her sat) ~)
(so-report-crowd(locals nol) so-followers)
::
::> ||
::> || %subscriptions
::> ||
::> arms for starting and ending subscriptions
::+|
2017-03-23 03:34:56 +03:00
::
++ so-acquire ::< subscribe us
::> subscribes this story to each partner.
2017-03-23 03:34:56 +03:00
::
|= pas/(list partner)
%+ so-sauce 0 :: subscription is caused by this app
%- zing
%+ turn pas
|= pan/partner
^- (list card)
::> subscribe starting at the last message we got,
::> or if we haven't gotten any yet, messages
::> from up to a day ago.
=+ num=(~(get by sequence) pan)
=+ old=(sub now.bol ~d1) :: XX full backlog
=+ ini=?^(num (scot %ud u.num) (scot %da old))
?- -.pan
$| !! ::< passport partner
::
$& ::< circle partner
:_ ~
:* %peer
/friend/show/[nom]/(scot %p hos.p.pan)/[nom.p.pan]
[hos.p.pan %talk-guardian]
/[nom.p.pan]/[ini]
==
==
2017-03-23 03:34:56 +03:00
::
++ so-abjure ::< unsubscribe us
::> unsubscribes this story from each partner.
::
|= pas/(list partner)
%+ so-sauce 0 :: subscription is caused by this app
%- zing
%+ turn pas
|= pan/partner
^- (list card)
?- -.pan
$| !! ::< passport partner
::
$& ::< circle partner
:_ ~
:* %pull
/friend/show/[nom]/(scot %p hos.p.pan)/[nom.p.pan]
[hos.p.pan %talk-guardian]
~
==
==
::
++ so-quit ::< subscription failed
::> delete {pan} from our subscriptions, then send
::> an updated capal report.
::
|= pan/partner
^+ +>
?. (~(has in src.shape) pan) +>
=. src.shape (~(del in src.shape) pan)
=. +> (so-inform %confs `shape ~)
2017-04-27 00:33:25 +03:00
(so-report-lobby so-followers)
::
++ so-start ::< subscribe follower
::> called upon subscribe. deduces the range of
::> {her} subscription from {pax}, then sends
::> the currently available part of it.
::
|= {her/ship pax/path}
^+ +>
:: read permissions
?. (so-visible her)
=. +>
(so-sauce ost.bol [%quit ~]~)
%- so-note %- crip
"so-start permission denied {(scow %p her)}"
:: find grams range
=/ ruv/(unit river)
:: collapse unit list
%+ biff
%- zl:jo
%+ turn pax
;~(biff slay |=(a/coin `(unit dime)`?~(-.a a ~)))
|= paf/(list dime)
?~ paf
$(paf [%ud (sub (max 64 count) 64)]~)
?~ t.paf
$(t.paf [%da (dec (bex 128))]~)
?. ?=({{?($ud $da) @} {?($ud $da) @} $~} paf)
~
`[[?+(- . $ud .)]:i.paf [?+(- . $ud .)]:i.t.paf] ::XX arvo issue #366
?~ ruv
=. +>.$
(so-sauce ost.bol [%quit ~]~)
%- so-note %- crip
"so-start malformed path {~(ram re >pax<)}"
(so-first-grams u.ruv)
::
++ so-first-grams ::< beginning of stream
::> find all grams that fall within the river and
::> send them in a grams report to {ost.bol}.
2017-03-23 03:34:56 +03:00
::
|= riv/river
^+ +>
=; lab/{dun/? end/@u zeg/(list telegram)}
2017-03-23 03:34:56 +03:00
=. +>.$
(so-sauce ost.bol [[%diff %talk-report %grams end.lab zeg.lab] ~])
?: dun.lab
(so-sauce ost.bol [[%quit ~] ~])
+>.$(followers (~(put by followers) ost.bol riv))
2017-03-23 03:34:56 +03:00
=+ [end=count gaz=grams dun=| zeg=*(list telegram)]
|- ^- (trel ? @ud (list telegram))
?~ gaz [dun end zeg]
?: ?- -.q.riv :: after the end
$ud (lte p.q.riv end)
$da (lte p.q.riv wen.sam.tot.i.gaz)
2017-03-23 03:34:56 +03:00
==
:: if past the river, continue back, mark as done.
$(end (dec end), gaz t.gaz, dun &)
2017-03-23 03:34:56 +03:00
?: ?- -.p.riv :: before the start
$ud (lth end p.p.riv)
$da (lth wen.sam.tot.i.gaz p.p.riv)
2017-03-23 03:34:56 +03:00
==
:: if before the river, we're done searching.
2017-03-23 03:34:56 +03:00
[dun end zeg]
2017-04-21 17:14:11 +03:00
:: if in the river, add this gram and continue.
2017-03-23 03:34:56 +03:00
$(end (dec end), gaz t.gaz, zeg [i.gaz zeg])
::
++ so-cancel ::< unsubscribe follower
::> removes {ost.bol} from our followers.
2017-03-23 03:34:56 +03:00
::
.(followers (~(del by followers) ost.bol))
::
++ so-eject ::< unsubscribe ships
::> removes ships {sis} from {followers}.
::
|= sis/(set ship)
%= +>
followers
%- ~(rep in (so-unearth sis))
|= {b/bone f/_followers}
=. f ?~(f followers f) ::TODO =?
(~(del by f) b)
==
::
::> ||
::> || %messaging
::> ||
::> arms for adding to this story's messages.
::+|
::
++ so-refresh ::< update to listeners
::> called when messages get added or changed.
::> calculates the changes and sends them to all
::> followers.
::> any followers that are no longer interested
::> get removed.
2017-03-23 03:34:56 +03:00
::
|= {num/@ud gam/telegram}
^+ +>
::> notify the interested readers.
=. +> (so-inform %grams num gam ~)
::> notify only the followers who are currently interested.
=/ moy
2017-04-25 22:09:20 +03:00
^- (pair (list bone) (list move))
%- ~(rep in followers)
|= {f/(pair bone river) r/(pair (list bone) (list move))}
:: after the end: unsubscribe
?: ?- -.q.q.f
$ud (lte p.q.q.f num)
$da (lte p.q.q.f wen.sam.tot.gam)
==
[[p.f p.r] [[p.f %quit ~] q.r]]
:: before the start: ignore
?: ?- -.p.q.f
$ud (gth p.p.q.f num)
$da (gth p.p.q.f wen.sam.tot.gam)
==
r
:: in the river: send gram
:- p.r
[[p.f %diff %talk-report %grams num gam ~] q.r]
=. moves (welp q.moy moves)
2017-03-23 03:34:56 +03:00
|- ^+ +>.^$
?~ p.moy +>.^$
2017-03-25 02:54:56 +03:00
$(p.moy t.p.moy, followers (~(del by followers) i.p.moy))
2017-03-23 03:34:56 +03:00
::
++ so-lesson ::< learn messages
::> learn all telegrams in a list.
2017-03-23 03:34:56 +03:00
::
|= gaz/(list telegram)
^+ +>
?~ gaz +>
$(gaz t.gaz, +> (so-learn i.gaz))
2017-03-23 03:34:56 +03:00
::
++ so-learn ::< save/update message
::> store an incoming telegram, updating if it
::> already exists.
2017-03-23 03:34:56 +03:00
::
|= gam/telegram
^+ +>
?. (so-admire aut.gam) ::< write permissions
2017-03-23 03:34:56 +03:00
+>.$
=. aud.tot.gam
::> if we are in the audience, mark as received.
=+ ole=(~(get by aud.tot.gam) [%& our.bol nom])
?^ ole (~(put by aud.tot.gam) [%& our.bol nom] -.u.ole %received)
::> federated circles need to pretend ~src/nom
::> is also ~our/nom.
::TODO pass src through explicitly instead of
2017-04-25 22:09:20 +03:00
:: relying on src.bol.
=+ ole=(~(get by aud.tot.gam) [%& src.bol nom])
?~ ole aud.tot.gam
::> as described above, fake src into our.
=. aud.tot.gam (~(del by aud.tot.gam) [%& src.bol nom])
(~(put by aud.tot.gam) [%& our.bol nom] -.u.ole %received)
=+ old=(~(get by known) uid.tot.gam)
2017-03-23 03:34:56 +03:00
?~ old
(so-append gam) ::< add
(so-revise u.old gam) ::< modify
2017-03-23 03:34:56 +03:00
::
++ so-append ::< append message
::> add gram to our story, send report to subs.
2017-03-23 03:34:56 +03:00
::
|= gam/telegram
^+ +>
%+ %= so-refresh
2017-03-23 03:34:56 +03:00
grams [gam grams]
count +(count)
known (~(put by known) uid.tot.gam count)
2017-03-23 03:34:56 +03:00
==
count
gam
::
++ so-revise ::< revise message
::> modify gram in our story, send report to subs.
2017-03-23 03:34:56 +03:00
::
|= {num/@ud gam/telegram}
::> dex: index in grams list to insert message at.
=+ dex=(sub count num)
?: =(gam (snag (dec dex) grams)) +>.$ ::< no change
=. grams
%+ welp
(scag (dec dex) grams)
[gam (slag dex grams)]
(so-refresh num gam)
::
::> ||
::> || %permissions
::> ||
::> arms relating to story permissions.
::+|
::
++ so-permit ::< invite/banish
::> update config to dis/allow ships permission.
::
|= {inv/? sis/(set ship)}
^+ +>
::> wyt: whitelist?
::> add: add to list?
=/ wyt/? ?=(?($white $green) sec.con.shape)
=/ add/? =(inv wyt)
=. +>.$ ::TODO =?
?: inv +>.$
(so-eject sis)
=. +>.$
%- so-act
:- %phrase
%- ~(rep in sis)
|= {s/ship a/(set partner) t/(list speech)}
:- (~(put in a) [%& s (main s)])
[[%inv inv [our.bol nom]] t]
%- so-reform
%= shape
ses.con
%. sis
?: add
~(uni in ses.con.shape)
~(dif in ses.con.shape)
==
::
++ so-admire ::< accept from
::> checks {her} write permissions.
::
|= her/ship
^- ?
?- sec.con.shape
$black !(~(has in ses.con.shape) her) ::< channel, blacklist
$white (~(has in ses.con.shape) her) ::< village, whitelist
$green (~(has in ses.con.shape) her) ::< journal, whitelist
$brown !(~(has in ses.con.shape) her) ::< mailbox, blacklist
==
::
++ so-visible ::< display to
::> checks {her} read permissions.
::
|= her/ship
^- ?
?- sec.con.shape
$black !(~(has in ses.con.shape) her) ::< channel, blacklist
$white (~(has in ses.con.shape) her) ::< village, whitelist
$green & ::< journal, all
$brown (team our.bol her) ::< mailbox, our team
==
2017-03-23 03:34:56 +03:00
--
--
::
::> ||
::> || %wire-parsing
::> ||
::+|
::
++ etch ::< parse wire
::> parses {wir}} to obtain either %friend with story
::> and circle or %repeat with message number,
::> source ship and story.
2017-03-23 03:34:56 +03:00
::
|= wir/wire
^- weir
?+ -.wir !!
$friend
?> ?=({$show @ @ @ $~} t.wir)
:^ %friend
i.t.t.wir
(slav %p i.t.t.t.wir)
i.t.t.t.t.wir
::
$repeat
?> ?=({@ @ @ $~} t.wir)
:^ %repeat
(slav %ud i.t.wir)
(slav %p i.t.t.wir)
i.t.t.t.wir
==
2017-03-23 03:34:56 +03:00
::
++ etch-friend ::< parse /friend wire
::> parses a /friend wire, call a gate with the result.
2017-03-23 03:34:56 +03:00
::
|= $: wir/wire
$= fun
$- {nom/knot cir/circle}
{(list move) _.}
==
=+ wer=(etch wir)
?>(?=($friend -.wer) (fun nom.wer cir.wer))
2017-03-23 03:34:56 +03:00
::
++ etch-repeat ::< parse /repeat wire
::> parses a /repeat wire, call gate with the result.
::
|= $: wir/wire
$= fun
$- {num/@ud src/ship nom/knot}
{(list move) _.}
==
=+ wer=(etch wir)
?>(?=($repeat -.wer) (fun num.wer hos.wer nom.wer))
::
::> ||
::> || %poke-events
::> ||
::+|
::
++ poke-talk-command ::< accept command
::> incoming talk command. process it and update logs.
2017-03-23 03:34:56 +03:00
::
|= cod/command
2017-03-23 03:34:56 +03:00
^- (quip move +>)
=^ mos +>.$
ta-done:(ta-apply:ta src.bol cod)
=^ mow +>.$
log-all-to-file
2017-03-23 03:34:56 +03:00
[(welp mos mow) +>.$]
::
++ poke-talk-action ::< accept action
::> incoming talk action. process it.
2017-03-23 03:34:56 +03:00
::
|= act/action
^- (quip move +>)
?. (team src.bol our.bol)
=< ta-done
%- ta-note:ta %- crip
"talk-action stranger {(scow %p src.bol)}"
ta-done:(ta-action:ta ost.bol act)
2017-03-23 03:34:56 +03:00
::
++ poke-talk-comment ::< do comment
::> sends a comment.
2017-03-23 03:34:56 +03:00
::
|= {pax/path sup/spur txt/@t}
^- (quip move +>)
ta-done:(ta-comment:ta pax sup txt)
2017-03-23 03:34:56 +03:00
::
++ poke-talk-fora-post ::< do fora post
::> sends a fora post.
2017-03-23 03:34:56 +03:00
::
|= {pax/path sup/spur hed/@t txt/@t}
^- (quip move +>)
ta-done:(ta-fora-post:ta pax sup hed txt)
2017-03-23 03:34:56 +03:00
::
::> ||
::> || %subscription-events
::> ||
::+|
2017-03-23 03:34:56 +03:00
::
++ diff-talk-report ::< accept report
::> incoming talk-report. process it and update logs.
2017-03-23 03:34:56 +03:00
::
|= {wir/wire ret/report}
2017-03-23 03:34:56 +03:00
^- (quip move +>)
=^ mos +>.$
%+ etch-friend wir
|= {nom/knot cir/circle}
ta-done:(ta-diff-report:ta nom cir ret)
=^ mow +>.$
log-all-to-file
[(welp mos mow) +>.$]
2017-03-23 03:34:56 +03:00
::
++ peer ::< accept subscription
::> incoming subscription on {pax}.
2017-03-23 03:34:56 +03:00
::
|= pax/path
^- (quip move +>)
?: ?=({$sole *} pax) ~&(%talk-broker-no-sole !!)
ta-done:(ta-subscribe:ta src.bol pax)
2017-03-23 03:34:56 +03:00
::
++ pull ::< unsubscribe
::> unsubscribes.
2017-03-23 03:34:56 +03:00
::
|= pax/path
^- (quip move +>)
ta-done:(ta-cancel:ta src.bol pax)
2017-03-23 03:34:56 +03:00
::
++ reap-friend ::< subscription n/ack
::> if subscribing failed, update state to reflect
::> that.
2017-03-23 03:34:56 +03:00
::
::TODO this should deal with /reader subscriptions too.
|= {wir/wire fal/(unit tang)}
^- (quip move +>)
?~ fal [~ +>]
%+ etch-friend [%friend wir]
|= {nom/knot cir/circle}
=. u.fal [>%reap-friend-fail nom cir< u.fal]
%- (slog (flop u.fal))
ta-done:(ta-quit:ta nom cir)
2017-03-23 03:34:56 +03:00
::
++ quit-friend ::< dropped subscription
::> gall dropped our subscription. resubscribe.
2017-03-23 03:34:56 +03:00
::
|= wir/wire
^- (quip move +>)
%+ etch-friend [%friend wir]
|= {nom/knot cir/circle}
ta-done:(ta-retry:ta nom cir)
2017-03-23 03:34:56 +03:00
::
++ coup-repeat ::< message n/ack
::> ack from ++ta-transmit. mark the message as
::> received or rejected.
2017-03-23 03:34:56 +03:00
::
|= {wir/wire fal/(unit tang)}
^- (quip move +>)
%+ etch-repeat [%repeat wir]
|= {num/@ud src/ship nom/knot}
ta-done:(ta-coup-repeat:ta [num src nom] fal)
2017-03-23 03:34:56 +03:00
::
::> ||
::> || %logging
::> ||
::+|
2017-03-23 03:34:56 +03:00
::
++ poke-talk-save ::< save as log
::> stores the telegrams of story {nom} in a log file,
::> to be re-loaded by ++poke-talk-load.
2017-03-23 03:34:56 +03:00
::
|= nom/knot
2017-03-23 03:34:56 +03:00
^- (quip move +>)
=/ paf/path
/(scot %p our.bol)/home/(scot %da now.bol)/talk/[nom]/talk-telegrams
=+ grams:(~(got by stories) nom)
:_ +>.$
:_ ~
:* ost.bol
%info
/jamfile
our.bol
(foal paf [%talk-telegrams !>(-)])
==
2017-03-23 03:34:56 +03:00
::
++ poke-talk-load ::< load from log
::> loads the telegrams of story {nom} into our state,
::> as saved in ++poke-talk-save.
2017-03-23 03:34:56 +03:00
::
|= nom/knot
^- (quip move +>)
=/ grams
.^ (list telegram)
%cx
/(scot %p our.bol)/home/(scot %da now.bol)/talk/[nom]/talk-telegrams
==
=+ soy=(~(got by stories) nom)
:- ~
%= +>.$
stories
%+ ~(put by stories) nom
soy(grams grams, count (lent grams))
==
2017-03-23 03:34:56 +03:00
::
++ poke-talk-log ::< start logging
::> starts logging story {nom}'s messages.
2017-03-23 03:34:56 +03:00
::
|= nom/knot
~& %talk-poke-log
2017-03-23 03:34:56 +03:00
^- (quip move +>)
:- [(log-to-file nom) ~]
%= +>.$
log
%+ ~(put by log) nom
count:(~(got by stories) nom)
==
2017-03-23 03:34:56 +03:00
::
++ poke-talk-unlog ::< stop logging
::> stops logging story {nom}'s messages.
2017-03-23 03:34:56 +03:00
::
|= nom/knot
2017-03-23 03:34:56 +03:00
^- (quip move +>)
:- ~
+>.$(log (~(del by log) nom))
2017-03-23 03:34:56 +03:00
::
++ log-all-to-file ::< update stories logs
::> for every story we're logging, (over)writes all
::> their grams to log files if new ones have arrived.
2017-03-23 03:34:56 +03:00
::
::TODO re-enable and test.
^- (quip move .)
?: & [~ .] :: XXX!!!!
:_ %_ .
log
%- ~(urn by log)
|= {nom/knot len/@ud}
count:(~(got by stories) nom)
==
%+ murn (~(tap by log))
|= {nom/knot len/@ud}
^- (unit move)
?: (gte len count:(~(got by stories) nom))
~
`(log-to-file nom)
::
++ log-to-file ::< update story log
::> logs all grams of story {nom} to a file.
::
|= nom/knot
^- move
=+ ^- paf/path
=+ day=(year %*(. (yore now.bol) +.t +:*tarp))
%+ tope [our.bol %home da+now.bol]
/talk-telegrams/(scot %da day)/[nom]/talk
=+ grams:(~(got by stories) nom)
[ost.bol %info /jamfile our.bol (foal paf [%talk-telegrams !>(-)])]
2017-03-23 03:34:56 +03:00
--