2019-11-23 01:05:06 +03:00
|
|
|
:: chat-hook:
|
|
|
|
:: mirror chat data from foreign to local based on read permissions
|
|
|
|
:: allow sending chat messages to foreign paths based on write perms
|
|
|
|
::
|
2020-02-22 01:56:44 +03:00
|
|
|
/- *permission-store, *chat-hook, *invite-store, *metadata-store,
|
|
|
|
*permission-hook, *group-store, *permission-group-hook ::TMP for upgrade
|
2020-02-20 03:04:21 +03:00
|
|
|
/+ *chat-json, *chat-eval, default-agent, verb, dbug
|
2020-04-03 00:43:03 +03:00
|
|
|
~% %chat-hook-top ..is ~
|
2019-11-23 01:05:06 +03:00
|
|
|
|%
|
|
|
|
+$ card card:agent:gall
|
|
|
|
::
|
|
|
|
+$ versioned-state
|
2020-02-21 01:01:21 +03:00
|
|
|
$% state-0
|
|
|
|
state-1
|
2019-11-23 01:05:06 +03:00
|
|
|
==
|
|
|
|
::
|
2020-03-09 22:40:04 +03:00
|
|
|
+$ state-1
|
|
|
|
$: %1
|
2020-03-07 02:15:03 +03:00
|
|
|
loaded-cards=(list card)
|
2020-03-09 22:40:04 +03:00
|
|
|
state-base
|
2020-03-07 02:15:03 +03:00
|
|
|
==
|
2020-03-09 22:40:04 +03:00
|
|
|
+$ state-0 [%0 state-base]
|
2020-02-21 01:01:21 +03:00
|
|
|
+$ state-base
|
2020-03-12 02:28:34 +03:00
|
|
|
$: =synced
|
2019-11-23 01:05:06 +03:00
|
|
|
invite-created=_|
|
|
|
|
allow-history=(map path ?)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ poke
|
|
|
|
$% [%chat-action chat-action]
|
|
|
|
[%permission-action permission-action]
|
|
|
|
[%invite-action invite-action]
|
|
|
|
[%chat-view-action chat-view-action]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ fact
|
|
|
|
$% [%chat-update chat-update]
|
|
|
|
==
|
|
|
|
--
|
2020-02-21 01:01:21 +03:00
|
|
|
=| state-1
|
2019-11-23 01:05:06 +03:00
|
|
|
=* state -
|
2020-01-21 23:36:03 +03:00
|
|
|
::
|
2020-02-21 01:01:21 +03:00
|
|
|
%- agent:dbug
|
2020-04-03 00:43:03 +03:00
|
|
|
%+ verb |
|
2019-11-23 01:05:06 +03:00
|
|
|
^- agent:gall
|
|
|
|
=<
|
2020-04-03 00:43:03 +03:00
|
|
|
~% %chat-hook-agent-core ..poke-json ~
|
2019-11-27 04:43:03 +03:00
|
|
|
|_ bol=bowl:gall
|
2019-11-23 01:05:06 +03:00
|
|
|
+* this .
|
|
|
|
chat-core +>
|
2019-11-27 04:43:03 +03:00
|
|
|
cc ~(. chat-core bol)
|
|
|
|
def ~(. (default-agent this %|) bol)
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
|
|
|
:_ this(invite-created %.y)
|
2019-11-27 04:43:03 +03:00
|
|
|
:~ (invite-poke:cc [%create /chat])
|
2019-11-23 01:05:06 +03:00
|
|
|
[%pass /invites %agent [our.bol %invite-store] %watch /invitatory/chat]
|
|
|
|
[%pass /permissions %agent [our.bol %permission-store] %watch /updates]
|
|
|
|
==
|
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
2020-03-07 02:15:03 +03:00
|
|
|
|= old-vase=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
|^
|
2020-02-21 01:01:21 +03:00
|
|
|
=/ old !<(versioned-state old-vase)
|
|
|
|
?: ?=(%1 -.old)
|
2020-03-20 19:56:17 +03:00
|
|
|
:_ this(state old)
|
|
|
|
%+ murn ~(tap by wex.bol)
|
|
|
|
|= [[=wire =ship =term] *]
|
|
|
|
^- (unit card)
|
|
|
|
?. &(?=([%mailbox *] wire) =(our.bol ship) =(%chat-store term))
|
|
|
|
~
|
|
|
|
`[%pass wire %agent [our.bol %chat-store] %leave ~]
|
2020-02-21 01:01:21 +03:00
|
|
|
:: path structure ugprade logic
|
|
|
|
::
|
2020-03-07 02:15:03 +03:00
|
|
|
=/ keys=(set path) (scry:cc (set path) %chat-store /keys)
|
|
|
|
=/ upgraded-state
|
|
|
|
%* . *state-1
|
|
|
|
synced synced
|
|
|
|
invite-created invite-created
|
|
|
|
allow-history allow-history
|
|
|
|
loaded-cards
|
|
|
|
%- zing
|
|
|
|
^- (list (list card))
|
|
|
|
%+ turn ~(tap in keys) generate-cards
|
|
|
|
==
|
2020-03-09 22:40:04 +03:00
|
|
|
[loaded-cards.upgraded-state this(state upgraded-state)]
|
2020-03-07 02:15:03 +03:00
|
|
|
::
|
|
|
|
++ generate-cards
|
|
|
|
|= old-chat=path
|
|
|
|
^- (list card)
|
|
|
|
=/ host=ship (slav %p (snag 0 old-chat))
|
|
|
|
=/ new-chat [%'~' old-chat]
|
|
|
|
=/ newp=permission (unify-permissions old-chat)
|
|
|
|
=/ old-group=path [%chat old-chat]
|
|
|
|
%- zing
|
|
|
|
:~ :~ (delete-group host (snoc old-group %read))
|
2020-02-25 00:50:19 +03:00
|
|
|
(delete-group host (snoc old-group %write))
|
2020-02-21 01:01:21 +03:00
|
|
|
==
|
|
|
|
::
|
2020-03-07 02:15:03 +03:00
|
|
|
(create-group new-chat who.newp)
|
|
|
|
(hookup-group new-chat kind.newp)
|
|
|
|
[(record-group new-chat new-chat)]~
|
|
|
|
(recreate-chat host old-chat new-chat)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ recreate-chat
|
|
|
|
|= [host=ship chat=path new-chat=path]
|
|
|
|
^- (list card)
|
|
|
|
=/ old-mailbox=mailbox
|
|
|
|
(need (scry:cc (unit mailbox) %chat-store [%mailbox chat]))
|
|
|
|
=* enves envelopes.old-mailbox
|
2020-03-12 06:43:41 +03:00
|
|
|
:~ (chat-poke:cc [%delete new-chat])
|
|
|
|
(chat-poke:cc [%delete chat])
|
2020-03-11 22:12:51 +03:00
|
|
|
(chat-poke:cc [%create new-chat])
|
|
|
|
(chat-poke:cc [%messages new-chat enves])
|
|
|
|
(chat-poke:cc [%read new-chat])
|
2020-03-07 02:15:03 +03:00
|
|
|
%^ make-poke %chat-hook %chat-hook-action
|
|
|
|
!> ^- chat-hook-action
|
|
|
|
?: =(our.bol host) [%add-owned new-chat %.y]
|
|
|
|
[%add-synced host new-chat %.y]
|
|
|
|
==
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
|
|
|
++ unify-permissions
|
|
|
|
|= chat=path
|
|
|
|
^- permission
|
|
|
|
=/ read=(unit permission) (get-permission chat %read)
|
|
|
|
=/ write=(unit permission) (get-permission chat %write)
|
|
|
|
?. &(?=(^ read) ?=(^ write))
|
|
|
|
~& [%missing-permission chat read=?=(~ read) write=?=(~ write)]
|
|
|
|
[%white [(slav %p (snag 0 chat)) ~ ~]]
|
2020-02-25 18:55:49 +03:00
|
|
|
?+ [kind.u.read kind.u.write] !!
|
|
|
|
:: village: exclusive to writers
|
|
|
|
::
|
|
|
|
[%white %white] [%white who.u.write]
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
2020-02-25 18:55:49 +03:00
|
|
|
:: channel: merge blacklists
|
|
|
|
::
|
|
|
|
[%black %black] [%black (~(uni in who.u.read) who.u.write)]
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
2020-02-25 18:55:49 +03:00
|
|
|
:: journal: exclusive to writers
|
|
|
|
::
|
|
|
|
[%black %white] [%white who.u.write]
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
2020-02-25 18:55:49 +03:00
|
|
|
:: mailbox: exclusive to readers
|
|
|
|
::
|
|
|
|
[%white %black] [%white who.u.read]
|
|
|
|
==
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
|
|
|
++ get-permission
|
|
|
|
|= [chat=path what=?(%read %write)]
|
|
|
|
%^ scry:cc (unit permission)
|
|
|
|
%permission-store
|
|
|
|
[%permission %chat (snoc chat what)]
|
|
|
|
::
|
|
|
|
++ make-poke
|
|
|
|
|= [app=term =mark =vase]
|
|
|
|
^- card
|
|
|
|
[%pass /on-load/[app]/[mark] %agent [our.bol app] %poke mark vase]
|
|
|
|
::
|
|
|
|
++ delete-group
|
2020-02-25 00:50:19 +03:00
|
|
|
|= [host=ship group=path]
|
2020-02-21 01:01:21 +03:00
|
|
|
^- card
|
2020-02-25 00:50:19 +03:00
|
|
|
:: if we host the group, delete it directly
|
|
|
|
::
|
|
|
|
?: =(our.bol host)
|
|
|
|
%^ make-poke %group-store
|
|
|
|
%group-action
|
|
|
|
!> ^- group-action
|
|
|
|
[%unbundle group]
|
|
|
|
:: else, just delete the sync in the hook
|
|
|
|
::
|
|
|
|
%^ make-poke %permission-hook
|
|
|
|
%permission-hook-action
|
|
|
|
!> ^- permission-hook-action
|
|
|
|
[%remove group]
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
|
|
|
++ create-group
|
|
|
|
|= [group=path who=(set ship)]
|
|
|
|
^- (list card)
|
|
|
|
:~ %^ make-poke %group-store
|
|
|
|
%group-action
|
|
|
|
!> ^- group-action
|
|
|
|
[%bundle group]
|
|
|
|
::
|
|
|
|
%^ make-poke %group-store
|
|
|
|
%group-action
|
|
|
|
!> ^- group-action
|
|
|
|
[%add who group]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ hookup-group
|
|
|
|
|= [group=path =kind]
|
2020-02-22 01:56:44 +03:00
|
|
|
^- (list card)
|
|
|
|
:* %^ make-poke %permission-group-hook
|
|
|
|
%permission-group-hook-action
|
|
|
|
!> ^- permission-group-hook-action
|
|
|
|
[%associate group [group^kind ~ ~]]
|
|
|
|
::
|
|
|
|
=/ =ship (slav %p (snag 1 group))
|
|
|
|
?. =(our.bol ship) ~
|
|
|
|
:_ ~
|
|
|
|
%^ make-poke %permission-hook
|
|
|
|
%permission-hook-action
|
|
|
|
!> ^- permission-hook-action
|
|
|
|
[%add-owned group group]
|
|
|
|
==
|
2020-02-21 01:01:21 +03:00
|
|
|
::
|
|
|
|
++ record-group
|
|
|
|
|= [group=path chat=path]
|
|
|
|
^- card
|
|
|
|
=/ =metadata
|
|
|
|
~| [%weird-chat-path chat]
|
|
|
|
%* . *metadata
|
2020-03-07 02:15:03 +03:00
|
|
|
title (snag 2 chat)
|
2020-02-21 01:01:21 +03:00
|
|
|
date-created now.bol
|
2020-03-07 02:15:03 +03:00
|
|
|
creator (slav %p (snag 1 chat))
|
2020-02-21 01:01:21 +03:00
|
|
|
==
|
|
|
|
%^ make-poke %metadata-store
|
|
|
|
%metadata-action
|
|
|
|
!> ^- metadata-action
|
|
|
|
[%add group [%chat chat] metadata]
|
|
|
|
--
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ on-poke
|
2020-04-03 00:43:03 +03:00
|
|
|
~/ %chat-hook-poke
|
2019-11-23 01:05:06 +03:00
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
=^ cards state
|
|
|
|
?+ mark (on-poke:def mark vase)
|
2020-03-07 02:15:03 +03:00
|
|
|
%json (poke-json:cc !<(json vase))
|
|
|
|
%chat-action (poke-chat-action:cc !<(chat-action vase))
|
|
|
|
%noun
|
|
|
|
?: =(%store-load q.vase)
|
|
|
|
[loaded-cards.state state(loaded-cards ~)]
|
|
|
|
[~ state]
|
|
|
|
::
|
|
|
|
%chat-hook-action
|
|
|
|
(poke-chat-hook-action:cc !<(chat-hook-action vase))
|
2019-11-23 01:05:06 +03:00
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
++ on-watch
|
2020-04-03 00:43:03 +03:00
|
|
|
~/ %chat-hook-watch
|
2019-11-23 01:05:06 +03:00
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ path (on-watch:def path)
|
2019-11-27 04:43:03 +03:00
|
|
|
[%backlog *] [(watch-backlog:cc t.path) this]
|
|
|
|
[%mailbox *] [(watch-mailbox:cc t.path) this]
|
2020-03-12 02:28:34 +03:00
|
|
|
[%synced *] [(watch-synced:cc t.path) this]
|
2019-11-23 01:05:06 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-agent
|
2020-04-03 00:43:03 +03:00
|
|
|
~/ %chat-hook-agent
|
2019-11-23 01:05:06 +03:00
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ -.sign (on-agent:def wire sign)
|
|
|
|
%watch-ack
|
|
|
|
=^ cards state
|
2020-01-04 00:06:42 +03:00
|
|
|
(watch-ack:cc wire p.sign)
|
2019-11-23 01:05:06 +03:00
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
%kick
|
|
|
|
=^ cards state
|
|
|
|
(kick:cc wire)
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
%fact
|
|
|
|
?+ p.cage.sign (on-agent:def wire sign)
|
|
|
|
%chat-update
|
|
|
|
=^ cards state
|
|
|
|
(fact-chat-update:cc wire !<(chat-update q.cage.sign))
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
%invite-update
|
|
|
|
=^ cards state
|
|
|
|
(fact-invite-update:cc wire !<(invite-update q.cage.sign))
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
%permission-update
|
|
|
|
=^ cards state
|
|
|
|
(fact-permission-update:cc wire !<(permission-update q.cage.sign))
|
|
|
|
[cards this]
|
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
::
|
|
|
|
::
|
2020-04-03 00:43:03 +03:00
|
|
|
~% %chat-hook-library ..card ~
|
2019-11-23 01:05:06 +03:00
|
|
|
|_ bol=bowl:gall
|
|
|
|
::
|
|
|
|
++ poke-json
|
|
|
|
|= jon=json
|
|
|
|
^- (quip card _state)
|
|
|
|
(poke-chat-action (json-to-action jon))
|
|
|
|
::
|
|
|
|
++ poke-chat-action
|
|
|
|
|= act=chat-action
|
|
|
|
^- (quip card _state)
|
|
|
|
?> ?=(%message -.act)
|
|
|
|
:: local
|
|
|
|
:_ state
|
|
|
|
?: (team:title our.bol src.bol)
|
|
|
|
?. (~(has by synced) path.act)
|
|
|
|
~
|
2020-02-10 18:34:37 +03:00
|
|
|
=* letter letter.envelope.act
|
|
|
|
=? letter &(?=(%code -.letter) ?=(~ output.letter))
|
|
|
|
=/ =hoon (ream expression.letter)
|
|
|
|
letter(output (eval bol hoon))
|
2019-11-23 01:05:06 +03:00
|
|
|
=/ ship (~(got by synced) path.act)
|
|
|
|
=/ appl ?:(=(ship our.bol) %chat-store %chat-hook)
|
|
|
|
[%pass / %agent [ship appl] %poke %chat-action !>(act)]~
|
|
|
|
:: foreign
|
|
|
|
=/ ship (~(get by synced) path.act)
|
2020-03-07 02:15:03 +03:00
|
|
|
?~ ship ~
|
|
|
|
?. =(u.ship our.bol) ~
|
2020-02-21 00:40:24 +03:00
|
|
|
:: check if write is permitted
|
2020-03-07 02:15:03 +03:00
|
|
|
?. (is-permitted src.bol path.act) ~
|
2019-11-23 01:05:06 +03:00
|
|
|
=: author.envelope.act src.bol
|
|
|
|
when.envelope.act now.bol
|
|
|
|
==
|
|
|
|
[%pass / %agent [our.bol %chat-store] %poke %chat-action !>(act)]~
|
|
|
|
::
|
|
|
|
++ poke-chat-hook-action
|
|
|
|
|= act=chat-hook-action
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.act
|
|
|
|
%add-owned
|
|
|
|
?> (team:title our.bol src.bol)
|
|
|
|
=/ chat-path [%mailbox path.act]
|
2020-03-12 08:21:56 +03:00
|
|
|
=/ chat-wire [%store path.act]
|
2020-03-07 02:15:03 +03:00
|
|
|
?: (~(has by synced) path.act) [~ state]
|
2019-11-23 01:05:06 +03:00
|
|
|
=: synced (~(put by synced) path.act our.bol)
|
|
|
|
allow-history (~(put by allow-history) path.act allow-history.act)
|
|
|
|
==
|
|
|
|
:_ state
|
2020-03-12 08:21:56 +03:00
|
|
|
:~ [%pass chat-wire %agent [our.bol %chat-store] %watch chat-path]
|
2020-03-12 02:38:46 +03:00
|
|
|
[%give %fact [/synced]~ %chat-hook-update !>([%initial synced])]
|
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
%add-synced
|
|
|
|
?> (team:title our.bol src.bol)
|
2020-02-05 02:16:20 +03:00
|
|
|
?: (~(has by synced) path.act) [~ state]
|
|
|
|
=. synced (~(put by synced) path.act ship.act)
|
2019-11-27 04:43:03 +03:00
|
|
|
?. ask-history.act
|
2020-02-05 02:16:20 +03:00
|
|
|
=/ chat-path [%mailbox path.act]
|
2019-11-27 04:43:03 +03:00
|
|
|
:_ state
|
|
|
|
[%pass chat-path %agent [ship.act %chat-hook] %watch chat-path]~
|
2020-03-11 22:12:51 +03:00
|
|
|
=/ mailbox=(unit mailbox) (chat-scry path.act)
|
|
|
|
=/ chat-history=path
|
|
|
|
:- %backlog
|
|
|
|
%+ weld path.act
|
|
|
|
?~(mailbox /0 /(scot %ud (lent envelopes.u.mailbox)))
|
2019-11-23 01:05:06 +03:00
|
|
|
:_ state
|
2020-03-12 02:38:46 +03:00
|
|
|
:~ [%pass chat-history %agent [ship.act %chat-hook] %watch chat-history]
|
|
|
|
[%give %fact [/synced]~ %chat-hook-update !>([%initial synced])]
|
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
%remove
|
2020-04-15 17:29:26 +03:00
|
|
|
=/ ship=(unit ship)
|
|
|
|
=/ ship (~(get by synced) path.act)
|
|
|
|
?^ ship ship
|
|
|
|
=? path.act ?=([%'~' *] path.act) t.path.act
|
|
|
|
?~ path.act ~
|
|
|
|
(slaw %p i.path.act)
|
|
|
|
?~ ship
|
|
|
|
~& [dap.bol %unknown-host-cannot-leave path.act]
|
|
|
|
[~ state]
|
2020-03-07 02:15:03 +03:00
|
|
|
?: &(!=(u.ship src.bol) ?!((team:title our.bol src.bol)))
|
2019-11-23 01:05:06 +03:00
|
|
|
[~ state]
|
2020-03-12 02:38:46 +03:00
|
|
|
=. synced (~(del by synced) path.act)
|
|
|
|
:_ state
|
2020-04-15 20:26:58 +03:00
|
|
|
:* [%give %kick ~[[%mailbox path.act]] ~]
|
|
|
|
[%give %fact [/synced]~ %chat-hook-update !>([%initial synced])]
|
2020-04-15 17:29:26 +03:00
|
|
|
(pull-wire u.ship [%mailbox path.act])
|
2020-04-15 20:26:58 +03:00
|
|
|
(pull-backlog-subscriptions u.ship path.act)
|
2020-03-07 02:15:03 +03:00
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
==
|
|
|
|
::
|
2020-03-12 02:28:34 +03:00
|
|
|
++ watch-synced
|
|
|
|
|= pax=path
|
|
|
|
^- (list card)
|
|
|
|
?> (team:title our.bol src.bol)
|
|
|
|
[%give %fact ~ %chat-hook-update !>([%initial synced])]~
|
|
|
|
::
|
2019-11-23 01:05:06 +03:00
|
|
|
++ watch-mailbox
|
2019-11-27 04:43:03 +03:00
|
|
|
|= pax=path
|
|
|
|
^- (list card)
|
|
|
|
?> ?=(^ pax)
|
|
|
|
?> (~(has by synced) pax)
|
2020-02-21 00:40:24 +03:00
|
|
|
:: check if read is permitted
|
|
|
|
?> (is-permitted src.bol pax)
|
2019-11-27 04:43:03 +03:00
|
|
|
=/ box (chat-scry pax)
|
|
|
|
?~ box !!
|
2020-02-04 22:12:51 +03:00
|
|
|
[%give %fact ~ %chat-update !>([%create pax])]~
|
2019-11-27 04:43:03 +03:00
|
|
|
::
|
|
|
|
++ watch-backlog
|
2019-11-23 01:05:06 +03:00
|
|
|
|= pax=path
|
|
|
|
^- (list card)
|
|
|
|
?> ?=(^ pax)
|
|
|
|
=/ last (dec (lent pax))
|
2020-04-03 09:33:09 +03:00
|
|
|
=/ backlog-latest=(unit @ud) (rush (snag last `(list @ta)`pax) dem:ag)
|
2019-11-27 04:43:03 +03:00
|
|
|
=/ pas `path`(oust [last 1] `(list @ta)`pax)
|
|
|
|
?> ?=([* ^] pas)
|
|
|
|
?> (~(has by synced) pas)
|
2020-02-21 00:40:24 +03:00
|
|
|
?> (is-permitted src.bol pas)
|
2020-04-03 09:33:09 +03:00
|
|
|
=/ envs envelopes:(need (chat-scry pas))
|
|
|
|
=/ length (lent envs)
|
|
|
|
=/ latest
|
|
|
|
?~ backlog-latest length
|
|
|
|
?: (gth u.backlog-latest length) length
|
|
|
|
(sub length u.backlog-latest)
|
|
|
|
=. envs (scag latest envs)
|
|
|
|
=/ =vase !>([%messages pas 0 latest envs])
|
2019-11-27 04:43:03 +03:00
|
|
|
%- zing
|
2020-02-05 02:16:20 +03:00
|
|
|
:~ [%give %fact ~ %chat-update !>([%create pas])]~
|
2020-04-03 09:33:09 +03:00
|
|
|
?. ?&(?=(^ backlog-latest) (~(has by allow-history) pas)) ~
|
|
|
|
[%give %fact ~ %chat-update vase]~
|
2020-02-05 02:16:20 +03:00
|
|
|
[%give %kick [%backlog pax]~ `src.bol]~
|
2019-11-27 04:43:03 +03:00
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ fact-invite-update
|
|
|
|
|= [wir=wire fact=invite-update]
|
|
|
|
^- (quip card _state)
|
2020-02-26 00:23:07 +03:00
|
|
|
:_ state
|
|
|
|
?+ -.fact ~
|
2019-11-23 01:05:06 +03:00
|
|
|
%accepted
|
2020-02-05 02:16:20 +03:00
|
|
|
=/ ask-history ?~((chat-scry path.invite.fact) %.y %.n)
|
2020-02-26 00:23:07 +03:00
|
|
|
=* shp ship.invite.fact
|
|
|
|
=* app-path path.invite.fact
|
|
|
|
~[(chat-view-poke [%join shp app-path ask-history])]
|
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ fact-permission-update
|
|
|
|
|= [wir=wire fact=permission-update]
|
|
|
|
^- (quip card _state)
|
2020-02-08 02:52:55 +03:00
|
|
|
|^
|
2019-11-23 01:05:06 +03:00
|
|
|
:_ state
|
2020-02-04 22:12:51 +03:00
|
|
|
?+ -.fact ~
|
2019-11-23 01:05:06 +03:00
|
|
|
%add (handle-permissions [%add path.fact who.fact])
|
|
|
|
%remove (handle-permissions [%remove path.fact who.fact])
|
|
|
|
==
|
2020-02-08 02:52:55 +03:00
|
|
|
::
|
|
|
|
++ handle-permissions
|
|
|
|
|= [kind=?(%add %remove) pax=path who=(set ship)]
|
|
|
|
^- (list card)
|
2020-02-21 00:40:24 +03:00
|
|
|
%- zing
|
|
|
|
%+ turn
|
|
|
|
(chats-of-group pax)
|
|
|
|
|= chat=path
|
|
|
|
^- (list card)
|
|
|
|
=/ owner (~(get by synced) chat)
|
2020-02-11 22:47:34 +03:00
|
|
|
?~ owner ~
|
|
|
|
?. =(u.owner our.bol) ~
|
2020-02-08 02:52:55 +03:00
|
|
|
%- zing
|
|
|
|
%+ turn ~(tap in who)
|
|
|
|
|= =ship
|
2020-02-21 00:40:24 +03:00
|
|
|
?: (is-permitted ship chat)
|
2020-03-10 02:41:31 +03:00
|
|
|
?: ?|(=(kind %remove) =(ship our.bol) (is-managed pax)) ~
|
2020-02-08 02:52:55 +03:00
|
|
|
:: if ship has just been added to the permitted group,
|
|
|
|
:: send them an invite
|
2020-02-21 00:40:24 +03:00
|
|
|
~[(send-invite chat ship)]
|
2020-02-08 02:52:55 +03:00
|
|
|
:: if ship is not permitted, kick their subscription
|
2020-02-21 00:40:24 +03:00
|
|
|
[%give %kick [%mailbox chat]~ `ship]~
|
2020-02-08 02:52:55 +03:00
|
|
|
::
|
|
|
|
++ send-invite
|
|
|
|
|= [=path =ship]
|
|
|
|
^- card
|
|
|
|
=/ =invite [our.bol %chat-hook path ship '']
|
|
|
|
=/ act=invite-action [%invite /chat (shaf %msg-uid eny.bol) invite]
|
|
|
|
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
|
2020-03-10 02:41:31 +03:00
|
|
|
::
|
|
|
|
++ is-managed
|
|
|
|
|= =path
|
|
|
|
^- ?
|
|
|
|
?> ?=(^ path)
|
|
|
|
!=(i.path '~')
|
2020-02-08 02:52:55 +03:00
|
|
|
--
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ fact-chat-update
|
|
|
|
|= [wir=wire fact=chat-update]
|
|
|
|
^- (quip card _state)
|
|
|
|
?: (team:title our.bol src.bol)
|
|
|
|
(handle-local fact)
|
|
|
|
(handle-foreign fact)
|
|
|
|
::
|
|
|
|
++ handle-local
|
|
|
|
|= fact=chat-update
|
|
|
|
^- (quip card _state)
|
2020-02-04 22:12:51 +03:00
|
|
|
?+ -.fact [~ state]
|
2019-11-23 01:05:06 +03:00
|
|
|
%delete
|
2020-03-07 02:15:03 +03:00
|
|
|
?. (~(has by synced) path.fact) [~ state]
|
2020-03-12 02:38:46 +03:00
|
|
|
=. synced (~(del by synced) path.fact)
|
|
|
|
:_ state
|
|
|
|
:~ [%pass [%mailbox path.fact] %agent [our.bol %chat-store] %leave ~]
|
|
|
|
[%give %fact [/synced]~ %chat-hook-update !>([%initial synced])]
|
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
%message
|
|
|
|
:_ state
|
2019-12-22 23:12:28 +03:00
|
|
|
[%give %fact [%mailbox path.fact]~ %chat-update !>(fact)]~
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
%messages
|
|
|
|
:_ state
|
2019-12-22 23:12:28 +03:00
|
|
|
[%give %fact [%mailbox path.fact]~ %chat-update !>(fact)]~
|
2019-11-23 01:05:06 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-foreign
|
|
|
|
|= fact=chat-update
|
|
|
|
^- (quip card _state)
|
2020-02-04 22:12:51 +03:00
|
|
|
?+ -.fact [~ state]
|
2019-11-23 01:05:06 +03:00
|
|
|
%create
|
|
|
|
:_ state
|
|
|
|
?> ?=([* ^] path.fact)
|
|
|
|
=/ shp (~(get by synced) path.fact)
|
|
|
|
?~ shp ~
|
|
|
|
?. =(src.bol u.shp) ~
|
2020-02-04 22:12:51 +03:00
|
|
|
[(chat-poke [%create path.fact])]~
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
%delete
|
|
|
|
?> ?=([* ^] path.fact)
|
|
|
|
=/ shp (~(get by synced) path.fact)
|
2020-03-07 02:15:03 +03:00
|
|
|
?~ shp [~ state]
|
|
|
|
?. =(u.shp src.bol) [~ state]
|
2020-03-12 02:38:46 +03:00
|
|
|
=. synced (~(del by synced) path.fact)
|
|
|
|
:_ state
|
2019-11-23 01:05:06 +03:00
|
|
|
:- (chat-poke [%delete path.fact])
|
2020-03-12 02:38:46 +03:00
|
|
|
:~ [%pass [%mailbox path.fact] %agent [src.bol %chat-hook] %leave ~]
|
|
|
|
[%give %fact [/synced]~ %chat-hook-update !>([%initial synced])]
|
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
%message
|
|
|
|
:_ state
|
|
|
|
?> ?=([* ^] path.fact)
|
|
|
|
=/ shp (~(get by synced) path.fact)
|
|
|
|
?~ shp ~
|
|
|
|
?. =(src.bol u.shp) ~
|
|
|
|
[(chat-poke [%message path.fact envelope.fact])]~
|
|
|
|
::
|
|
|
|
%messages
|
|
|
|
:_ state
|
|
|
|
?> ?=([* ^] path.fact)
|
|
|
|
=/ shp (~(get by synced) path.fact)
|
|
|
|
?~ shp ~
|
|
|
|
?. =(src.bol u.shp) ~
|
|
|
|
[(chat-poke [%messages path.fact envelopes.fact])]~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ kick
|
|
|
|
|= wir=wire
|
|
|
|
^- (quip card _state)
|
|
|
|
?: =(wir /permissions)
|
|
|
|
:_ state
|
|
|
|
[%pass /permissions %agent [our.bol %permission-store] %watch /updates]~
|
2019-12-01 08:24:23 +03:00
|
|
|
::
|
2020-02-06 22:28:58 +03:00
|
|
|
?+ wir !!
|
2020-03-12 08:21:56 +03:00
|
|
|
[%store @ *]
|
|
|
|
~& store-kick+wir
|
|
|
|
?. (~(has by synced) t.wir) [~ state]
|
|
|
|
~& %chat-store-resubscribe
|
|
|
|
=/ mailbox=(unit mailbox) (chat-scry t.wir)
|
|
|
|
:_ state
|
|
|
|
[%pass wir %agent [our.bol %chat-store] %watch [%mailbox t.wir]]~
|
|
|
|
::
|
2020-02-06 22:28:58 +03:00
|
|
|
[%mailbox @ *]
|
2019-11-27 04:43:03 +03:00
|
|
|
~& mailbox-kick+wir
|
2020-03-07 02:15:03 +03:00
|
|
|
?. (~(has by synced) t.wir) [~ state]
|
2019-11-27 04:43:03 +03:00
|
|
|
~& %chat-hook-resubscribe
|
2019-12-01 08:24:23 +03:00
|
|
|
=/ =ship (~(got by synced) t.wir)
|
2019-12-01 09:08:06 +03:00
|
|
|
=/ mailbox=(unit mailbox) (chat-scry t.wir)
|
|
|
|
=/ chat-history
|
|
|
|
%+ welp backlog+t.wir
|
2020-02-04 22:12:51 +03:00
|
|
|
?~(mailbox /0 /(scot %ud (lent envelopes.u.mailbox)))
|
2019-11-27 04:43:03 +03:00
|
|
|
:_ state
|
2019-12-01 08:24:23 +03:00
|
|
|
[%pass chat-history %agent [ship %chat-hook] %watch chat-history]~
|
|
|
|
::
|
2020-02-06 22:28:58 +03:00
|
|
|
[%backlog @ @ *]
|
2020-04-16 02:44:36 +03:00
|
|
|
=/ chat=path (oust [(dec (lent t.wir)) 1] `(list @ta)`t.wir)
|
|
|
|
?. (~(has by synced) chat) [~ state]
|
2020-02-06 22:28:58 +03:00
|
|
|
=/ =ship
|
|
|
|
?: =('~' i.t.wir)
|
|
|
|
(slav %p i.t.t.wir)
|
|
|
|
(slav %p i.t.wir)
|
2020-04-16 02:44:36 +03:00
|
|
|
=/ =path ?~((chat-scry chat) wir [%mailbox chat])
|
2020-02-06 22:28:58 +03:00
|
|
|
:_ state
|
2020-04-16 02:44:36 +03:00
|
|
|
[%pass path %agent [ship %chat-hook] %watch path]~
|
2020-02-06 22:28:58 +03:00
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ watch-ack
|
|
|
|
|= [wir=wire saw=(unit tang)]
|
|
|
|
^- (quip card _state)
|
2020-03-07 02:15:03 +03:00
|
|
|
?~ saw [~ state]
|
2020-03-12 02:28:34 +03:00
|
|
|
?+ wir [~ state]
|
2020-03-12 09:13:31 +03:00
|
|
|
[%store @ *]
|
2020-03-16 17:14:05 +03:00
|
|
|
(poke-chat-hook-action %remove t.wir)
|
2020-03-12 09:13:31 +03:00
|
|
|
::
|
2020-03-12 02:28:34 +03:00
|
|
|
[%backlog @ @ @ *]
|
2020-04-16 02:44:36 +03:00
|
|
|
=/ chat=path (oust [(dec (lent t.wir)) 1] `(list @ta)`t.wir)
|
|
|
|
%. (poke-chat-hook-action %remove chat)
|
2020-03-12 02:28:34 +03:00
|
|
|
%- slog
|
2020-04-16 02:44:36 +03:00
|
|
|
:* leaf+"chat-hook failed subscribe on {(spud chat)}"
|
2020-03-12 02:28:34 +03:00
|
|
|
leaf+"stack trace:"
|
|
|
|
u.saw
|
|
|
|
==
|
2019-11-23 01:05:06 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ chat-poke
|
|
|
|
|= act=chat-action
|
|
|
|
^- card
|
|
|
|
[%pass / %agent [our.bol %chat-store] %poke %chat-action !>(act)]
|
|
|
|
::
|
|
|
|
++ chat-view-poke
|
|
|
|
|= act=chat-view-action
|
|
|
|
^- card
|
|
|
|
[%pass / %agent [our.bol %chat-view] %poke %chat-view-action !>(act)]
|
|
|
|
::
|
|
|
|
++ invite-poke
|
|
|
|
|= act=invite-action
|
|
|
|
^- card
|
|
|
|
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(act)]
|
|
|
|
::
|
|
|
|
++ sec-to-perm
|
|
|
|
|= [pax=path =kind]
|
|
|
|
^- permission-action
|
|
|
|
[%create pax kind *(set ship)]
|
|
|
|
::
|
|
|
|
++ chat-scry
|
|
|
|
|= pax=path
|
|
|
|
^- (unit mailbox)
|
2020-02-21 00:28:56 +03:00
|
|
|
%^ scry (unit mailbox)
|
|
|
|
%chat-store
|
|
|
|
[%mailbox pax]
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
|
|
|
++ invite-scry
|
|
|
|
|= uid=serial
|
|
|
|
^- (unit invite)
|
2020-02-21 00:28:56 +03:00
|
|
|
%^ scry (unit invite)
|
|
|
|
%invite-store
|
|
|
|
/invite/chat/(scot %uv uid)
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
2020-02-21 00:40:24 +03:00
|
|
|
++ chats-of-group
|
|
|
|
|= =group-path
|
|
|
|
^- (list path)
|
2020-02-21 22:51:20 +03:00
|
|
|
:: if metadata-store isn't running yet, we're still in the upgrade ota phase.
|
|
|
|
:: we can't get chats from the metadata-store, but can make assumptions
|
|
|
|
:: about group path shape, and the chat that would match it.
|
|
|
|
::TODO remove me at some point.
|
|
|
|
::
|
2020-03-07 02:15:03 +03:00
|
|
|
?. .^(? %gu (scot %p our.bol) %metadata-store (scot %da now.bol) ~) ~
|
2020-02-21 00:40:24 +03:00
|
|
|
%+ murn
|
|
|
|
^- (list resource)
|
2020-02-25 18:55:49 +03:00
|
|
|
=; resources
|
|
|
|
%~ tap in
|
|
|
|
%+ ~(gut by resources)
|
|
|
|
group-path
|
|
|
|
*(set resource)
|
2020-02-21 00:40:24 +03:00
|
|
|
.^ (jug path resource)
|
|
|
|
%gy
|
|
|
|
(scot %p our.bol)
|
|
|
|
%metadata-store
|
|
|
|
(scot %da now.bol)
|
|
|
|
/group-indices
|
|
|
|
==
|
|
|
|
|= resource
|
|
|
|
^- (unit path)
|
|
|
|
?. =(%chat app-name) ~
|
|
|
|
`app-path
|
|
|
|
::
|
|
|
|
++ groups-of-chat
|
|
|
|
|= chat=path
|
|
|
|
^- (list group-path)
|
2020-02-21 22:51:20 +03:00
|
|
|
:: if metadata-store isn't running yet, we're still in the upgrade ota phase.
|
|
|
|
:: we can't get groups from the metadata-store, but can make assumptions
|
|
|
|
:: about chat path shape, and the chat that would match it.
|
|
|
|
::TODO remove me at some point.
|
|
|
|
::
|
2020-03-07 02:15:03 +03:00
|
|
|
?. .^(? %gu (scot %p our.bol) %metadata-store (scot %da now.bol) ~) ~
|
2020-02-25 18:55:49 +03:00
|
|
|
=; resources
|
|
|
|
%~ tap in
|
|
|
|
%+ ~(gut by resources)
|
|
|
|
[%chat chat]
|
|
|
|
*(set group-path)
|
2020-02-21 00:40:24 +03:00
|
|
|
.^ (jug resource group-path)
|
|
|
|
%gy
|
|
|
|
(scot %p our.bol)
|
|
|
|
%metadata-store
|
|
|
|
(scot %da now.bol)
|
|
|
|
/resource-indices
|
|
|
|
==
|
|
|
|
::
|
|
|
|
::NOTE this assumes permission paths match group paths
|
|
|
|
++ is-permitted
|
|
|
|
|= [who=ship chat=path]
|
2019-11-23 01:05:06 +03:00
|
|
|
^- ?
|
2020-02-21 00:40:24 +03:00
|
|
|
%+ lien (groups-of-chat chat)
|
|
|
|
|= =group-path
|
|
|
|
%^ scry ?
|
|
|
|
%permission-store
|
|
|
|
[%permitted (scot %p who) group-path]
|
2019-11-23 01:05:06 +03:00
|
|
|
::
|
2020-02-21 00:28:56 +03:00
|
|
|
++ scry
|
|
|
|
|* [=mold app=term =path]
|
|
|
|
.^ mold
|
|
|
|
%gx
|
|
|
|
(scot %p our.bol)
|
|
|
|
app
|
|
|
|
(scot %da now.bol)
|
|
|
|
(snoc `^path`path %noun)
|
|
|
|
==
|
|
|
|
::
|
2020-04-15 20:26:58 +03:00
|
|
|
++ pull-backlog-subscriptions
|
|
|
|
|= [target=ship chat=path]
|
|
|
|
^- (list card)
|
|
|
|
%+ murn ~(tap by wex.bol)
|
|
|
|
|= [[=wire =ship =term] [acked=? =path]]
|
|
|
|
^- (unit card)
|
|
|
|
?. ?& =(ship target)
|
|
|
|
?=([%backlog *] wire)
|
|
|
|
=(`1 (find chat wire))
|
|
|
|
==
|
|
|
|
~
|
|
|
|
`(pull-wire target wire)
|
|
|
|
::
|
2019-11-23 01:05:06 +03:00
|
|
|
++ pull-wire
|
2020-04-15 17:29:26 +03:00
|
|
|
|= [=ship =wire]
|
2020-04-15 20:26:58 +03:00
|
|
|
^- card
|
2020-04-15 17:29:26 +03:00
|
|
|
?: =(ship our.bol)
|
2020-04-15 20:26:58 +03:00
|
|
|
[%pass wire %agent [our.bol %chat-store] %leave ~]
|
|
|
|
[%pass wire %agent [ship %chat-hook] %leave ~]
|
2019-11-23 01:05:06 +03:00
|
|
|
--
|