2019-11-05 22:30:58 +03:00
|
|
|
:: chat-store: data store that holds linear sequences of chat messages
|
|
|
|
::
|
2020-04-30 02:04:29 +03:00
|
|
|
/+ store=chat-store, default-agent, verb, dbug
|
2020-04-03 00:43:03 +03:00
|
|
|
~% %chat-store-top ..is ~
|
2019-11-05 22:30:58 +03:00
|
|
|
|%
|
2019-11-23 01:04:36 +03:00
|
|
|
+$ card card:agent:gall
|
2019-11-06 02:50:56 +03:00
|
|
|
+$ versioned-state
|
|
|
|
$% state-zero
|
2020-03-07 02:15:03 +03:00
|
|
|
state-one
|
2020-03-27 23:39:22 +03:00
|
|
|
state-two
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
::
|
2020-06-01 21:17:14 +03:00
|
|
|
+$ state-zero [%0 =inbox:store]
|
|
|
|
+$ state-one [%1 =inbox:store]
|
|
|
|
+$ state-two [%2 =inbox:store]
|
2019-11-05 22:30:58 +03:00
|
|
|
--
|
|
|
|
::
|
2020-03-27 23:39:22 +03:00
|
|
|
=| state-two
|
2019-11-07 09:19:32 +03:00
|
|
|
=* state -
|
2020-01-21 23:36:03 +03:00
|
|
|
::
|
|
|
|
%- agent:dbug
|
|
|
|
%+ verb |
|
2019-11-19 07:36:21 +03:00
|
|
|
^- agent:gall
|
2019-11-06 05:52:27 +03:00
|
|
|
=<
|
2020-04-03 00:43:03 +03:00
|
|
|
~% %chat-store-agent-core ..peek-x-envelopes ~
|
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
|
2020-03-07 02:15:03 +03:00
|
|
|
|= old-vase=vase
|
|
|
|
=/ old !<(versioned-state old-vase)
|
2020-03-27 23:39:22 +03:00
|
|
|
?: ?=(%2 -.old)
|
2020-03-07 02:15:03 +03:00
|
|
|
[~ this(state old)]
|
2020-04-25 06:51:28 +03:00
|
|
|
=/ reversed-inbox=inbox:store
|
2020-03-27 23:39:22 +03:00
|
|
|
%- ~(run by inbox.old)
|
2020-04-25 06:51:28 +03:00
|
|
|
|= =mailbox:store
|
|
|
|
^- mailbox:store
|
2020-03-27 23:39:22 +03:00
|
|
|
[config.mailbox (flop envelopes.mailbox)]
|
|
|
|
[~ this(state [%2 reversed-inbox])]
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-poke
|
2020-04-03 00:43:03 +03:00
|
|
|
~/ %chat-store-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))
|
2020-04-25 06:51:28 +03:00
|
|
|
%chat-action (poke-chat-action:cc !<(action:store vase))
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
2019-11-07 09:19:32 +03:00
|
|
|
++ on-watch
|
2020-04-03 00:43:03 +03:00
|
|
|
~/ %chat-store-watch
|
2019-11-05 22:30:58 +03:00
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
|^
|
2020-03-07 02:15:03 +03:00
|
|
|
?> (team:title our.bowl src.bowl)
|
2019-11-05 22:30:58 +03:00
|
|
|
=/ 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)]))
|
2020-05-22 21:21:10 +03:00
|
|
|
[%all ~] (give %chat-update !>([%initial inbox]))
|
2019-11-05 22:30:58 +03:00
|
|
|
[%updates ~] ~
|
|
|
|
[%mailbox @ *]
|
2019-11-06 05:52:27 +03:00
|
|
|
?> (~(has by inbox) t.path)
|
2020-02-04 22:12:51 +03:00
|
|
|
(give %chat-update !>([%create t.path]))
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
[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
|
2020-04-03 00:43:03 +03:00
|
|
|
~/ %chat-store-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 %keys ~] ``noun+!>(~(key by inbox))
|
2019-12-05 23:18:21 +03:00
|
|
|
[%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
|
|
|
--
|
|
|
|
::
|
|
|
|
::
|
2020-04-03 00:43:03 +03:00
|
|
|
~% %chat-store-library ..card ~
|
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)
|
2020-04-30 02:04:29 +03:00
|
|
|
(poke-chat-action (action:dejs:store jon))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ poke-chat-action
|
2020-04-25 06:51:28 +03:00
|
|
|
|= =action:store
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?- -.action
|
2019-11-14 03:53:47 +03:00
|
|
|
%create (handle-create action)
|
|
|
|
%delete (handle-delete action)
|
|
|
|
%read (handle-read action)
|
2020-02-21 00:55:19 +03:00
|
|
|
%messages (handle-messages action)
|
|
|
|
%message
|
|
|
|
?. =(our.bol author.envelope.action)
|
|
|
|
(handle-message action)
|
|
|
|
=^ message-moves state (handle-message action)
|
|
|
|
=^ read-moves state (handle-read [%read path.action])
|
|
|
|
[(weld message-moves read-moves) state]
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-create
|
2020-04-25 06:51:28 +03:00
|
|
|
|= =action:store
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2020-04-25 06:51:28 +03:00
|
|
|
?> ?=(%create -.action)
|
|
|
|
?: (~(has by inbox) path.action) [~ state]
|
|
|
|
:- (send-diff path.action action)
|
|
|
|
state(inbox (~(put by inbox) path.action *mailbox:store))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ handle-delete
|
2020-04-25 06:51:28 +03:00
|
|
|
|= =action:store
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2020-04-25 06:51:28 +03:00
|
|
|
?> ?=(%delete -.action)
|
|
|
|
=/ mailbox=(unit mailbox:store)
|
|
|
|
(~(get by inbox) path.action)
|
2020-03-07 02:15:03 +03:00
|
|
|
?~ mailbox [~ state]
|
2020-04-25 06:51:28 +03:00
|
|
|
:- (send-diff path.action action)
|
|
|
|
state(inbox (~(del by inbox) path.action))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ handle-message
|
2020-04-25 06:51:28 +03:00
|
|
|
|= =action:store
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2020-04-25 06:51:28 +03:00
|
|
|
?> ?=(%message -.action)
|
|
|
|
=/ mailbox=(unit mailbox:store)
|
|
|
|
(~(get by inbox) path.action)
|
2019-11-05 22:30:58 +03:00
|
|
|
?~ mailbox
|
2019-12-05 16:18:11 +03:00
|
|
|
[~ state]
|
2020-04-25 06:51:28 +03:00
|
|
|
=. letter.envelope.action (evaluate-letter [author letter]:envelope.action)
|
|
|
|
=^ envelope u.mailbox (prepend-envelope u.mailbox envelope.action)
|
|
|
|
:- (send-diff path.action action(envelope envelope))
|
|
|
|
state(inbox (~(put by inbox) path.action u.mailbox))
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
2019-11-14 03:53:47 +03:00
|
|
|
++ handle-messages
|
2020-04-25 06:51:28 +03:00
|
|
|
|= act=action:store
|
2019-11-24 10:41:46 +03:00
|
|
|
^- (quip card _state)
|
2019-11-14 03:53:47 +03:00
|
|
|
?> ?=(%messages -.act)
|
2020-04-25 06:51:28 +03:00
|
|
|
=/ mailbox=(unit mailbox:store)
|
|
|
|
(~(get by inbox) path.act)
|
2019-11-14 03:53:47 +03:00
|
|
|
?~ mailbox
|
2019-11-24 10:41:46 +03:00
|
|
|
[~ state]
|
2020-04-03 09:08:58 +03:00
|
|
|
=. envelopes.act (flop envelopes.act)
|
2020-04-25 06:51:28 +03:00
|
|
|
=| evaluated-envelopes=(list envelope:store)
|
2019-11-24 10:41:46 +03:00
|
|
|
|- ^- (quip card _state)
|
2019-11-15 23:27:35 +03:00
|
|
|
?~ envelopes.act
|
2019-11-24 10:41:46 +03:00
|
|
|
:_ state(inbox (~(put by inbox) path.act u.mailbox))
|
2019-11-23 01:04:36 +03:00
|
|
|
%+ send-diff path.act
|
2020-03-27 23:39:22 +03:00
|
|
|
[%messages path.act 0 (lent evaluated-envelopes) evaluated-envelopes]
|
2019-12-03 02:51:01 +03:00
|
|
|
=. letter.i.envelopes.act (evaluate-letter [author letter]:i.envelopes.act)
|
2020-03-27 23:39:22 +03:00
|
|
|
=^ envelope u.mailbox (prepend-envelope u.mailbox i.envelopes.act)
|
|
|
|
=. evaluated-envelopes [envelope evaluated-envelopes]
|
2019-11-14 03:53:47 +03:00
|
|
|
$(envelopes.act t.envelopes.act)
|
2019-11-27 04:47:29 +03:00
|
|
|
::
|
2019-11-05 22:30:58 +03:00
|
|
|
++ handle-read
|
2020-04-25 06:51:28 +03:00
|
|
|
|= act=action:store
|
2019-11-06 02:50:56 +03:00
|
|
|
^- (quip card _state)
|
2019-11-05 22:30:58 +03:00
|
|
|
?> ?=(%read -.act)
|
2020-04-25 06:51:28 +03:00
|
|
|
=/ mailbox=(unit mailbox:store) (~(get by inbox) path.act)
|
2019-11-05 22:30:58 +03:00
|
|
|
?~ 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
|
|
|
::
|
2019-11-15 23:27:35 +03:00
|
|
|
++ evaluate-letter
|
2020-04-25 06:51:28 +03:00
|
|
|
|= [author=ship =letter:store]
|
|
|
|
^- letter:store
|
2019-12-03 02:51:01 +03:00
|
|
|
=? letter
|
|
|
|
?& ?=(%code -.letter)
|
|
|
|
?=(~ output.letter)
|
|
|
|
(team:title our.bol author)
|
|
|
|
==
|
2019-11-15 23:27:35 +03:00
|
|
|
=/ =hoon (ream expression.letter)
|
2020-04-30 02:04:29 +03:00
|
|
|
letter(output (eval:store bol hoon))
|
2019-11-15 23:27:35 +03:00
|
|
|
letter
|
|
|
|
::
|
2020-03-27 23:39:22 +03:00
|
|
|
++ prepend-envelope
|
2020-04-25 06:51:28 +03:00
|
|
|
|= [=mailbox:store =envelope:store]
|
2020-03-15 01:15:41 +03:00
|
|
|
^+ [envelope mailbox]
|
2019-11-15 23:27:35 +03:00
|
|
|
=. number.envelope +(length.config.mailbox)
|
|
|
|
=: length.config.mailbox +(length.config.mailbox)
|
2020-03-27 23:39:22 +03:00
|
|
|
envelopes.mailbox [envelope envelopes.mailbox]
|
2019-11-15 23:27:35 +03:00
|
|
|
==
|
2020-03-15 01:15:41 +03:00
|
|
|
[envelope mailbox]
|
2019-11-15 23:27:35 +03:00
|
|
|
::
|
2019-11-05 22:30:58 +03:00
|
|
|
++ update-subscribers
|
2020-04-25 06:51:28 +03:00
|
|
|
|= [pax=path =update:store]
|
2019-11-05 22:30:58 +03:00
|
|
|
^- (list card)
|
2019-12-22 23:12:28 +03:00
|
|
|
[%give %fact ~[pax] %chat-update !>(update)]~
|
2019-11-05 22:30:58 +03:00
|
|
|
::
|
|
|
|
++ send-diff
|
2020-04-25 06:51:28 +03:00
|
|
|
|= [pax=path upd=update:store]
|
2019-11-05 22:30:58 +03:00
|
|
|
^- (list card)
|
|
|
|
%- zing
|
2019-11-14 03:53:47 +03:00
|
|
|
:~ (update-subscribers /all upd)
|
|
|
|
(update-subscribers /updates upd)
|
|
|
|
(update-subscribers [%mailbox pax] upd)
|
|
|
|
?. |(|(=(%read -.upd) =(%message -.upd)) =(%messages -.upd))
|
2019-11-05 22:30:58 +03:00
|
|
|
~
|
2019-11-14 03:53:47 +03:00
|
|
|
?. |(=(%create -.upd) =(%delete -.upd))
|
2019-11-05 22:30:58 +03:00
|
|
|
~
|
2019-11-14 03:53:47 +03:00
|
|
|
(update-subscribers /keys upd)
|
2019-11-05 22:30:58 +03:00
|
|
|
==
|
|
|
|
--
|