mirror of
https://github.com/urbit/shrub.git
synced 2025-01-01 17:16:47 +03:00
Merge branch 'chat-history' (#1948)
* chat-history: chat: added temporary chat-two-update mark with new %messages type chat: oust correctness fix and js style fix chat-store: factored out functions used in both message and messages chat: style fixes chat: fixes to cli parser and increased page size in hook chat-js: updated to support %messages events sur: added rw-security to replace chat-security chat: add history functionality. optionally request backlog. Signed-off-by: Jared Tobin <jared@tlon.io>
This commit is contained in:
commit
053c784de6
@ -39,12 +39,14 @@
|
||||
[%say letter] :: send message
|
||||
[%eval cord hoon] :: send #-message
|
||||
::
|
||||
[%create chat-security path (unit glyph)] :: create chat
|
||||
::
|
||||
:: create chat
|
||||
[%create rw-security path (unit glyph) (unit ?)]
|
||||
[%delete path] :: delete chat
|
||||
[%invite ?(%r %w %rw) path (set ship)] :: allow
|
||||
[%banish ?(%r %w %rw) path (set ship)] :: disallow
|
||||
::
|
||||
[%join target (unit glyph)] :: join target
|
||||
[%join target (unit glyph) (unit ?)] :: join target
|
||||
[%leave target] :: nuke target
|
||||
::
|
||||
[%bind glyph target] :: bind glyph
|
||||
@ -178,6 +180,11 @@
|
||||
:- [prompt:sh-out ~]
|
||||
:: start with fresh sole state
|
||||
this(state.cli *sole-share:sole-sur)
|
||||
::
|
||||
++ diff-chat-two-update
|
||||
|= [=wire upd=chat-two-update]
|
||||
^- (quip move _this)
|
||||
(read-envelopes (path-to-target path.upd) envelopes.upd)
|
||||
:: +diff-chat-update: get new mailboxes & messages
|
||||
::
|
||||
++ diff-chat-update
|
||||
@ -364,13 +371,24 @@
|
||||
;~ (glue ace)
|
||||
(tag %create)
|
||||
security
|
||||
;~(plug path (punt ;~(pfix ace glyph)))
|
||||
;~ plug
|
||||
path
|
||||
(punt ;~(pfix ace glyph))
|
||||
(punt ;~(pfix ace (fuss 'y' 'n')))
|
||||
==
|
||||
==
|
||||
;~((glue ace) (tag %delete) path)
|
||||
;~((glue ace) (tag %invite) rw path ships)
|
||||
;~((glue ace) (tag %banish) rw path ships)
|
||||
::
|
||||
;~((glue ace) (tag %join) ;~(plug targ (punt ;~(pfix ace glyph))))
|
||||
;~ (glue ace)
|
||||
(tag %join)
|
||||
;~ plug
|
||||
targ
|
||||
(punt ;~(pfix ace glyph))
|
||||
(punt ;~(pfix ace (fuss 'y' 'n')))
|
||||
==
|
||||
==
|
||||
;~((glue ace) (tag %leave) targ)
|
||||
::
|
||||
;~((glue ace) (tag %bind) glyph targ)
|
||||
@ -625,7 +643,7 @@
|
||||
:: +create: new local mailbox
|
||||
::
|
||||
++ create
|
||||
|= [security=chat-security =path gyf=(unit char)]
|
||||
|= [security=rw-security =path gyf=(unit char) allow-history=(unit ?)]
|
||||
^- (quip move _this)
|
||||
::TODO check if already exists
|
||||
=/ =target [our-self path]
|
||||
@ -636,18 +654,22 @@
|
||||
=- [[- moz] this]
|
||||
%^ act %do-create %chat-view
|
||||
:- %chat-view-action
|
||||
:^ %create path security
|
||||
:: ensure we can read from/write to our own chats
|
||||
::
|
||||
:- :: read
|
||||
:* %create
|
||||
path
|
||||
security
|
||||
:: ensure we can read from/write to our own chats
|
||||
::
|
||||
:: read
|
||||
?- security
|
||||
?(%channel %journal) ~
|
||||
?(%village %mailbox) [our-self ~ ~]
|
||||
==
|
||||
:: write
|
||||
?- security
|
||||
?(%channel %mailbox) ~
|
||||
?(%village %journal) [our-self ~ ~]
|
||||
:: write
|
||||
?- security
|
||||
?(%channel %mailbox) ~
|
||||
?(%village %journal) [our-self ~ ~]
|
||||
==
|
||||
(fall allow-history %.y)
|
||||
==
|
||||
:: +delete: delete local chats
|
||||
::
|
||||
@ -708,7 +730,7 @@
|
||||
:: +join: sync with remote mailbox
|
||||
::
|
||||
++ join
|
||||
|= [=target gyf=(unit char)]
|
||||
|= [=target gyf=(unit char) ask-history=(unit ?)]
|
||||
^- (quip move _this)
|
||||
=^ moz this
|
||||
?. ?=(^ gyf) [~ this]
|
||||
@ -720,7 +742,7 @@
|
||||
:: gives ugly %chat-hook-reap
|
||||
%^ act %do-join %chat-view
|
||||
:- %chat-view-action
|
||||
[%join target]
|
||||
[%join ship.target path.target (fall ask-history %.y)]
|
||||
:: +leave: unsync & destroy mailbox
|
||||
::
|
||||
::TODO allow us to "mute" local chats using this
|
||||
|
@ -8,16 +8,17 @@
|
||||
+$ move [bone card]
|
||||
::
|
||||
+$ card
|
||||
$% [%diff [%chat-update chat-update]]
|
||||
$% [%diff diff]
|
||||
[%quit ~]
|
||||
[%poke wire dock poke]
|
||||
[%pull wire dock ~]
|
||||
[%peer wire dock path]
|
||||
==
|
||||
::
|
||||
+$ state-both
|
||||
+$ versioned-state
|
||||
$% state-zero
|
||||
state-one
|
||||
state-two
|
||||
==
|
||||
::
|
||||
+$ state-zero
|
||||
@ -33,6 +34,14 @@
|
||||
invite-created=_|
|
||||
==
|
||||
::
|
||||
+$ state-two
|
||||
$: %2
|
||||
synced=(map path ship)
|
||||
boned=(map wire (list bone))
|
||||
invite-created=_|
|
||||
allow-history=(map path ?)
|
||||
==
|
||||
::
|
||||
+$ poke
|
||||
$% [%chat-action chat-action]
|
||||
[%permission-action permission-action]
|
||||
@ -40,15 +49,19 @@
|
||||
[%chat-view-action chat-view-action]
|
||||
==
|
||||
::
|
||||
+$ diff
|
||||
$% [%chat-update chat-update]
|
||||
[%chat-two-update chat-two-update]
|
||||
==
|
||||
--
|
||||
::
|
||||
|_ [bol=bowl:gall state-one]
|
||||
|_ [bol=bowl:gall state-two]
|
||||
::
|
||||
++ this .
|
||||
::
|
||||
++ prep
|
||||
|= old=(unit state-both)
|
||||
^- (quip move _this)
|
||||
|= old=(unit versioned-state)
|
||||
|^ ^- (quip move _this)
|
||||
?~ old
|
||||
:_ this(invite-created %.y)
|
||||
:~ (invite-poke [%create /chat])
|
||||
@ -56,19 +69,32 @@
|
||||
[ost.bol %peer /permissions [our.bol %permission-store] /updates]
|
||||
==
|
||||
?- -.u.old
|
||||
%1 [~ this(+<+ u.old)]
|
||||
%2 [~ this(+<+ u.old)]
|
||||
%1 [~ (migrate-state synced.u.old boned.u.old)]
|
||||
::
|
||||
%0
|
||||
=/ sta *state-one
|
||||
=: boned.sta boned.u.old
|
||||
synced.sta synced.u.old
|
||||
invite-created %.y
|
||||
==
|
||||
:_ this(+<+ sta)
|
||||
:_ (migrate-state synced.u.old boned.u.old)
|
||||
:~ (invite-poke [%create /chat])
|
||||
[ost.bol %peer /invites [our.bol %invite-store] /invitatory/chat]
|
||||
==
|
||||
==
|
||||
::
|
||||
++ migrate-state
|
||||
|= [synced=(map path ship) boned=(map wire (list bone))]
|
||||
^- _this
|
||||
=/ sta *state-two
|
||||
=: boned.sta boned
|
||||
synced.sta synced
|
||||
allow-history.sta (create-allow-history synced)
|
||||
invite-created %.y
|
||||
==
|
||||
this(+<+ sta)
|
||||
::
|
||||
++ create-allow-history
|
||||
|= synced=(map path ship)
|
||||
^- (map path ?)
|
||||
(~(run by synced) |=(* %.n))
|
||||
--
|
||||
::
|
||||
++ poke-json
|
||||
|= jon=json
|
||||
@ -110,7 +136,9 @@
|
||||
=/ chat-path [%mailbox path.act]
|
||||
?: (~(has by synced) path.act)
|
||||
[~ this]
|
||||
=. synced (~(put by synced) path.act our.bol)
|
||||
=: synced (~(put by synced) path.act our.bol)
|
||||
allow-history (~(put by allow-history) path.act allow-history.act)
|
||||
==
|
||||
:_ (track-bone chat-path)
|
||||
%+ weld
|
||||
[ost.bol %peer chat-path [our.bol %chat-store] chat-path]~
|
||||
@ -118,12 +146,13 @@
|
||||
::
|
||||
%add-synced
|
||||
?> (team:title our.bol src.bol)
|
||||
=/ chat-path [%mailbox (scot %p ship.act) path.act]
|
||||
=/ chat-path=path [%mailbox (scot %p ship.act) path.act]
|
||||
?: (~(has by synced) [(scot %p ship.act) path.act])
|
||||
[~ this]
|
||||
=. synced (~(put by synced) [(scot %p ship.act) path.act] ship.act)
|
||||
=/ history=path ?:(ask-history.act /0 /~)
|
||||
:_ (track-bone chat-path)
|
||||
[ost.bol %peer chat-path [ship.act %chat-hook] chat-path]~
|
||||
[ost.bol %peer chat-path [ship.act %chat-hook] (weld chat-path history)]~
|
||||
::
|
||||
%remove
|
||||
=/ ship (~(get by synced) path.act)
|
||||
@ -157,6 +186,13 @@
|
||||
++ peer-mailbox
|
||||
|= pax=path
|
||||
^- (quip move _this)
|
||||
?> ?=(^ pax)
|
||||
=/ last (dec (lent pax))
|
||||
=/ backlog-start=(unit @ud)
|
||||
%+ rush
|
||||
(snag last `(list @ta)`pax)
|
||||
dem:ag
|
||||
=> .(pax `path`(oust [last 1] `(list @ta)`pax))
|
||||
?> ?=([* ^] pax)
|
||||
?> (~(has by synced) pax)
|
||||
:: scry permissions to check if read is permitted
|
||||
@ -164,7 +200,43 @@
|
||||
=/ box (chat-scry pax)
|
||||
?~ box !!
|
||||
:_ this
|
||||
[ost.bol %diff %chat-update [%create (slav %p i.pax) pax]]~
|
||||
:- [ost.bol %diff %chat-update [%create (slav %p i.pax) pax]]
|
||||
?: ?&(?=(^ backlog-start) (~(got by allow-history) pax))
|
||||
(paginate-messages pax u.box u.backlog-start)
|
||||
~
|
||||
::
|
||||
++ paginate-messages
|
||||
|= [=path =mailbox start=@ud]
|
||||
^- (list move)
|
||||
=/ moves=(list move) ~
|
||||
=/ end (lent envelopes.mailbox)
|
||||
?: |((gte start end) =(end 0))
|
||||
moves
|
||||
=. envelopes.mailbox (slag start `(list envelope)`envelopes.mailbox)
|
||||
|- ^- (list move)
|
||||
?~ envelopes.mailbox
|
||||
moves
|
||||
?: (lte end 5.000)
|
||||
=. moves
|
||||
%+ snoc moves
|
||||
%- messages-move
|
||||
[path start (lent envelopes.mailbox) envelopes.mailbox]
|
||||
$(envelopes.mailbox ~)
|
||||
=. moves
|
||||
%+ snoc moves
|
||||
%- messages-move
|
||||
:^ path start
|
||||
(add start 5.000)
|
||||
(scag 5.000 `(list envelope)`envelopes.mailbox)
|
||||
=: start (add start 5.000)
|
||||
end (sub end 5.000)
|
||||
==
|
||||
$(envelopes.mailbox (slag 5.000 `(list envelope)`envelopes.mailbox))
|
||||
::
|
||||
++ messages-move
|
||||
|= [=path start=@ud end=@ud envelopes=(list envelope)]
|
||||
^- move
|
||||
[ost.bol %diff %chat-two-update [%messages path start end envelopes]]
|
||||
::
|
||||
++ diff-invite-update
|
||||
|= [wir=wire diff=invite-update]
|
||||
@ -173,8 +245,12 @@
|
||||
[~ this]
|
||||
::
|
||||
%accepted
|
||||
=/ ask-history
|
||||
?~ (chat-scry [(scot %p ship.invite.diff) path.invite.diff])
|
||||
%.y
|
||||
%.n
|
||||
:_ this
|
||||
[(chat-view-poke [%join ship.invite.diff path.invite.diff])]~
|
||||
[(chat-view-poke [%join ship.invite.diff path.invite.diff ask-history])]~
|
||||
==
|
||||
::
|
||||
++ diff-permission-update
|
||||
@ -211,6 +287,24 @@
|
||||
=/ bne (~(get by sup) [check-ship [%mailbox mail-path]])
|
||||
?~(bne ~ [u.bne %quit ~]~)
|
||||
::
|
||||
++ diff-chat-two-update
|
||||
|= [wir=wire diff=chat-two-update]
|
||||
^- (quip move _this)
|
||||
:: local
|
||||
?: (team:title our.bol src.bol)
|
||||
:_ this
|
||||
%+ turn (prey:pubsub:userlib [%mailbox path.diff] bol)
|
||||
|= [=bone *]
|
||||
^- move
|
||||
[bone %diff [%chat-two-update diff]]
|
||||
:: foreign
|
||||
:_ this
|
||||
?> ?=([* ^] path.diff)
|
||||
=/ shp (~(get by synced) path.diff)
|
||||
?~ shp ~
|
||||
?. =(src.bol u.shp) ~
|
||||
[(chat-poke [%messages path.diff envelopes.diff])]~
|
||||
::
|
||||
++ diff-chat-update
|
||||
|= [wir=wire diff=chat-update]
|
||||
^- (quip move _this)
|
||||
@ -222,10 +316,10 @@
|
||||
|= diff=chat-update
|
||||
^- (quip move _this)
|
||||
?- -.diff
|
||||
%keys [~ this]
|
||||
%config [~ this]
|
||||
%create [~ this]
|
||||
%read [~ this]
|
||||
%keys [~ this]
|
||||
%config [~ this]
|
||||
%create [~ this]
|
||||
%read [~ this]
|
||||
%delete
|
||||
?. (~(has by synced) path.diff)
|
||||
[~ this]
|
||||
@ -263,7 +357,7 @@
|
||||
?. =(u.shp src.bol)
|
||||
[~ this]
|
||||
:_ this(synced (~(del by synced) path.diff))
|
||||
:- (chat-poke diff)
|
||||
:- (chat-poke [%delete path.diff])
|
||||
[ost.bol %pull [%mailbox path.diff] [src.bol %chat-hook] ~]~
|
||||
::
|
||||
%message
|
||||
@ -272,7 +366,7 @@
|
||||
=/ shp (~(get by synced) path.diff)
|
||||
?~ shp ~
|
||||
?. =(src.bol u.shp) ~
|
||||
[(chat-poke diff)]~
|
||||
[(chat-poke [%message path.diff envelope.diff])]~
|
||||
==
|
||||
::
|
||||
++ quit
|
||||
@ -286,9 +380,13 @@
|
||||
?. (~(has by synced) t.wir)
|
||||
:: no-op
|
||||
[~ this]
|
||||
=/ mailbox (chat-scry t.wir)
|
||||
?~ mailbox [~ this]
|
||||
~& %chat-hook-resubscribe
|
||||
=/ pax=path (weld wir /(scot %ud (lent envelopes.u.mailbox)))
|
||||
~& pax
|
||||
:_ (track-bone wir)
|
||||
[ost.bol %peer wir [(slav %p i.t.wir) %chat-hook] wir]~
|
||||
[ost.bol %peer wir [(slav %p i.t.wir) %chat-hook] pax]~
|
||||
::
|
||||
++ reap
|
||||
|= [wir=wire saw=(unit tang)]
|
||||
@ -325,7 +423,7 @@
|
||||
[ost.bol %poke / [our.bol %invite-store] [%invite-action act]]
|
||||
::
|
||||
++ create-permission
|
||||
|= [pax=path sec=chat-security]
|
||||
|= [pax=path sec=rw-security]
|
||||
^- (list move)
|
||||
=/ read-perm (weld pax /read)
|
||||
=/ write-perm (weld pax /write)
|
||||
|
@ -21,6 +21,7 @@
|
||||
$% [%chat-initial inbox]
|
||||
[%chat-configs chat-configs]
|
||||
[%chat-update chat-update]
|
||||
[%chat-two-update chat-two-update]
|
||||
==
|
||||
--
|
||||
::
|
||||
@ -154,10 +155,11 @@
|
||||
^- (quip move _this)
|
||||
?> (team:title our.bol src.bol)
|
||||
?- -.action
|
||||
%create (handle-create action)
|
||||
%delete (handle-delete action)
|
||||
%message (handle-message action)
|
||||
%read (handle-read action)
|
||||
%create (handle-create action)
|
||||
%delete (handle-delete action)
|
||||
%message (handle-message action)
|
||||
%messages (handle-messages action)
|
||||
%read (handle-read action)
|
||||
==
|
||||
::
|
||||
++ handle-create
|
||||
@ -187,17 +189,34 @@
|
||||
=/ mailbox=(unit mailbox) (~(get by inbox) path.act)
|
||||
?~ mailbox
|
||||
[~ this]
|
||||
=* 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)
|
||||
==
|
||||
=. letter.envelope.act (evaluate-letter letter.envelope.act)
|
||||
=. u.mailbox (append-envelope u.mailbox envelope.act)
|
||||
:- (send-diff path.act act)
|
||||
this(inbox (~(put by inbox) path.act u.mailbox))
|
||||
::
|
||||
++ handle-messages
|
||||
|= act=chat-action
|
||||
^- (quip move _this)
|
||||
?> ?=(%messages -.act)
|
||||
=/ mailbox=(unit mailbox) (~(get by inbox) path.act)
|
||||
?~ mailbox
|
||||
[~ this]
|
||||
=/ evaluated-envelopes=(list envelope) ~
|
||||
|- ^- (quip move _this)
|
||||
?~ envelopes.act
|
||||
:_ this(inbox (~(put by inbox) path.act u.mailbox))
|
||||
%+ send-two-diff path.act
|
||||
:* %messages
|
||||
path.act
|
||||
(sub length.config.u.mailbox (lent evaluated-envelopes))
|
||||
length.config.u.mailbox
|
||||
evaluated-envelopes
|
||||
==
|
||||
=. letter.i.envelopes.act (evaluate-letter letter.i.envelopes.act)
|
||||
=. evaluated-envelopes (snoc evaluated-envelopes i.envelopes.act)
|
||||
=. u.mailbox (append-envelope u.mailbox i.envelopes.act)
|
||||
$(envelopes.act t.envelopes.act)
|
||||
::
|
||||
++ handle-read
|
||||
|= act=chat-action
|
||||
^- (quip move _this)
|
||||
@ -209,26 +228,58 @@
|
||||
:- (send-diff path.act act)
|
||||
this(inbox (~(put by inbox) path.act u.mailbox))
|
||||
::
|
||||
++ evaluate-letter
|
||||
|= =letter
|
||||
^- ^letter
|
||||
=? letter &(?=(%code -.letter) ?=(~ output.letter))
|
||||
=/ =hoon (ream expression.letter)
|
||||
letter(output (eval bol hoon))
|
||||
letter
|
||||
::
|
||||
++ append-envelope
|
||||
|= [=mailbox =envelope]
|
||||
^- ^mailbox
|
||||
=. number.envelope +(length.config.mailbox)
|
||||
=: length.config.mailbox +(length.config.mailbox)
|
||||
envelopes.mailbox (snoc envelopes.mailbox envelope)
|
||||
==
|
||||
mailbox
|
||||
::
|
||||
++ update-subscribers
|
||||
|= [pax=path act=chat-action]
|
||||
|= [pax=path upd=chat-update]
|
||||
^- (list move)
|
||||
%+ turn (prey:pubsub:userlib pax bol)
|
||||
|= [=bone *]
|
||||
[bone %diff %chat-update act]
|
||||
[bone %diff %chat-update upd]
|
||||
::
|
||||
++ send-diff
|
||||
|= [pax=path act=chat-action]
|
||||
|= [pax=path upd=chat-update]
|
||||
^- (list move)
|
||||
%- zing
|
||||
:~ (update-subscribers /all act)
|
||||
(update-subscribers /updates act)
|
||||
(update-subscribers [%mailbox pax] act)
|
||||
?. |(=(%read -.act) =(%message -.act))
|
||||
:~ (update-subscribers /all upd)
|
||||
(update-subscribers /updates upd)
|
||||
(update-subscribers [%mailbox pax] upd)
|
||||
?. |(|(=(%read -.upd) =(%message -.upd)) =(%messages -.upd))
|
||||
~
|
||||
(update-subscribers /configs act)
|
||||
?. |(=(%create -.act) =(%delete -.act))
|
||||
(update-subscribers /configs upd)
|
||||
?. |(=(%create -.upd) =(%delete -.upd))
|
||||
~
|
||||
(update-subscribers /keys act)
|
||||
(update-subscribers /keys upd)
|
||||
==
|
||||
::
|
||||
++ send-two-diff
|
||||
|= [pax=path upd=chat-two-update]
|
||||
^- (list move)
|
||||
%- zing
|
||||
:~ (update-two-subscribers /all upd)
|
||||
(update-two-subscribers /updates upd)
|
||||
(update-two-subscribers [%mailbox pax] upd)
|
||||
==
|
||||
::
|
||||
++ update-two-subscribers
|
||||
|= [pax=path upd=chat-two-update]
|
||||
^- (list move)
|
||||
%+ turn (prey:pubsub:userlib pax bol)
|
||||
|= [=bone *]
|
||||
[bone %diff %chat-two-update upd]
|
||||
--
|
||||
|
@ -129,9 +129,8 @@
|
||||
%http-response
|
||||
%- json-response:app
|
||||
%- json-to-octs
|
||||
%+ envelopes-update
|
||||
envelopes
|
||||
[start end pax]
|
||||
%- two-update-to-json
|
||||
[%messages pax start end envelopes]
|
||||
==
|
||||
::
|
||||
:: inbox page
|
||||
@ -155,7 +154,6 @@
|
||||
[~ this]
|
||||
?- -.act
|
||||
%create
|
||||
:: TODO: add invites
|
||||
=/ pax [(scot %p our.bol) path.act]
|
||||
=/ group-read=path [%chat (weld pax /read)]
|
||||
=/ group-write=path [%chat (weld pax /write)]
|
||||
@ -166,7 +164,7 @@
|
||||
(group-poke [%add read.act group-read])
|
||||
(group-poke [%add write.act group-write])
|
||||
(chat-poke [%create our.bol path.act])
|
||||
(chat-hook-poke [%add-owned pax security.act])
|
||||
(chat-hook-poke [%add-owned pax security.act allow-history.act])
|
||||
==
|
||||
(create-security [%chat pax] security.act)
|
||||
:~ (permission-hook-poke [%add-owned group-read group-read])
|
||||
@ -190,7 +188,7 @@
|
||||
=/ group-read [%chat (scot %p ship.act) (weld path.act /read)]
|
||||
=/ group-write [%chat (scot %p ship.act) (weld path.act /write)]
|
||||
:_ this
|
||||
:~ (chat-hook-poke [%add-synced ship.act path.act])
|
||||
:~ (chat-hook-poke [%add-synced ship.act path.act ask-history.act])
|
||||
(permission-hook-poke [%add-synced ship.act group-write])
|
||||
(permission-hook-poke [%add-synced ship.act group-read])
|
||||
==
|
||||
@ -227,6 +225,21 @@
|
||||
|= [=bone *]
|
||||
[bone %diff %json configs-json]
|
||||
::
|
||||
++ diff-chat-two-update
|
||||
|= [wir=wire upd=chat-two-update]
|
||||
^- (quip move _this)
|
||||
=/ updates-json (two-update-to-json upd)
|
||||
=/ configs-json (configs-to-json configs-scry)
|
||||
:_ this
|
||||
%+ weld
|
||||
%+ turn (prey:pubsub:userlib /primary bol)
|
||||
|= [=bone *]
|
||||
[bone %diff %json updates-json]
|
||||
%+ turn (prey:pubsub:userlib /configs bol)
|
||||
|= [=bone *]
|
||||
[bone %diff %json configs-json]
|
||||
|
||||
::
|
||||
++ quit
|
||||
|= wir=wire
|
||||
^- (quip move _this)
|
||||
@ -281,7 +294,7 @@
|
||||
.^(chat-configs %gx /=chat-store/(scot %da now.bol)/configs/noun)
|
||||
::
|
||||
++ create-security
|
||||
|= [pax=path sec=chat-security]
|
||||
|= [pax=path sec=rw-security]
|
||||
^- (list move)
|
||||
=/ read (weld pax /read)
|
||||
=/ write (weld pax /write)
|
||||
@ -308,22 +321,6 @@
|
||||
::
|
||||
==
|
||||
::
|
||||
++ envelopes-update
|
||||
|= [envelopes=(list envelope) start=@ud end=@ud pax=path]
|
||||
^- json
|
||||
=, enjs:format
|
||||
%+ frond %chat-update
|
||||
%- pairs
|
||||
:~
|
||||
:- %messages
|
||||
%- pairs
|
||||
:~ [%path (path pax)]
|
||||
[%start (numb start)]
|
||||
[%end (numb end)]
|
||||
[%envelopes [%a (turn envelopes enve)]]
|
||||
==
|
||||
==
|
||||
::
|
||||
++ truncate-envelopes
|
||||
|= envelopes=(list envelope)
|
||||
^- (list envelope)
|
||||
@ -340,5 +337,4 @@
|
||||
^- mailbox
|
||||
:- config.mail
|
||||
(truncate-envelopes envelopes.mail)
|
||||
::
|
||||
--
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -118,6 +118,25 @@
|
||||
[%config (conf config.mailbox)]
|
||||
==
|
||||
::
|
||||
++ two-update-to-json
|
||||
|= upd=chat-two-update
|
||||
=, enjs:format
|
||||
^- json
|
||||
%+ frond %chat-update
|
||||
%- pairs
|
||||
:~
|
||||
?: =(%messages -.upd)
|
||||
?> ?=(%messages -.upd)
|
||||
:- %messages
|
||||
%- pairs
|
||||
:~ [%path (path path.upd)]
|
||||
[%start (numb start.upd)]
|
||||
[%end (numb end.upd)]
|
||||
[%envelopes [%a (turn envelopes.upd enve)]]
|
||||
==
|
||||
[*@t *^json]
|
||||
==
|
||||
::
|
||||
++ update-to-json
|
||||
|= upd=chat-update
|
||||
=, enjs:format
|
||||
@ -166,6 +185,7 @@
|
||||
:~ [%create create]
|
||||
[%delete delete]
|
||||
[%message message]
|
||||
[%messages messages]
|
||||
[%read read]
|
||||
==
|
||||
::
|
||||
@ -184,6 +204,12 @@
|
||||
[%envelope envelope]
|
||||
==
|
||||
::
|
||||
++ messages
|
||||
%- ot
|
||||
:~ [%path pa]
|
||||
[%envelopes (ar envelope)]
|
||||
==
|
||||
::
|
||||
++ read
|
||||
(ot [%path pa] ~)
|
||||
::
|
||||
@ -225,6 +251,7 @@
|
||||
[%security sec]
|
||||
[%read (as (su ;~(pfix sig fed:ag)))]
|
||||
[%write (as (su ;~(pfix sig fed:ag)))]
|
||||
[%allow-history bo]
|
||||
==
|
||||
::
|
||||
++ delete
|
||||
@ -234,11 +261,12 @@
|
||||
%- ot
|
||||
:~ [%ship (su ;~(pfix sig fed:ag))]
|
||||
[%path pa]
|
||||
[%ask-history bo]
|
||||
==
|
||||
::
|
||||
++ sec
|
||||
=, dejs:format
|
||||
^- $-(json chat-security)
|
||||
^- $-(json rw-security)
|
||||
(su (perk %channel %village %journal %mailbox ~))
|
||||
--
|
||||
--
|
||||
|
@ -20,16 +20,18 @@
|
||||
%- ot
|
||||
:~ [%path pa]
|
||||
[%security sec]
|
||||
[%allow-history bo]
|
||||
==
|
||||
::
|
||||
++ add-synced
|
||||
%- ot
|
||||
:~ [%ship (su ;~(pfix sig fed:ag))]
|
||||
[%path pa]
|
||||
[%ask-history bo]
|
||||
==
|
||||
::
|
||||
++ sec
|
||||
^- $-(^json chat-security)
|
||||
^- $-(^json rw-security)
|
||||
(su (perk %channel %village %journal %mailbox ~))
|
||||
::
|
||||
--
|
||||
|
13
pkg/arvo/mar/chat/two-update.hoon
Normal file
13
pkg/arvo/mar/chat/two-update.hoon
Normal file
@ -0,0 +1,13 @@
|
||||
/+ *chat-json
|
||||
|_ upd=chat-two-update
|
||||
++ grow
|
||||
|%
|
||||
++ json (two-update-to-json upd)
|
||||
--
|
||||
::
|
||||
++ grab
|
||||
|%
|
||||
++ noun chat-two-update
|
||||
--
|
||||
::
|
||||
--
|
@ -1,23 +1,16 @@
|
||||
/- *rw-security
|
||||
|%
|
||||
+$ chat-security
|
||||
$? $channel :: black r, black w
|
||||
$village :: white r, white w
|
||||
$journal :: black r, white w
|
||||
$mailbox :: white r, black w
|
||||
==
|
||||
::
|
||||
+$ chat-hook-action
|
||||
$% :: %add-owned: make a chatroom accessible to foreign ships
|
||||
:: specified by the chat-security model
|
||||
:: specified by the rw-security model
|
||||
::
|
||||
[%add-owned =path security=chat-security]
|
||||
[%add-owned =path security=rw-security allow-history=?]
|
||||
:: %add-synced: mirror a foreign chatroom to our chat-store
|
||||
::
|
||||
[%add-synced =ship =path]
|
||||
[%add-synced =ship =path ask-history=?]
|
||||
:: %remove: stop mirroring a foreign chatroom or allowing a local
|
||||
:: chatroom to be mirrored
|
||||
::
|
||||
[%remove =path]
|
||||
==
|
||||
--
|
||||
|
||||
|
@ -30,16 +30,26 @@
|
||||
::
|
||||
+$ chat-configs (map path config)
|
||||
::
|
||||
+$ chat-action
|
||||
+$ chat-base
|
||||
$% [%create =ship =path] :: %create: create a mailbox at ~ship/path
|
||||
[%delete =path] :: %delete: delete a mailbox at path
|
||||
[%message =path =envelope] :: %message: append a message to mailbox
|
||||
[%read =path] :: %read: set mailbox to read
|
||||
==
|
||||
::
|
||||
+$ chat-action
|
||||
$% :: %messages: append a list of messages to mailbox
|
||||
::
|
||||
[%messages =path envelopes=(list envelope)]
|
||||
chat-base
|
||||
==
|
||||
::
|
||||
+$ chat-update
|
||||
$% [%keys keys=(set path)]
|
||||
[%config =path =config]
|
||||
chat-action
|
||||
chat-base
|
||||
==
|
||||
::
|
||||
+$ chat-two-update
|
||||
[%messages =path start=@ud end=@ud envelopes=(list envelope)]
|
||||
--
|
||||
|
@ -1,14 +1,14 @@
|
||||
/- *rw-security
|
||||
|%
|
||||
+$ chat-security
|
||||
$? $channel :: black r, black w
|
||||
$village :: white r, white w
|
||||
$journal :: black r, white w
|
||||
$mailbox :: white r, black w
|
||||
==
|
||||
::
|
||||
+$ chat-view-action
|
||||
$% [%create =path security=chat-security read=(set ship) write=(set ship)]
|
||||
$% $: %create
|
||||
=path
|
||||
security=rw-security
|
||||
read=(set ship)
|
||||
write=(set ship)
|
||||
allow-history=?
|
||||
==
|
||||
[%delete =path]
|
||||
[%join =ship =path]
|
||||
[%join =ship =path ask-history=?]
|
||||
==
|
||||
--
|
||||
|
8
pkg/arvo/sur/rw-security.hoon
Normal file
8
pkg/arvo/sur/rw-security.hoon
Normal file
@ -0,0 +1,8 @@
|
||||
|%
|
||||
+$ rw-security
|
||||
$? $channel :: black r, black w
|
||||
$village :: white r, white w
|
||||
$journal :: black r, white w
|
||||
$mailbox :: white r, black w
|
||||
==
|
||||
--
|
@ -14,6 +14,10 @@ textarea, input, button {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
input[type=checkbox] {
|
||||
-webkit-appearance: checkbox;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000 !important;
|
||||
font-weight: 400 !important;
|
||||
|
@ -128,10 +128,11 @@ class UrbitApi {
|
||||
this.action("chat-view", "json", data);
|
||||
}
|
||||
|
||||
chatViewCreate(path, security, read, write) {
|
||||
chatViewCreate(path, security, read, write, allowHistory) {
|
||||
this.chatViewAction({
|
||||
create: {
|
||||
path, security, read, write
|
||||
path, security, read, write,
|
||||
'allow-history': allowHistory
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -140,8 +141,13 @@ class UrbitApi {
|
||||
this.chatViewAction({ delete: { path } });
|
||||
}
|
||||
|
||||
chatViewJoin(ship, path) {
|
||||
this.chatViewAction({ join: { ship, path } });
|
||||
chatViewJoin(ship, path, askHistory) {
|
||||
this.chatViewAction({
|
||||
join: {
|
||||
ship, path,
|
||||
'ask-history': askHistory
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
inviteAction(data) {
|
||||
|
@ -67,7 +67,7 @@ export class ChatScreen extends Component {
|
||||
|
||||
updateReadNumber() {
|
||||
const { props, state } = this;
|
||||
if (props.read < props.envelopes.length) {
|
||||
if (props.read < props.length) {
|
||||
props.api.chat.read(state.station);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ export class JoinScreen extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
props.api.chatView.join(ship, station);
|
||||
// TODO: askHistory setting
|
||||
props.api.chatView.join(ship, station, true);
|
||||
this.props.history.push('/~chat');
|
||||
}
|
||||
|
||||
|
@ -26,19 +26,21 @@ export class ChatInput extends Component {
|
||||
|
||||
// perf testing:
|
||||
/*let closure = () => {
|
||||
let x = 0;
|
||||
for (var i = 0; i < 30; i++) {
|
||||
x++;
|
||||
props.api.chat.message(
|
||||
props.station,
|
||||
`~${window.ship}`,
|
||||
Date.now(),
|
||||
{
|
||||
text: `${Date.now()}`
|
||||
text: `${x}`
|
||||
}
|
||||
);
|
||||
}
|
||||
setTimeout(closure, 1000);
|
||||
};
|
||||
setTimeout(closure, 2000);*/
|
||||
this.closure = closure.bind(this);*/
|
||||
|
||||
moment.updateLocale('en', {
|
||||
relativeTime : {
|
||||
@ -144,6 +146,7 @@ export class ChatInput extends Component {
|
||||
Date.now(),
|
||||
letter
|
||||
);
|
||||
// perf: setTimeout(this.closure, 2000);
|
||||
|
||||
this.setState({
|
||||
message: '',
|
||||
|
@ -14,12 +14,14 @@ export class NewScreen extends Component {
|
||||
invites: '',
|
||||
security: 'village',
|
||||
idError: false,
|
||||
inviteError: false
|
||||
inviteError: false,
|
||||
allowHistory: true
|
||||
};
|
||||
|
||||
this.idChange = this.idChange.bind(this);
|
||||
this.invChange = this.invChange.bind(this);
|
||||
this.securityChange = this.securityChange.bind(this);
|
||||
this.allowHistoryChange = this.allowHistoryChange.bind(this);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
@ -47,6 +49,10 @@ export class NewScreen extends Component {
|
||||
this.setState({security: event.target.value});
|
||||
}
|
||||
|
||||
allowHistoryChange(event) {
|
||||
this.setState({allowHistory: !!event.target.checked});
|
||||
}
|
||||
|
||||
onClickCreate() {
|
||||
const { props, state } = this;
|
||||
if (!state.idName) {
|
||||
@ -114,14 +120,15 @@ export class NewScreen extends Component {
|
||||
readAud = aud.slice(); // white list
|
||||
writeAud = []; // black list
|
||||
}
|
||||
|
||||
this.setState({
|
||||
error: false,
|
||||
success: true,
|
||||
invites: ''
|
||||
}, () => {
|
||||
props.setSpinner(true);
|
||||
props.api.chatView.create(station, state.security, readAud, writeAud);
|
||||
props.api.chatView.create(
|
||||
station, state.security, readAud, writeAud, state.allowHistory
|
||||
);
|
||||
aud.forEach((ship) => {
|
||||
if (ship !== `~${window.ship}`) {
|
||||
props.api.invite.invite(station, ship);
|
||||
@ -194,6 +201,18 @@ export class NewScreen extends Component {
|
||||
<option value="journal">Journal</option>
|
||||
<option value="mailbox">Mailbox</option>
|
||||
</select>
|
||||
<p className="body-medium mt3 db">Chat History</p>
|
||||
<div className="db mt2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={this.state.allowHistory}
|
||||
onChange={this.allowHistoryChange.bind(this)}
|
||||
className="dib mr2"
|
||||
/>
|
||||
<p className="body-small db mt2 mb3 dib">
|
||||
Allow participants to download the chat history upon joining.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={this.onClickCreate.bind(this)}
|
||||
className={createClasses}
|
||||
|
@ -44,7 +44,8 @@ export class Root extends Component {
|
||||
messagePreviews[stat] = envelopes[envelopes.length - 1];
|
||||
}
|
||||
|
||||
unreads[stat] = envelopes.length > state.inbox[stat].config.read;
|
||||
unreads[stat] =
|
||||
state.inbox[stat].config.length > state.inbox[stat].config.read;
|
||||
});
|
||||
|
||||
let invites = '/chat' in state.invites ?
|
||||
@ -113,7 +114,7 @@ export class Root extends Component {
|
||||
`/${props.match.params.ship}/${props.match.params.station}`;
|
||||
let mailbox = state.inbox[station] || {
|
||||
config: {
|
||||
read: -1,
|
||||
read: 0,
|
||||
length: 0
|
||||
},
|
||||
envelopes: []
|
||||
@ -127,6 +128,7 @@ export class Root extends Component {
|
||||
api={api}
|
||||
subscription={subscription}
|
||||
read={mailbox.config.read}
|
||||
length={mailbox.config.length}
|
||||
envelopes={mailbox.envelopes}
|
||||
inbox={state.inbox}
|
||||
group={write}
|
||||
|
@ -18,15 +18,18 @@ export class ChatUpdateReducer {
|
||||
let data = _.get(json, 'message', false);
|
||||
if (data) {
|
||||
state.inbox[data.path].envelopes.push(data.envelope);
|
||||
state.inbox[data.path].config.length
|
||||
= state.inbox[data.path].config.length + 1;
|
||||
}
|
||||
}
|
||||
|
||||
messages(json, state) {
|
||||
let data = _.get(json, 'messages', false);
|
||||
if (data) {
|
||||
console.log(data);
|
||||
state.inbox[data.path].envelopes =
|
||||
data.envelopes.concat(state.inbox[data.path].envelopes);
|
||||
state.inbox[data.path].config.length =
|
||||
state.inbox[data.path].config.length + data.envelopes.length;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +37,7 @@ export class ChatUpdateReducer {
|
||||
let data = _.get(json, 'read', false);
|
||||
if (data) {
|
||||
state.inbox[data.path].config.read =
|
||||
state.inbox[data.path].envelopes.length;
|
||||
state.inbox[data.path].config.length;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,8 +47,8 @@ export class ChatUpdateReducer {
|
||||
state.inbox[`/~${data.ship}${data.path}`] = {
|
||||
envelopes: [],
|
||||
config: {
|
||||
read:0,
|
||||
length: 0,
|
||||
read: 0,
|
||||
length: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user