2019-11-05 22:30:58 +03:00
|
|
|
:: chat-store: data store that holds linear sequences of chat messages
|
|
|
|
::
|
|
|
|
/+ *chat-json, *chat-eval, default-agent
|
|
|
|
|%
|
2019-11-19 07:36:21 +03:00
|
|
|
+$ card card:agent:gall
|
2019-11-06 02:50:56 +03:00
|
|
|
+$ versioned-state
|
|
|
|
$% state-zero
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ state-zero
|
2019-11-06 02:50:56 +03:00
|
|
|
$: %0
|
|
|
|
=inbox
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ diff
|
|
|
|
$% [%chat-initial inbox]
|
|
|
|
[%chat-configs chat-configs]
|
|
|
|
[%chat-update chat-update]
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
=| state-zero
|
|
|
|
=* state -
|
2019-11-19 07:36:21 +03:00
|
|
|
^- agent:gall
|
2019-11-06 05:52:27 +03:00
|
|
|
=<
|
2019-11-19 07:36:21 +03:00
|
|
|
|_ =bowl:gall
|
2019-11-07 09:19:32 +03:00
|
|
|
+* this .
|
2019-11-06 05:52:27 +03:00
|
|
|
chat-core +>
|
2019-11-07 09:19:32 +03:00
|
|
|
cc ~(. chat-core bowl)
|
2019-11-09 00:56:35 +03:00
|
|
|
def ~(. (default-agent this %|) bowl)
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-init on-init:def
|
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
2019-11-05 22:30:58 +03:00
|
|
|
|= old=vase
|
2019-11-06 02:50:56 +03:00
|
|
|
`this(state !<(state-zero old))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-poke
|
2019-11-05 22:30:58 +03:00
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
2019-11-06 02:50:56 +03:00
|
|
|
?> (team:title our.bowl src.bowl)
|
2019-11-05 22:30:58 +03:00
|
|
|
=^ cards state
|
2019-11-07 09:19:32 +03:00
|
|
|
?+ mark (on-poke:def mark vase)
|
2019-11-06 05:52:27 +03:00
|
|
|
%json (poke-json:cc !<(json vase))
|
|
|
|
%chat-action (poke-chat-action:cc !<(chat-action vase))
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-watch
|
2019-11-05 22:30:58 +03:00
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
?> (team:title our.bowl src.bowl)
|
|
|
|
|^
|
|
|
|
=/ cards=(list card)
|
2019-11-07 09:19:32 +03:00
|
|
|
?+ path (on-watch:def path)
|
2019-11-06 05:52:27 +03:00
|
|
|
[%keys ~] (give %chat-update !>([%keys ~(key by inbox)]))
|
|
|
|
[%all ~] (give %chat-initial !>(inbox))
|
|
|
|
[%configs ~] (give %chat-configs !>((inbox-to-configs inbox)))
|
2019-11-05 22:30:58 +03:00
|
|
|
[%updates ~] ~
|
|
|
|
[%mailbox @ *]
|
2019-11-06 05:52:27 +03:00
|
|
|
?> (~(has by inbox) t.path)
|
2019-11-05 22:30:58 +03:00
|
|
|
=/ =ship (slav %p i.t.path)
|
|
|
|
(give %chat-update !>([%create ship t.t.path]))
|
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
++ give
|
|
|
|
|= =cage
|
|
|
|
^- (list card)
|
2019-11-07 09:19:32 +03:00
|
|
|
[%give %fact ~ cage]~
|
2019-11-05 22:30:58 +03:00
|
|
|
--
|
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek
|
2019-11-05 22:30:58 +03:00
|
|
|
|= =path
|
|
|
|
^- (unit (unit cage))
|
2019-11-07 09:19:32 +03:00
|
|
|
?+ path (on-peek:def path)
|
2019-11-06 05:52:27 +03:00
|
|
|
[%x %all ~] ``noun+!>(inbox)
|
|
|
|
[%x %configs ~] ``noun+!>((inbox-to-configs inbox))
|
|
|
|
[%x %keys ~] ``noun+!>(~(key by inbox))
|
|
|
|
[%x %envelopes ~] (peek-x-envelopes:cc t.t.path)
|
2019-11-05 22:30:58 +03:00
|
|
|
[%x %mailbox *]
|
|
|
|
?~ t.t.path
|
|
|
|
~
|
2019-11-06 05:52:27 +03:00
|
|
|
``noun+!>((~(get by inbox) t.t.path))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
[%x %config *]
|
|
|
|
?~ t.t.path
|
|
|
|
~
|
2019-11-06 05:52:27 +03:00
|
|
|
=/ mailbox (~(get by inbox) t.t.path)
|
2019-11-05 22:30:58 +03:00
|
|
|
?~ mailbox
|
|
|
|
~
|
|
|
|
``noun+!>(config.u.mailbox)
|
|
|
|
==
|
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-agent on-agent:def
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
2019-11-05 22:30:58 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
::
|
2019-11-19 07:36:21 +03:00
|
|
|
|_ bol=bowl:gall
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ peek-x-envelopes
|
|
|
|
|= pax=path
|
|
|
|
^- (unit (unit [%noun vase]))
|
|
|
|
?+ pax ~
|
|
|
|
[@ @ *]
|
|
|
|
=/ mail-path t.t.pax
|
|
|
|
=/ mailbox (~(get by inbox) mail-path)
|
|
|
|
?~ mailbox
|
|
|
|
[~ ~ %noun !>(~)]
|
|
|
|
=* envelopes envelopes.u.mailbox
|
|
|
|
=/ sign-test=[?(%neg %pos) @]
|
|
|
|
%- need
|
|
|
|
%+ rush i.pax
|
|
|
|
;~ pose
|
|
|
|
%+ cook
|
|
|
|
|= n=@
|
|
|
|
[%neg n]
|
|
|
|
;~(pfix hep dem:ag)
|
|
|
|
::
|
|
|
|
%+ cook
|
|
|
|
|= n=@
|
|
|
|
[%pos n]
|
|
|
|
dem:ag
|
|
|
|
==
|
|
|
|
=* length length.config.u.mailbox
|
|
|
|
=* start +.sign-test
|
|
|
|
?: =(-.sign-test %neg)
|
|
|
|
?: (gth start length)
|
|
|
|
[~ ~ %noun !>(envelopes)]
|
|
|
|
[~ ~ %noun !>((swag [(sub length start) start] envelopes))]
|
|
|
|
::
|
|
|
|
=/ end (slav %ud i.t.pax)
|
|
|
|
?. (lte start end)
|
|
|
|
~
|
|
|
|
=. end ?:((lth end length) end length)
|
|
|
|
[~ ~ %noun !>((swag [start (sub end start)] envelopes))]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ poke-json
|
|
|
|
|= jon=json
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
(poke-chat-action (json-to-action jon))
|
|
|
|
::
|
|
|
|
++ poke-chat-action
|
|
|
|
|= action=chat-action
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?- -.action
|
|
|
|
%create (handle-create action)
|
|
|
|
%delete (handle-delete action)
|
|
|
|
%message (handle-message action)
|
|
|
|
%read (handle-read action)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-create
|
|
|
|
|= act=chat-action
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?> ?=(%create -.act)
|
|
|
|
=/ pax [(scot %p ship.act) path.act]
|
|
|
|
?: (~(has by inbox) pax)
|
2019-11-06 02:50:56 +03:00
|
|
|
[~ state]
|
2019-11-05 22:30:58 +03:00
|
|
|
:- (send-diff pax act)
|
2019-11-06 02:50:56 +03:00
|
|
|
state(inbox (~(put by inbox) pax *mailbox))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ handle-delete
|
|
|
|
|= act=chat-action
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?> ?=(%delete -.act)
|
|
|
|
=/ mailbox=(unit mailbox) (~(get by inbox) path.act)
|
|
|
|
?~ mailbox
|
2019-11-06 02:50:56 +03:00
|
|
|
[~ state]
|
2019-11-05 22:30:58 +03:00
|
|
|
:- (send-diff path.act act)
|
2019-11-06 02:50:56 +03:00
|
|
|
state(inbox (~(del by inbox) path.act))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ handle-message
|
|
|
|
|= act=chat-action
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?> ?=(%message -.act)
|
|
|
|
=/ mailbox=(unit mailbox) (~(get by inbox) path.act)
|
|
|
|
?~ mailbox
|
2019-11-06 02:50:56 +03:00
|
|
|
[~ state]
|
2019-11-05 22:30:58 +03:00
|
|
|
=* letter letter.envelope.act
|
|
|
|
=? letter &(?=(%code -.letter) ?=(~ output.letter))
|
|
|
|
=/ =hoon (ream expression.letter)
|
|
|
|
letter(output (eval bol hoon))
|
|
|
|
=: length.config.u.mailbox +(length.config.u.mailbox)
|
|
|
|
number.envelope.act +(length.config.u.mailbox)
|
|
|
|
envelopes.u.mailbox (snoc envelopes.u.mailbox envelope.act)
|
|
|
|
==
|
|
|
|
:- (send-diff path.act act)
|
2019-11-06 02:50:56 +03:00
|
|
|
state(inbox (~(put by inbox) path.act u.mailbox))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ handle-read
|
|
|
|
|= act=chat-action
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?> ?=(%read -.act)
|
|
|
|
=/ mailbox=(unit mailbox) (~(get by inbox) path.act)
|
|
|
|
?~ mailbox
|
2019-11-06 02:50:56 +03:00
|
|
|
[~ state]
|
2019-11-05 22:30:58 +03:00
|
|
|
=. read.config.u.mailbox length.config.u.mailbox
|
|
|
|
:- (send-diff path.act act)
|
2019-11-06 02:50:56 +03:00
|
|
|
state(inbox (~(put by inbox) path.act u.mailbox))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ update-subscribers
|
|
|
|
|= [pax=path act=chat-action]
|
|
|
|
^- (list card)
|
2019-11-07 09:19:32 +03:00
|
|
|
[%give %fact `pax %chat-update !>(act)]~
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ send-diff
|
|
|
|
|= [pax=path act=chat-action]
|
|
|
|
^- (list card)
|
|
|
|
%- zing
|
|
|
|
:~ (update-subscribers /all act)
|
|
|
|
(update-subscribers /updates act)
|
|
|
|
(update-subscribers [%mailbox pax] act)
|
|
|
|
?. |(=(%read -.act) =(%message -.act))
|
|
|
|
~
|
|
|
|
(update-subscribers /configs act)
|
|
|
|
?. |(=(%create -.act) =(%delete -.act))
|
|
|
|
~
|
|
|
|
(update-subscribers /keys act)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
--
|