mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
Merge branch 'release/next-js' into release/next-userspace
This commit is contained in:
commit
391a3101d9
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f6b5e33e573818120051651c1182163527edbbe0dff0eb6591e12a55cfccb273
|
||||
size 10486101
|
||||
oid sha256:2773b91958c18c7537cb568e01bcf83056447bfef981c5ed4b6688cc3ab69936
|
||||
size 10739521
|
||||
|
@ -82,6 +82,8 @@ haskell-nix.stackProject {
|
||||
|
||||
urbit-king.components.tests.urbit-king-tests.testFlags =
|
||||
[ "--brass-pill=${brass.lfs}" ];
|
||||
|
||||
lmdb.components.library.libs = lib.mkForce [ lmdb ];
|
||||
};
|
||||
}];
|
||||
}
|
||||
|
@ -169,7 +169,7 @@
|
||||
::
|
||||
%fact
|
||||
?+ p.cage.sign ~|([dap.bowl %bad-sub-mark wire p.cage.sign] !!)
|
||||
%graph-update-1
|
||||
%graph-update-2
|
||||
%- on-graph-update:tc
|
||||
!<(update:graph q.cage.sign)
|
||||
==
|
||||
@ -401,12 +401,16 @@
|
||||
:: +read-post: add envelope to state and show it to user
|
||||
::
|
||||
++ read-post
|
||||
|= [=target =index:post =post:post]
|
||||
|= [=target =index:post =maybe-post:graph]
|
||||
^- (quip card _session)
|
||||
:- (show-post:sh-out target post)
|
||||
%_ session
|
||||
history [[target index] history.session]
|
||||
count +(count.session)
|
||||
?- -.maybe-post
|
||||
%| [~ session]
|
||||
%&
|
||||
:- (show-post:sh-out target p.maybe-post)
|
||||
%_ session
|
||||
history [[target index] history.session]
|
||||
count +(count.session)
|
||||
==
|
||||
==
|
||||
::
|
||||
++ notice-remove
|
||||
@ -759,15 +763,15 @@
|
||||
::TODO move creation into lib?
|
||||
%^ act %out-message
|
||||
%graph-push-hook
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
!> ^- update:graph
|
||||
:- now.bowl
|
||||
:+ %add-nodes audience
|
||||
%- ~(put by *(map index:post node:graph))
|
||||
:- ~[now.bowl]
|
||||
:_ *internal-graph:graph
|
||||
^- post:post
|
||||
[our-self ~[now.bowl] now.bowl [msg]~ ~ ~]
|
||||
^- maybe-post:graph
|
||||
[%& `post:post`[our-self ~[now.bowl] now.bowl [msg]~ ~ ~]]
|
||||
:: +eval: run hoon, send code and result as message
|
||||
::
|
||||
:: this double-virtualizes and clams to disable .^ for security reasons
|
||||
@ -891,10 +895,12 @@
|
||||
=/ =uid:post (snag index history)
|
||||
=/ =node:graph (got-node:libgraph uid)
|
||||
=. audience resource.uid
|
||||
?: ?=(%| -.post.node)
|
||||
[~ state]
|
||||
:_ put-ses
|
||||
^- (list card)
|
||||
:~ (print:sh-out ['?' ' ' number])
|
||||
(effect:sh-out ~(render-activate mr resource.uid post.node))
|
||||
(effect:sh-out ~(render-activate mr resource.uid p.post.node))
|
||||
prompt:sh-out
|
||||
==
|
||||
--
|
||||
|
@ -154,7 +154,7 @@
|
||||
++ poke-graph-store
|
||||
|= =update:graph-store
|
||||
^- card
|
||||
(poke-our %graph-store %graph-update-1 !>(update))
|
||||
(poke-our %graph-store %graph-update-2 !>(update))
|
||||
::
|
||||
++ nobody
|
||||
^- @p
|
||||
|
@ -1,334 +1,28 @@
|
||||
:: chat-store [landscape]:
|
||||
:: chat-store [landscape]: deprecated
|
||||
::
|
||||
:: data store that holds linear sequences of chat messages
|
||||
::
|
||||
/- *group, store=chat-store
|
||||
/+ default-agent, verb, dbug, group-store,
|
||||
graph-store, resource, *migrate, grpl=group, mdl=metadata
|
||||
~% %chat-store-top ..part ~
|
||||
/- store=chat-store
|
||||
/+ default-agent
|
||||
|%
|
||||
+$ card card:agent:gall
|
||||
+$ versioned-state
|
||||
$% state-0
|
||||
state-1
|
||||
state-2
|
||||
state-3
|
||||
state-4
|
||||
==
|
||||
::
|
||||
+$ state-0 [%0 =inbox:store]
|
||||
+$ state-1 [%1 =inbox:store]
|
||||
+$ state-2 [%2 =inbox:store]
|
||||
+$ state-3 [%3 =inbox:store]
|
||||
+$ state-4 [%4 =inbox:store]
|
||||
+$ admin-action
|
||||
$% [%trim ~]
|
||||
[%migrate-graph ~]
|
||||
==
|
||||
--
|
||||
::
|
||||
=| state-4
|
||||
=* state -
|
||||
::
|
||||
%- agent:dbug
|
||||
%+ verb |
|
||||
^- agent:gall
|
||||
=<
|
||||
~% %chat-store-agent-core ..peek-x-envelopes ~
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
chat-core +>
|
||||
cc ~(. chat-core bowl)
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old-vase=vase
|
||||
^- (quip card _this)
|
||||
|^
|
||||
=/ old !<(versioned-state old-vase)
|
||||
=| cards=(list card)
|
||||
|-
|
||||
^- (quip card _this)
|
||||
?- -.old
|
||||
%4 [cards this(state old)]
|
||||
::
|
||||
%3
|
||||
=. cards :_(cards (poke-admin %migrate-graph ~))
|
||||
$(old [%4 inbox.old])
|
||||
::
|
||||
%2
|
||||
=/ =inbox:store
|
||||
(migrate-path-map:group-store inbox.old)
|
||||
=/ kick-paths
|
||||
%~ tap in
|
||||
%+ roll
|
||||
~(val by sup.bowl)
|
||||
|= [[=ship sub=path] subs=(set path)]
|
||||
^- (set path)
|
||||
?. ?=([@ @ *] sub)
|
||||
subs
|
||||
?. &(=(%mailbox i.sub) =('~' i.t.sub))
|
||||
subs
|
||||
(~(put in subs) sub)
|
||||
=? cards ?=(^ kick-paths)
|
||||
:_ cards
|
||||
[%give %kick kick-paths ~]
|
||||
$(old [%3 inbox])
|
||||
::
|
||||
?(%0 %1) $(old (old-to-2 inbox.old))
|
||||
::
|
||||
==
|
||||
++ poke-admin
|
||||
|= =admin-action
|
||||
^- card
|
||||
[%pass / %agent [our dap]:bowl %poke noun+!>(admin-action)]
|
||||
::
|
||||
++ old-to-2
|
||||
|= =inbox:store
|
||||
^- state-2
|
||||
:- %2
|
||||
%- ~(run by inbox)
|
||||
|= =mailbox:store
|
||||
^- mailbox:store
|
||||
[config.mailbox (flop envelopes.mailbox)]
|
||||
--
|
||||
::
|
||||
++ on-poke
|
||||
~/ %chat-store-poke
|
||||
|= [=mark =vase]
|
||||
^- (quip card _this)
|
||||
?> (team:title our.bowl src.bowl)
|
||||
=^ cards state
|
||||
?+ mark (on-poke:def mark vase)
|
||||
%noun (poke-noun:cc !<(admin-action vase))
|
||||
%import (poke-import:cc q.vase)
|
||||
==
|
||||
[cards this]
|
||||
::
|
||||
++ on-watch on-watch:def
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek
|
||||
~/ %chat-store-peek
|
||||
|= =path
|
||||
^- (unit (unit cage))
|
||||
?+ path (on-peek:def path)
|
||||
[%x %all ~] ``noun+!>(inbox)
|
||||
[%x %keys ~] ``noun+!>(~(key by inbox))
|
||||
[%x %envelopes *] (peek-x-envelopes:cc t.t.path)
|
||||
[%x %mailbox *]
|
||||
?~ t.t.path
|
||||
~
|
||||
``noun+!>((~(get by inbox) t.t.path))
|
||||
::
|
||||
[%x %config *]
|
||||
?~ t.t.path
|
||||
~
|
||||
=/ mailbox (~(get by inbox) t.t.path)
|
||||
?~ mailbox
|
||||
~
|
||||
``noun+!>(config.u.mailbox)
|
||||
::
|
||||
[%x %export ~]
|
||||
``noun+!>(state)
|
||||
==
|
||||
::
|
||||
++ on-agent on-agent:def
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
~% %chat-store-library ..card ~
|
||||
|_ bol=bowl:gall
|
||||
++ met ~(. mdl bol)
|
||||
++ grp ~(. grpl bol)
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(~)
|
||||
++ on-load
|
||||
|= old-vase=vase
|
||||
^- (quip card _this)
|
||||
[~ this]
|
||||
::
|
||||
++ 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-noun
|
||||
|= nou=admin-action
|
||||
^- (quip card _state)
|
||||
?: ?=([%migrate-graph ~] nou)
|
||||
:_ state
|
||||
(migrate-inbox inbox)
|
||||
~& %trimming-chat-store
|
||||
:- ~
|
||||
%_ state
|
||||
inbox
|
||||
%- ~(urn by inbox)
|
||||
|= [=path mailbox:store]
|
||||
^- mailbox:store
|
||||
=/ [a=* out=(list envelope:store)]
|
||||
%+ roll envelopes
|
||||
|= $: =envelope:store
|
||||
o=[[hav=(set serial:store) curr=@] out=(list envelope:store)]
|
||||
==
|
||||
?: (~(has in hav.o) uid.envelope)
|
||||
[[hav.o curr.o] out.o]
|
||||
:-
|
||||
^- [(set serial:store) @]
|
||||
[(~(put in hav.o) uid.envelope) +(curr.o)]
|
||||
^- (list envelope:store)
|
||||
[envelope(number curr.o) out.o]
|
||||
=/ len (lent out)
|
||||
~? !=(len (lent envelopes)) [path [%old (lent envelopes)] [%new len]]
|
||||
[[len len] (flop out)]
|
||||
==
|
||||
::
|
||||
++ poke-import
|
||||
|= arc=*
|
||||
^- (quip card _state)
|
||||
=/ sty=state-4 [%4 (remake-map ;;((tree [path mailbox:store]) +.arc))]
|
||||
:_ sty
|
||||
(migrate-inbox inbox.sty)
|
||||
::
|
||||
++ update-subscribers
|
||||
|= [pax=path =update:store]
|
||||
^- (list card)
|
||||
[%give %fact ~[pax] %chat-update !>(update)]~
|
||||
::
|
||||
++ send-diff
|
||||
|= [pax=path upd=update:store]
|
||||
^- (list card)
|
||||
%- zing
|
||||
:~ (update-subscribers /all upd)
|
||||
(update-subscribers /updates upd)
|
||||
(update-subscribers [%mailbox pax] upd)
|
||||
?. |(|(=(%read -.upd) =(%message -.upd)) =(%messages -.upd))
|
||||
~
|
||||
?. |(=(%create -.upd) =(%delete -.upd))
|
||||
~
|
||||
(update-subscribers /keys upd)
|
||||
==
|
||||
::
|
||||
++ migrate-inbox
|
||||
|= =inbox:store
|
||||
^- (list card)
|
||||
%- zing
|
||||
(turn ~(tap by inbox) mailbox-to-updates)
|
||||
::
|
||||
++ add-graph
|
||||
|= [rid=resource =mailbox:store]
|
||||
%- poke-graph-store
|
||||
:- now.bol
|
||||
:+ %add-graph rid
|
||||
:- (mailbox-to-graph mailbox)
|
||||
[`%graph-validator-chat %.y]
|
||||
::
|
||||
++ archive-graph
|
||||
|= rid=resource
|
||||
%- poke-graph-store
|
||||
[now.bol %archive-graph rid]
|
||||
::
|
||||
++ nobody
|
||||
^- @p
|
||||
(bex 128)
|
||||
::
|
||||
++ path-to-resource
|
||||
|= =path
|
||||
^- resource
|
||||
?. ?=([@ @ ~] path)
|
||||
nobody^(spat path)
|
||||
=/ m-ship=(unit ship)
|
||||
(slaw %p i.path)
|
||||
?~ m-ship
|
||||
nobody^(spat path)
|
||||
[u.m-ship i.t.path]
|
||||
::
|
||||
++ mailbox-to-updates
|
||||
|= [=path =mailbox:store]
|
||||
^- (list card)
|
||||
=/ app-rid=resource
|
||||
(path-to-resource path)
|
||||
=/ group-rid=resource
|
||||
(fall (peek-group:met %graph app-rid) [nobody %bad-group])
|
||||
=/ group=(unit group)
|
||||
(scry-group:grp group-rid)
|
||||
:- (add-graph app-rid mailbox)
|
||||
?~ group (archive-graph app-rid)^~
|
||||
?. &(=(~ members.u.group) hidden.u.group) ~
|
||||
~& >>> "archiving {<app-rid>}"
|
||||
:~ (archive-graph app-rid)
|
||||
(remove-group group-rid)
|
||||
==
|
||||
::
|
||||
++ remove-group
|
||||
|= group=resource
|
||||
^- card
|
||||
=- [%pass / %agent [our.bol %group-store] %poke -]
|
||||
group-update-0+!>([%remove-group group ~])
|
||||
::
|
||||
++ poke-graph-store
|
||||
|= =update:graph-store
|
||||
^- card
|
||||
[%pass / %agent [our.bol %graph-store] %poke %graph-update-1 !>(update)]
|
||||
::
|
||||
++ letter-to-contents
|
||||
|= =letter:store
|
||||
^- (list content:graph-store)
|
||||
:_ ~
|
||||
?. ?=(%me -.letter)
|
||||
letter
|
||||
[%text narrative.letter]
|
||||
::
|
||||
++ envelope-to-node
|
||||
|= =envelope:store
|
||||
^- [atom:graph-store node:graph-store]
|
||||
=/ contents=(list content:graph-store)
|
||||
(letter-to-contents letter.envelope)
|
||||
=/ =index:graph-store
|
||||
[when.envelope ~]
|
||||
=, envelope
|
||||
:- when.envelope
|
||||
:_ [%empty ~]
|
||||
^- post:graph-store
|
||||
:* author
|
||||
index
|
||||
when
|
||||
contents
|
||||
~ ~
|
||||
==
|
||||
::
|
||||
++ mailbox-to-graph
|
||||
|= =mailbox:store
|
||||
^- graph:graph-store
|
||||
%+ gas:orm:graph-store *graph:graph-store
|
||||
(turn envelopes.mailbox envelope-to-node)
|
||||
++ on-poke on-poke:def
|
||||
++ on-watch on-watch:def
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek on-peek:def
|
||||
++ on-agent on-agent:def
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
|
@ -5,7 +5,7 @@
|
||||
/- glob
|
||||
/+ default-agent, verb, dbug
|
||||
|%
|
||||
++ hash 0v3.g6u13.haedt.jt4hd.61ek5.6t30q
|
||||
++ hash 0v2.9br5i.hl1e5.cda79.75gdi.jj5hc :: DO NOT MOVE FROM LINE 8
|
||||
+$ state-0 [%0 hash=@uv glob=(unit (each glob:glob tid=@ta))]
|
||||
+$ all-states
|
||||
$% state-0
|
||||
|
@ -9,7 +9,7 @@
|
||||
update:store
|
||||
%graph-update
|
||||
%graph-push-hook
|
||||
1 1
|
||||
2 2
|
||||
%.n
|
||||
==
|
||||
--
|
||||
@ -41,7 +41,7 @@
|
||||
%- (slog leaf+"nacked {<resource>}" tang)
|
||||
:_ this
|
||||
?. (~(has in get-keys:gra) resource) ~
|
||||
=- [%pass /pull-nack %agent [our.bowl %graph-store] %poke %graph-update-1 -]~
|
||||
=- [%pass /pull-nack %agent [our.bowl %graph-store] %poke %graph-update-2 -]~
|
||||
!> ^- update:store
|
||||
[now.bowl [%archive-graph resource]]
|
||||
::
|
||||
|
@ -12,16 +12,19 @@
|
||||
update:store
|
||||
%graph-update
|
||||
%graph-pull-hook
|
||||
1 1
|
||||
2 2
|
||||
==
|
||||
::
|
||||
+$ agent (push-hook:push-hook config)
|
||||
::
|
||||
+$ state-null ~
|
||||
+$ state-zero [%0 marks=(set mark)]
|
||||
+$ state-one [%1 ~]
|
||||
+$ versioned-state
|
||||
$@ state-null
|
||||
state-zero
|
||||
$% state-zero
|
||||
state-one
|
||||
==
|
||||
--
|
||||
::
|
||||
%- agent:dbug
|
||||
@ -30,13 +33,14 @@
|
||||
%- (agent:push-hook config)
|
||||
^- agent
|
||||
=-
|
||||
=| state-zero
|
||||
=| state-one
|
||||
=* state -
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
grp ~(. group bowl)
|
||||
gra ~(. graph bowl)
|
||||
met ~(. mdl bowl)
|
||||
hc ~(. hook-core bowl)
|
||||
::
|
||||
++ on-init on-init:def
|
||||
@ -46,7 +50,9 @@
|
||||
=+ !<(old=versioned-state vase)
|
||||
=? old ?=(~ old)
|
||||
[%0 ~]
|
||||
?> ?=(%0 -.old)
|
||||
=? old ?=(%0 -.old)
|
||||
[%1 ~]
|
||||
?> ?=(%1 -.old)
|
||||
`this(state old)
|
||||
::
|
||||
++ on-poke on-poke:def
|
||||
@ -58,17 +64,10 @@
|
||||
|= [=wire =sign-arvo]
|
||||
^- (quip card _this)
|
||||
?+ wire (on-arvo:def wire sign-arvo)
|
||||
:: XX: no longer necessary
|
||||
::
|
||||
[%perms @ @ ~]
|
||||
?> ?=(?(%add %remove) i.t.t.wire)
|
||||
=* mark i.t.wire
|
||||
:_ this
|
||||
(build-permissions:hc mark i.t.t.wire %next)^~
|
||||
::
|
||||
[%transform-add @ ~]
|
||||
=* mark i.t.wire
|
||||
:_ this
|
||||
(build-transform-add:hc mark %next)^~
|
||||
[%perms @ @ ~] [~ this]
|
||||
[%transform-add @ ~] [~ this]
|
||||
==
|
||||
::
|
||||
++ on-fail on-fail:def
|
||||
@ -134,6 +133,8 @@
|
||||
|= $: [=index:store =node:store]
|
||||
[indices=(set index:store) lis=(list [index:store node:store])]
|
||||
==
|
||||
~| "cannot put a deleted post into %add-nodes {<post.node>}"
|
||||
?> ?=(%& -.post.node)
|
||||
=/ l (lent index)
|
||||
=/ parent-modified=?
|
||||
%- ~(rep in indices)
|
||||
@ -144,12 +145,12 @@
|
||||
%.n
|
||||
=((swag [0 k] index) i)
|
||||
=/ [ind=index:store =post:store]
|
||||
(transform index post.node now.bowl parent-modified)
|
||||
(transform index p.post.node now.bowl parent-modified)
|
||||
:- (~(put in indices) index)
|
||||
(snoc lis [ind node(post post)])
|
||||
(snoc lis [ind node(p.post post)])
|
||||
--
|
||||
::
|
||||
%remove-nodes
|
||||
%remove-posts
|
||||
?. (is-allowed-remove:hc resource.q.update indices.q.update)
|
||||
~
|
||||
`vas
|
||||
@ -173,7 +174,8 @@
|
||||
++ initial-watch
|
||||
|= [=path =resource:res]
|
||||
^- vase
|
||||
?> (is-allowed:hc resource)
|
||||
|^
|
||||
?> (is-allowed resource)
|
||||
!> ^- update:store
|
||||
?~ path
|
||||
:: new subscribe
|
||||
@ -186,22 +188,19 @@
|
||||
=/ =time (slav %da i.path)
|
||||
=/ =update-log:store (get-update-log-subset:gra resource time)
|
||||
[now.bowl [%run-updates resource update-log]]
|
||||
::
|
||||
++ is-allowed
|
||||
|= =resource:res
|
||||
=/ group-res=resource:res
|
||||
(need (peek-group:met %graph resource))
|
||||
(is-member:grp src.bowl group-res)
|
||||
--
|
||||
::
|
||||
++ take-update
|
||||
|= =vase
|
||||
^- [(list card) agent]
|
||||
=/ =update:store !<(update:store vase)
|
||||
?+ -.q.update [~ this]
|
||||
%add-graph
|
||||
?~ mark.q.update `this
|
||||
=* mark u.mark.q.update
|
||||
?: (~(has in marks) mark) `this
|
||||
:_ this(marks (~(put in marks) mark))
|
||||
:~ (build-permissions:hc mark %add %sing)
|
||||
(build-permissions:hc mark %remove %sing)
|
||||
(build-transform-add:hc mark %sing)
|
||||
==
|
||||
::
|
||||
%remove-graph
|
||||
:_ this
|
||||
[%give %kick ~[resource+(en-path:res resource.q.update)] ~]~
|
||||
@ -211,6 +210,7 @@
|
||||
[%give %kick ~[resource+(en-path:res resource.q.update)] ~]~
|
||||
==
|
||||
--
|
||||
::
|
||||
^| ^= hook-core
|
||||
|_ =bowl:gall
|
||||
+* grp ~(. group bowl)
|
||||
@ -223,28 +223,22 @@
|
||||
/[care]/(scot %p our.bowl)/[desk]/(scot %da now.bowl)
|
||||
path
|
||||
::
|
||||
++ perm-mark-name
|
||||
|= perm=@t
|
||||
^- @t
|
||||
(cat 3 'graph-permissions-' perm)
|
||||
::
|
||||
++ perm-mark
|
||||
|= [=resource:res perm=@t vip=vip-metadata:metadata =indexed-post:store]
|
||||
^- permissions:store
|
||||
|^
|
||||
=- (check vip)
|
||||
!< check=$-(vip-metadata:metadata permissions:store)
|
||||
%. !>(indexed-post)
|
||||
=/ mark (get-mark:gra resource)
|
||||
?~ mark |=(=vase !>([%no %no %no]))
|
||||
.^(tube:clay (scry %cc %home /[u.mark]/(perm-mark-name perm)))
|
||||
::
|
||||
++ add-mark
|
||||
|= [=resource:res vip=vip-metadata:metadata =indexed-post:store]
|
||||
(perm-mark resource %add vip indexed-post)
|
||||
::
|
||||
++ remove-mark
|
||||
|= [=resource:res vip=vip-metadata:metadata =indexed-post:store]
|
||||
(perm-mark resource %remove vip indexed-post)
|
||||
::
|
||||
++ perm-mark-name
|
||||
|= perm=@t
|
||||
^- @t
|
||||
(cat 3 'graph-permissions-' perm)
|
||||
--
|
||||
::
|
||||
++ get-permission
|
||||
|= [=permissions:store is-admin=? writers=(set ship)]
|
||||
@ -257,12 +251,6 @@
|
||||
writer.permissions
|
||||
reader.permissions
|
||||
::
|
||||
++ is-allowed
|
||||
|= =resource:res
|
||||
=/ group-res=resource:res
|
||||
(need (peek-group:met %graph resource))
|
||||
(is-member:grp src.bowl group-res)
|
||||
::
|
||||
++ get-roles-writers-variation
|
||||
|= =resource:res
|
||||
^- (unit [is-admin=? writers=(set ship) vip=vip-metadata:metadata])
|
||||
@ -281,22 +269,27 @@
|
||||
++ node-to-indexed-post
|
||||
|= =node:store
|
||||
^- indexed-post:store
|
||||
=* index index.post.node
|
||||
[(snag (dec (lent index)) index) post.node]
|
||||
?> ?=(%& -.post.node)
|
||||
=* index index.p.post.node
|
||||
[(snag (dec (lent index)) index) p.post.node]
|
||||
::
|
||||
++ is-allowed-add
|
||||
|= [=resource:res nodes=(map index:store node:store)]
|
||||
^- ?
|
||||
|^
|
||||
%- (bond |.(%.n))
|
||||
%+ biff (get-roles-writers-variation resource)
|
||||
|= [is-admin=? writers=(set ship) vip=vip-metadata:metadata]
|
||||
^- (unit ?)
|
||||
%- some
|
||||
%+ levy ~(tap by nodes)
|
||||
|= [=index:store =node:store]
|
||||
=/ parent-index=index:store
|
||||
(scag (dec (lent index)) index)
|
||||
?: (~(has by nodes) parent-index) %.y
|
||||
?. =(author.post.node src.bowl)
|
||||
?: ?=(%| -.post.node)
|
||||
%.n
|
||||
?. =(author.p.post.node src.bowl)
|
||||
%.n
|
||||
=/ =permissions:store
|
||||
%^ add-mark resource vip
|
||||
@ -310,20 +303,30 @@
|
||||
%self
|
||||
=/ parent-node=node:store
|
||||
(got-node:gra resource parent-index)
|
||||
=(author.post.parent-node src.bowl)
|
||||
?: ?=(%| -.post.parent-node)
|
||||
%.n
|
||||
=(author.p.post.parent-node src.bowl)
|
||||
==
|
||||
::
|
||||
++ add-mark
|
||||
|= [=resource:res vip=vip-metadata:metadata =indexed-post:store]
|
||||
(perm-mark resource %add vip indexed-post)
|
||||
--
|
||||
::
|
||||
++ is-allowed-remove
|
||||
|= [=resource:res indices=(set index:store)]
|
||||
^- ?
|
||||
|^
|
||||
%- (bond |.(%.n))
|
||||
%+ biff (get-roles-writers-variation resource)
|
||||
|= [is-admin=? writers=(set ship) vip=vip-metadata:metadata]
|
||||
%- some
|
||||
%+ levy ~(tap by indices)
|
||||
|= =index:store
|
||||
^- ?
|
||||
=/ =node:store
|
||||
(got-node:gra resource index)
|
||||
?: ?=(%| -.post.node) %.n
|
||||
=/ =permissions:store
|
||||
%^ remove-mark resource vip
|
||||
(node-to-indexed-post node)
|
||||
@ -332,23 +335,12 @@
|
||||
?- permission-level
|
||||
%yes %.y
|
||||
%no %.n
|
||||
%self =(author.post.node src.bowl)
|
||||
%self =(author.p.post.node src.bowl)
|
||||
==
|
||||
::
|
||||
++ build-permissions
|
||||
|= [=mark kind=?(%add %remove) mode=?(%sing %next)]
|
||||
^- card
|
||||
=/ =wire /perms/[mark]/[kind]
|
||||
=/ =mood:clay [%c da+now.bowl /[mark]/(perm-mark-name kind)]
|
||||
=/ =rave:clay ?:(?=(%sing mode) [mode mood] [mode mood])
|
||||
[%pass wire %arvo %c %warp our.bowl %home `rave]
|
||||
::
|
||||
++ build-transform-add
|
||||
|= [=mark mode=?(%sing %next)]
|
||||
^- card
|
||||
=/ =wire /transform-add/[mark]
|
||||
=/ =mood:clay [%c da+now.bowl /[mark]/transform-add-nodes]
|
||||
=/ =rave:clay ?:(?=(%sing mode) [mode mood] [mode mood])
|
||||
[%pass wire %arvo %c %warp our.bowl %home `rave]
|
||||
::
|
||||
++ remove-mark
|
||||
|= [=resource:res vip=vip-metadata:metadata =indexed-post:store]
|
||||
(perm-mark resource %remove vip indexed-post)
|
||||
--
|
||||
--
|
||||
|
||||
|
@ -1,29 +1,26 @@
|
||||
:: graph-store [landscape]
|
||||
::
|
||||
::
|
||||
/+ store=graph-store, sigs=signatures, res=resource, default-agent, dbug, verb,
|
||||
*migrate
|
||||
/+ store=graph-store, sigs=signatures, res=resource, default-agent, dbug, verb
|
||||
~% %graph-store-top ..part ~
|
||||
|%
|
||||
+$ card card:agent:gall
|
||||
+$ versioned-state
|
||||
$% state-0
|
||||
state-1
|
||||
state-2
|
||||
state-3
|
||||
$% [%0 network:zero:store]
|
||||
[%1 network:zero:store]
|
||||
[%2 network:zero:store]
|
||||
[%3 network:one:store]
|
||||
[%4 network:store]
|
||||
state-5
|
||||
==
|
||||
::
|
||||
+$ state-0 [%0 network:zero:store]
|
||||
+$ state-1 [%1 network:zero:store]
|
||||
+$ state-2 [%2 network:zero:store]
|
||||
+$ state-3 [%3 network:store]
|
||||
::
|
||||
+$ state-5 [%5 network:store]
|
||||
++ orm orm:store
|
||||
++ orm-log orm-log:store
|
||||
+$ debug-input [%validate-graph =resource:store]
|
||||
--
|
||||
::
|
||||
=| state-3
|
||||
=| state-5
|
||||
=* state -
|
||||
::
|
||||
%- agent:dbug
|
||||
@ -41,19 +38,18 @@
|
||||
^- (quip card _this)
|
||||
=+ !<(old=versioned-state old-vase)
|
||||
=| cards=(list card)
|
||||
|^
|
||||
|-
|
||||
?- -.old
|
||||
%0
|
||||
%0
|
||||
=* zro zero-load:upgrade:store
|
||||
%_ $
|
||||
-.old %1
|
||||
cards cards
|
||||
validators.old validators.old
|
||||
::
|
||||
graphs.old
|
||||
%- ~(run by graphs.old)
|
||||
|= [=graph:zero:store q=(unit mark)]
|
||||
^- [graph:zero:store (unit mark)]
|
||||
:- (convert-unix-timestamped-graph:zero-load graph)
|
||||
:- (convert-unix-timestamped-graph:zro graph)
|
||||
?^ q q
|
||||
`%graph-validator-link
|
||||
::
|
||||
@ -63,138 +59,57 @@
|
||||
==
|
||||
::
|
||||
%1
|
||||
=* zro zero-load:upgrade:store
|
||||
%_ $
|
||||
-.old %2
|
||||
graphs.old (~(run by graphs.old) change-revision-graph:zero-load)
|
||||
graphs.old (~(run by graphs.old) change-revision-graph:zro)
|
||||
::
|
||||
update-logs.old
|
||||
%- ~(run by update-logs.old)
|
||||
|=(a=* *update-log:zero:store)
|
||||
==
|
||||
::
|
||||
%2
|
||||
%2
|
||||
=* upg upgrade:store
|
||||
%_ $
|
||||
-.old %3
|
||||
update-logs.old (~(run by update-logs.old) update-log-to-one:store)
|
||||
graphs.old (~(run by graphs.old) marked-graph-to-one:store)
|
||||
archive.old (~(run by archive.old) marked-graph-to-one:store)
|
||||
update-logs.old (~(run by update-logs.old) update-log-to-one:upg)
|
||||
graphs.old (~(run by graphs.old) marked-graph-to-one:upg)
|
||||
archive.old (~(run by archive.old) marked-graph-to-one:upg)
|
||||
==
|
||||
::
|
||||
%3 [cards this(state old)]
|
||||
==
|
||||
%3
|
||||
=* upg upgrade:store
|
||||
%_ $
|
||||
-.old %4
|
||||
graphs.old (~(run by graphs.old) marked-graph-to-two:upg)
|
||||
archive.old (~(run by archive.old) marked-graph-to-two:upg)
|
||||
tag-queries.old *tag-queries:store
|
||||
validators.old ~
|
||||
::
|
||||
update-logs.old
|
||||
%- ~(run by update-logs.old)
|
||||
|=(a=* *update-log:store)
|
||||
==
|
||||
::
|
||||
++ zero-load
|
||||
:: =* infinitely recurses
|
||||
=, store=zero:store
|
||||
=, orm=orm:zero:store
|
||||
=, orm-log=orm-log:zero:store
|
||||
|%
|
||||
++ change-revision-graph
|
||||
|= [=graph:store q=(unit mark)]
|
||||
^- [graph:store (unit mark)]
|
||||
|^
|
||||
:_ q
|
||||
?+ q graph
|
||||
[~ %graph-validator-link] convert-links
|
||||
[~ %graph-validator-publish] convert-publish
|
||||
==
|
||||
::
|
||||
++ convert-links
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm graph)
|
||||
|= [=atom =node:store]
|
||||
^- [^atom node:store]
|
||||
:: top-level
|
||||
::
|
||||
:+ atom post.node
|
||||
?: ?=(%empty -.children.node)
|
||||
[%empty ~]
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm p.children.node)
|
||||
|= [=^atom =node:store]
|
||||
^- [^^atom node:store]
|
||||
:: existing comments get turned into containers for revisions
|
||||
::
|
||||
:^ atom
|
||||
post.node(contents ~, hash ~)
|
||||
%graph
|
||||
%+ gas:orm *graph:store
|
||||
:_ ~ :- %0
|
||||
:_ [%empty ~]
|
||||
post.node(index (snoc index.post.node atom), hash ~)
|
||||
::
|
||||
++ convert-publish
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm graph)
|
||||
|= [=atom =node:store]
|
||||
^- [^atom node:store]
|
||||
:: top-level
|
||||
::
|
||||
:+ atom post.node
|
||||
?: ?=(%empty -.children.node)
|
||||
[%empty ~]
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm p.children.node)
|
||||
|= [=^atom =node:store]
|
||||
^- [^^atom node:store]
|
||||
:: existing container for publish note revisions
|
||||
::
|
||||
?+ atom !!
|
||||
%1 [atom node]
|
||||
%2
|
||||
:+ atom post.node
|
||||
?: ?=(%empty -.children.node)
|
||||
[%empty ~]
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm p.children.node)
|
||||
|= [=^^atom =node:store]
|
||||
^- [^^^atom node:store]
|
||||
:+ atom post.node(contents ~, hash ~)
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
:_ ~ :- %1
|
||||
:_ [%empty ~]
|
||||
post.node(index (snoc index.post.node atom), hash ~)
|
||||
==
|
||||
--
|
||||
::
|
||||
++ maybe-unix-to-da
|
||||
|= =atom
|
||||
^- @
|
||||
:: (bex 127) is roughly 226AD
|
||||
?. (lte atom (bex 127))
|
||||
atom
|
||||
(add ~1970.1.1 (div (mul ~s1 atom) 1.000))
|
||||
%4
|
||||
%_ $
|
||||
-.old %5
|
||||
::
|
||||
++ convert-unix-timestamped-node
|
||||
|= =node:store
|
||||
^- node:store
|
||||
=. index.post.node
|
||||
(convert-unix-timestamped-index index.post.node)
|
||||
?. ?=(%graph -.children.node)
|
||||
node
|
||||
:+ post.node
|
||||
%graph
|
||||
(convert-unix-timestamped-graph p.children.node)
|
||||
::
|
||||
++ convert-unix-timestamped-index
|
||||
|= =index:store
|
||||
(turn index maybe-unix-to-da)
|
||||
::
|
||||
++ convert-unix-timestamped-graph
|
||||
|= =graph:store
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn
|
||||
(tap:orm graph)
|
||||
|= [=atom =node:store]
|
||||
^- [^atom node:store]
|
||||
:- (maybe-unix-to-da atom)
|
||||
(convert-unix-timestamped-node node)
|
||||
--
|
||||
--
|
||||
update-logs.old
|
||||
%- ~(gas by *update-logs:store)
|
||||
%+ turn ~(tap by graphs.old)
|
||||
|= [=resource:store =graph:store mar=(unit mark)]
|
||||
:- resource
|
||||
=/ log (~(got by update-logs.old) resource)
|
||||
?. =(~ log) log
|
||||
=/ =logged-update:store
|
||||
[now.bowl %add-graph resource graph mar %.y]
|
||||
(gas:orm-log ~ [now.bowl logged-update] ~)
|
||||
==
|
||||
::
|
||||
%5 [cards this(state old)]
|
||||
==
|
||||
::
|
||||
++ on-watch
|
||||
~/ %graph-store-watch
|
||||
@ -213,7 +128,7 @@
|
||||
++ give
|
||||
|= =action:store
|
||||
^- (list card)
|
||||
[%give %fact ~ [%graph-update-1 !>([now.bowl action])]]~
|
||||
[%give %fact ~ [%graph-update-2 !>([now.bowl action])]]~
|
||||
--
|
||||
::
|
||||
++ on-poke
|
||||
@ -224,7 +139,7 @@
|
||||
?> (team:title our.bowl src.bowl)
|
||||
=^ cards state
|
||||
?+ mark (on-poke:def mark vase)
|
||||
%graph-update-1 (graph-update !<(update:store vase))
|
||||
%graph-update-2 (graph-update !<(update:store vase))
|
||||
%noun (debug !<(debug-input vase))
|
||||
%import (poke-import q.vase)
|
||||
==
|
||||
@ -239,7 +154,7 @@
|
||||
%add-graph (add-graph p.update +.q.update)
|
||||
%remove-graph (remove-graph +.q.update)
|
||||
%add-nodes (add-nodes p.update +.q.update)
|
||||
%remove-nodes (remove-nodes p.update +.q.update)
|
||||
%remove-posts (remove-posts p.update +.q.update)
|
||||
%add-signatures (add-signatures p.update +.q.update)
|
||||
%remove-signatures (remove-signatures p.update +.q.update)
|
||||
%add-tag (add-tag +.q.update)
|
||||
@ -319,27 +234,27 @@
|
||||
++ check-for-duplicates
|
||||
|= [=graph:store nodes=(set index:store)]
|
||||
^- ?
|
||||
=/ node-list ~(tap in nodes)
|
||||
|-
|
||||
?~ node-list %.n
|
||||
?: (has-node graph i.node-list) %.y
|
||||
$(node-list t.node-list)
|
||||
::
|
||||
++ has-node
|
||||
|= [=graph:store =index:store]
|
||||
^- ?
|
||||
=/ node=(unit node:store) ~
|
||||
|-
|
||||
?~ index
|
||||
?=(^ node)
|
||||
?~ t.index
|
||||
?=(^ (get:orm graph i.index))
|
||||
=. node (get:orm graph i.index)
|
||||
?~ node %.n
|
||||
?- -.children.u.node
|
||||
%empty %.n
|
||||
%graph $(graph p.children.u.node, index t.index)
|
||||
==
|
||||
|^
|
||||
%+ lien ~(tap in nodes)
|
||||
|= =index:store
|
||||
(has-node graph index)
|
||||
::
|
||||
++ has-node
|
||||
|= [=graph:store =index:store]
|
||||
^- ?
|
||||
=/ node=(unit node:store) ~
|
||||
|-
|
||||
?~ index
|
||||
?=(^ node)
|
||||
?~ t.index
|
||||
?=(^ (get:orm graph i.index))
|
||||
=. node (get:orm graph i.index)
|
||||
?~ node %.n
|
||||
?- -.children.u.node
|
||||
%empty %.n
|
||||
%graph $(graph p.children.u.node, index t.index)
|
||||
==
|
||||
--
|
||||
::
|
||||
++ sort-nodes
|
||||
|= nodes=(map index:store node:store)
|
||||
@ -382,8 +297,10 @@
|
||||
:: add child
|
||||
::
|
||||
?~ t.index
|
||||
=* p post.node
|
||||
?~ hash.p node(signatures.post *signatures:store)
|
||||
~| "cannot add deleted post"
|
||||
?> ?=(%& -.post.node)
|
||||
=* p p.post.node
|
||||
?~ hash.p node(signatures.p.post *signatures:store)
|
||||
=/ =validated-portion:store
|
||||
[parent-hash author.p time-sent.p contents.p]
|
||||
=/ =hash:store `@ux`(sham validated-portion)
|
||||
@ -402,8 +319,14 @@
|
||||
^- internal-graph:store
|
||||
:- %graph
|
||||
%_ $
|
||||
index t.index
|
||||
parent-hash hash.post.parent
|
||||
index t.index
|
||||
::
|
||||
parent-hash
|
||||
?- -.post.parent
|
||||
%| `p.post.parent
|
||||
%& hash.p.post.parent
|
||||
==
|
||||
::
|
||||
graph
|
||||
?: ?=(%graph -.children.parent)
|
||||
p.children.parent
|
||||
@ -412,7 +335,7 @@
|
||||
==
|
||||
--
|
||||
::
|
||||
++ remove-nodes
|
||||
++ remove-posts
|
||||
|= [=time =resource:store indices=(set index:store)]
|
||||
^- (quip card _state)
|
||||
|^
|
||||
@ -420,82 +343,83 @@
|
||||
(~(got by graphs) resource)
|
||||
=/ =update-log:store (~(got by update-logs) resource)
|
||||
=. update-log
|
||||
(put:orm-log update-log time [time [%remove-nodes resource indices]])
|
||||
=/ [affected-indices=(set index:store) new-graph=graph:store]
|
||||
(remove-indices resource graph (sort ~(tap in indices) by-lent))
|
||||
::
|
||||
:- (give [/updates]~ [%remove-nodes resource (~(uni in indices) affected-indices)])
|
||||
(put:orm-log update-log time [time [%remove-posts resource indices]])
|
||||
:- (give [/updates]~ [%remove-posts resource indices])
|
||||
%_ state
|
||||
update-logs (~(put by update-logs) resource update-log)
|
||||
update-logs (~(put by update-logs) resource update-log)
|
||||
::
|
||||
graphs
|
||||
%+ ~(put by graphs)
|
||||
resource
|
||||
[new-graph mark]
|
||||
:_ mark
|
||||
%^ remove-indices
|
||||
resource
|
||||
graph
|
||||
(sort ~(tap in indices) by-lent)
|
||||
==
|
||||
::
|
||||
:: we always want to remove the deepest node first,
|
||||
:: so we don't remove parents before children
|
||||
++ by-lent
|
||||
|* [a=(list) b=(list)]
|
||||
^- ?
|
||||
(gth (lent a) (lent b))
|
||||
::
|
||||
++ remove-indices
|
||||
=| affected=(set index:store)
|
||||
|= [=resource:store =graph:store indices=(list index:store)]
|
||||
^- [(set index:store) graph:store]
|
||||
?~ indices [affected graph]
|
||||
=^ new-affected graph
|
||||
(remove-index graph i.indices)
|
||||
^- graph:store
|
||||
?~ indices graph
|
||||
%_ $
|
||||
indices t.indices
|
||||
affected (~(uni in affected) new-affected)
|
||||
==
|
||||
::
|
||||
++ get-descendants
|
||||
|= =graph:store
|
||||
=| indices=(list index:store)
|
||||
=/ nodes (tap:orm:store graph)
|
||||
%- ~(gas in *(set index:store))
|
||||
|- =* tap-nodes $
|
||||
^+ indices
|
||||
%- zing
|
||||
%+ turn nodes
|
||||
|= [atom =node:store]
|
||||
^- (list index:store)
|
||||
%+ welp
|
||||
index.post.node^~
|
||||
?. ?=(%graph -.children.node)
|
||||
~
|
||||
%_ tap-nodes
|
||||
nodes (tap:orm p.children.node)
|
||||
indices t.indices
|
||||
graph (remove-index graph i.indices)
|
||||
==
|
||||
::
|
||||
++ remove-index
|
||||
=| indices=(set index:store)
|
||||
=| parent-hash=(unit hash:store)
|
||||
|= [=graph:store =index:store]
|
||||
^- [(set index:store) graph:store]
|
||||
?~ index [indices graph]
|
||||
^- graph:store
|
||||
?~ index graph
|
||||
=* atom i.index
|
||||
%^ put:orm
|
||||
graph
|
||||
atom
|
||||
:: last index in list
|
||||
::
|
||||
?~ t.index
|
||||
=^ rm-node graph (del:orm graph atom)
|
||||
?~ rm-node `graph
|
||||
?. ?=(%graph -.children.u.rm-node)
|
||||
`graph
|
||||
=/ new-indices
|
||||
(get-descendants p.children.u.rm-node)
|
||||
[(~(uni in indices) new-indices) graph]
|
||||
=/ =node:store
|
||||
=/ =node:store
|
||||
~| "cannot remove index that does not exist {<index>}"
|
||||
(need (get:orm graph atom))
|
||||
%_ node
|
||||
post
|
||||
~| "cannot remove post that has already been removed"
|
||||
?> ?=(%& -.post.node)
|
||||
=* p p.post.node
|
||||
^- maybe-post:store
|
||||
:- %|
|
||||
?~ hash.p
|
||||
=/ =validated-portion:store
|
||||
[parent-hash author.p time-sent.p contents.p]
|
||||
`@ux`(sham validated-portion)
|
||||
u.hash.p
|
||||
==
|
||||
:: recurse children
|
||||
::
|
||||
=/ parent=node:store
|
||||
~| "parent index does not exist to remove a node from!"
|
||||
(need (get:orm graph atom))
|
||||
~| "child index does not exist to remove a node from!"
|
||||
?> ?=(%graph -.children.node)
|
||||
=^ new-indices p.children.node
|
||||
$(graph p.children.node, index t.index)
|
||||
:- (~(uni in indices) new-indices)
|
||||
(put:orm graph atom node)
|
||||
?> ?=(%graph -.children.parent)
|
||||
%_ parent
|
||||
p.children
|
||||
%_ $
|
||||
index t.index
|
||||
graph p.children.parent
|
||||
::
|
||||
parent-hash
|
||||
?- -.post.parent
|
||||
%| `p.post.parent
|
||||
%& hash.p.post.parent
|
||||
==
|
||||
==
|
||||
==
|
||||
--
|
||||
::
|
||||
++ add-signatures
|
||||
@ -531,11 +455,13 @@
|
||||
graph
|
||||
atom
|
||||
?~ t.index
|
||||
~| "cannot add signatures to a deleted post"
|
||||
?> ?=(%& -.post.node)
|
||||
~| "cannot add signatures to a node missing a hash"
|
||||
?> ?=(^ hash.post.node)
|
||||
?> ?=(^ hash.p.post.node)
|
||||
~| "signatures did not match public keys!"
|
||||
?> (are-signatures-valid:sigs our.bowl signatures u.hash.post.node now.bowl)
|
||||
node(signatures.post (~(uni in signatures) signatures.post.node))
|
||||
?> (are-signatures-valid:sigs our.bowl signatures u.hash.p.post.node now.bowl)
|
||||
node(signatures.p.post (~(uni in signatures) signatures.p.post.node))
|
||||
~| "child graph does not exist to add signatures to!"
|
||||
?> ?=(%graph -.children.node)
|
||||
node(p.children $(graph p.children.node, index t.index))
|
||||
@ -576,28 +502,29 @@
|
||||
graph
|
||||
atom
|
||||
?~ t.index
|
||||
node(signatures.post (~(dif in signatures) signatures.post.node))
|
||||
~| "cannot add signatures to a deleted post"
|
||||
?> ?=(%& -.post.node)
|
||||
node(signatures.p.post (~(dif in signatures) signatures.p.post.node))
|
||||
~| "child graph does not exist to add signatures to!"
|
||||
?> ?=(%graph -.children.node)
|
||||
node(p.children $(graph p.children.node, index t.index))
|
||||
--
|
||||
::
|
||||
++ add-tag
|
||||
|= [=term =resource:store]
|
||||
|= [=term =uid:store]
|
||||
^- (quip card _state)
|
||||
?> (~(has by graphs) resource)
|
||||
:- (give [/updates /tags ~] [%add-tag term resource])
|
||||
?> (~(has by graphs) resource.uid)
|
||||
:- (give [/updates /tags ~] [%add-tag term uid])
|
||||
%_ state
|
||||
tag-queries (~(put ju tag-queries) term resource)
|
||||
tag-queries (~(put ju tag-queries) term uid)
|
||||
==
|
||||
::
|
||||
++ remove-tag
|
||||
|= [=term =resource:store]
|
||||
|= [=term =uid:store]
|
||||
^- (quip card _state)
|
||||
?> (~(has by graphs) resource)
|
||||
:- (give [/updates /tags ~] [%remove-tag term resource])
|
||||
:- (give [/updates /tags ~] [%remove-tag term uid])
|
||||
%_ state
|
||||
tag-queries (~(del ju tag-queries) term resource)
|
||||
tag-queries (~(del ju tag-queries) term uid)
|
||||
==
|
||||
::
|
||||
++ archive-graph
|
||||
@ -610,10 +537,6 @@
|
||||
archive (~(put by archive) resource (~(got by graphs) resource))
|
||||
graphs (~(del by graphs) resource)
|
||||
update-logs (~(del by update-logs) resource)
|
||||
tag-queries
|
||||
%- ~(run by tag-queries)
|
||||
|= =resources:store
|
||||
(~(del in resources) resource)
|
||||
==
|
||||
::
|
||||
++ unarchive-graph
|
||||
@ -648,7 +571,7 @@
|
||||
?- -.q.update
|
||||
%add-graph update(resource.q resource)
|
||||
%add-nodes update(resource.q resource)
|
||||
%remove-nodes update(resource.q resource)
|
||||
%remove-posts update(resource.q resource)
|
||||
%add-signatures update(resource.uid.q resource)
|
||||
%remove-signatures update(resource.uid.q resource)
|
||||
==
|
||||
@ -657,7 +580,7 @@
|
||||
++ give
|
||||
|= [paths=(list path) update=action:store]
|
||||
^- (list card)
|
||||
[%give %fact paths [%graph-update-1 !>([now.bowl update])]]~
|
||||
[%give %fact paths [%graph-update-2 !>([now.bowl update])]]~
|
||||
--
|
||||
::
|
||||
++ debug
|
||||
@ -682,7 +605,10 @@
|
||||
%+ roll (tap:orm graph)
|
||||
|= [[=atom =node:store] out=?]
|
||||
^- ?
|
||||
?& ?=(^ (vale:dais [atom post.node]))
|
||||
?& ?| ?=(%| -.post.node)
|
||||
?=(^ (vale:dais [atom p.post.node]))
|
||||
==
|
||||
::
|
||||
?- -.children.node
|
||||
%empty %.y
|
||||
%graph ^$(graph p.children.node)
|
||||
@ -691,155 +617,7 @@
|
||||
++ poke-import
|
||||
|= arc=*
|
||||
^- (quip card _state)
|
||||
|^
|
||||
=/ sty=state-3 [%3 (remake-network ;;(tree-network +.arc))]
|
||||
:_ sty
|
||||
%+ turn ~(tap by graphs.sty)
|
||||
|= [rid=resource:store =marked-graph:store]
|
||||
^- card
|
||||
?: =(our.bowl entity.rid)
|
||||
=/ =cage [%push-hook-action !>([%add rid])]
|
||||
[%pass / %agent [our.bowl %graph-push-hook] %poke cage]
|
||||
(try-rejoin rid 0)
|
||||
::
|
||||
+$ tree-network
|
||||
$: graphs=tree-graphs
|
||||
tag-queries=(tree [term (tree resource:store)])
|
||||
update-logs=tree-update-logs
|
||||
archive=tree-graphs
|
||||
validators=(tree ^mark)
|
||||
==
|
||||
+$ tree-graphs (tree [resource:store tree-marked-graph])
|
||||
+$ tree-marked-graph [p=tree-graph q=(unit ^mark)]
|
||||
+$ tree-graph (tree [atom tree-node])
|
||||
+$ tree-node [post=tree-post children=tree-internal-graph]
|
||||
+$ tree-internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=tree-graph]
|
||||
[%empty ~]
|
||||
==
|
||||
+$ tree-update-logs (tree [resource:store tree-update-log])
|
||||
+$ tree-update-log (tree [time tree-logged-update])
|
||||
+$ tree-logged-update
|
||||
$: p=time
|
||||
$= q
|
||||
$% [%add-graph =resource:store =tree-graph mark=(unit ^mark) ow=?]
|
||||
[%add-nodes =resource:store nodes=(tree [index:store tree-node])]
|
||||
[%remove-nodes =resource:store indices=(tree index:store)]
|
||||
[%add-signatures =uid:store signatures=tree-signatures]
|
||||
[%remove-signatures =uid:store signatures=tree-signatures]
|
||||
==
|
||||
==
|
||||
+$ tree-signatures (tree signature:store)
|
||||
+$ tree-post
|
||||
$: author=ship
|
||||
=index:store
|
||||
time-sent=time
|
||||
contents=(list content:store)
|
||||
hash=(unit hash:store)
|
||||
signatures=tree-signatures
|
||||
==
|
||||
::
|
||||
++ remake-network
|
||||
|= t=tree-network
|
||||
^- network:store
|
||||
:* (remake-graphs graphs.t)
|
||||
(remake-jug tag-queries.t)
|
||||
(remake-update-logs update-logs.t)
|
||||
(remake-graphs archive.t)
|
||||
(remake-set validators.t)
|
||||
==
|
||||
::
|
||||
++ remake-graphs
|
||||
|= t=tree-graphs
|
||||
^- graphs:store
|
||||
%- remake-map
|
||||
(~(run by t) remake-marked-graph)
|
||||
::
|
||||
++ remake-marked-graph
|
||||
|= t=tree-marked-graph
|
||||
^- marked-graph:store
|
||||
[(remake-graph p.t) q.t]
|
||||
::
|
||||
++ remake-graph
|
||||
|= t=tree-graph
|
||||
^- graph:store
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn ~(tap by t)
|
||||
|= [a=atom tn=tree-node]
|
||||
^- [atom node:store]
|
||||
[a (remake-node tn)]
|
||||
::
|
||||
++ remake-internal-graph
|
||||
|= t=tree-internal-graph
|
||||
^- internal-graph:store
|
||||
?: ?=(%empty -.t)
|
||||
[%empty ~]
|
||||
[%graph (remake-graph p.t)]
|
||||
::
|
||||
++ remake-node
|
||||
|= t=tree-node
|
||||
^- node:store
|
||||
:- (remake-post post.t)
|
||||
(remake-internal-graph children.t)
|
||||
::
|
||||
++ remake-update-logs
|
||||
|= t=tree-update-logs
|
||||
^- update-logs:store
|
||||
%- remake-map
|
||||
(~(run by t) remake-update-log)
|
||||
::
|
||||
++ remake-update-log
|
||||
|= t=tree-update-log
|
||||
^- update-log:store
|
||||
=/ ulm ((ordered-map time logged-update:store) gth)
|
||||
%+ gas:ulm *update-log:store
|
||||
%+ turn ~(tap by t)
|
||||
|= [=time tlu=tree-logged-update]
|
||||
^- [^time logged-update:store]
|
||||
[time (remake-logged-update tlu)]
|
||||
::
|
||||
++ remake-logged-update
|
||||
|= t=tree-logged-update
|
||||
^- logged-update:store
|
||||
:- p.t
|
||||
?- -.q.t
|
||||
%add-graph
|
||||
:* %add-graph
|
||||
resource.q.t
|
||||
(remake-graph tree-graph.q.t)
|
||||
mark.q.t
|
||||
ow.q.t
|
||||
==
|
||||
::
|
||||
%add-nodes
|
||||
:- %add-nodes
|
||||
:- resource.q.t
|
||||
%- remake-map
|
||||
(~(run by nodes.q.t) remake-node)
|
||||
::
|
||||
%remove-nodes
|
||||
[%remove-nodes resource.q.t (remake-set indices.q.t)]
|
||||
::
|
||||
%add-signatures
|
||||
[%add-signatures uid.q.t (remake-set signatures.q.t)]
|
||||
::
|
||||
%remove-signatures
|
||||
[%remove-signatures uid.q.t (remake-set signatures.q.t)]
|
||||
==
|
||||
::
|
||||
++ remake-post
|
||||
|= t=tree-post
|
||||
^- post:store
|
||||
t(signatures (remake-set signatures.t))
|
||||
--
|
||||
::
|
||||
++ try-rejoin
|
||||
|= [rid=resource:store nack-count=@]
|
||||
^- card
|
||||
=/ res-path (en-path:res rid)
|
||||
=/ wire [%try-rejoin (scot %ud nack-count) res-path]
|
||||
[%pass wire %agent [entity.rid %graph-push-hook] %watch resource+res-path]
|
||||
(import:store arc our.bowl)
|
||||
--
|
||||
::
|
||||
++ on-peek
|
||||
@ -858,15 +636,15 @@
|
||||
``noun+!>(q.u.result)
|
||||
::
|
||||
[%x %keys ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!>(`update:store`[now.bowl [%keys ~(key by graphs)]])
|
||||
::
|
||||
[%x %tags ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!>(`update:store`[now.bowl [%tags ~(key by tag-queries)]])
|
||||
::
|
||||
[%x %tag-queries ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!>(`update:store`[now.bowl [%tag-queries tag-queries]])
|
||||
::
|
||||
[%x %graph @ @ ~]
|
||||
@ -875,7 +653,7 @@
|
||||
=/ result=(unit marked-graph:store)
|
||||
(~(get by graphs) [ship term])
|
||||
?~ result [~ ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
[%add-graph [ship term] `graph:store`p.u.result q.u.result %.y]
|
||||
@ -890,7 +668,7 @@
|
||||
?~ result
|
||||
~& no-archived-graph+[ship term]
|
||||
[~ ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
[%add-graph [ship term] `graph:store`p.u.result q.u.result %.y]
|
||||
@ -906,7 +684,7 @@
|
||||
=/ graph=(unit marked-graph:store)
|
||||
(~(get by graphs) [ship term])
|
||||
?~ graph [~ ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
:+ %add-nodes
|
||||
@ -933,7 +711,7 @@
|
||||
(turn t.t.t.t.path (cury slav %ud))
|
||||
=/ node=(unit node:store) (get-node ship term index)
|
||||
?~ node [~ ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
:+ %add-nodes
|
||||
@ -952,7 +730,7 @@
|
||||
=/ graph
|
||||
(get-node-children ship term parent)
|
||||
?~ graph [~ ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
:+ %add-nodes
|
||||
@ -982,7 +760,7 @@
|
||||
=/ children
|
||||
(get-node-children ship term index)
|
||||
?~ children [~ ~]
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
:+ %add-nodes
|
||||
@ -1008,7 +786,7 @@
|
||||
?- -.children.u.node
|
||||
%empty [~ ~]
|
||||
%graph
|
||||
:- ~ :- ~ :- %graph-update-1
|
||||
:- ~ :- ~ :- %graph-update-2
|
||||
!> ^- update:store
|
||||
:- now.bowl
|
||||
:+ %add-nodes
|
||||
|
@ -24,7 +24,6 @@
|
||||
watch-on-self=_&
|
||||
==
|
||||
::
|
||||
::
|
||||
++ scry
|
||||
|* [[our=@p now=@da] =mold p=path]
|
||||
?> ?=(^ p)
|
||||
@ -37,7 +36,6 @@
|
||||
%^ scry [our now]
|
||||
tube:clay
|
||||
/cc/[desk]/[mark]/notification-kind
|
||||
::
|
||||
--
|
||||
::
|
||||
=| state-1
|
||||
@ -182,7 +180,7 @@
|
||||
~[watch-graph:ha]
|
||||
::
|
||||
%fact
|
||||
?. ?=(%graph-update-1 p.cage.sign)
|
||||
?. ?=(%graph-update-2 p.cage.sign)
|
||||
(on-agent:def wire sign)
|
||||
=^ cards state
|
||||
(graph-update !<(update:graph-store q.cage.sign))
|
||||
@ -198,8 +196,8 @@
|
||||
?(%remove-graph %archive-graph)
|
||||
(remove-graph resource.q.update)
|
||||
::
|
||||
%remove-nodes
|
||||
(remove-nodes resource.q.update indices.q.update)
|
||||
%remove-posts
|
||||
(remove-posts resource.q.update indices.q.update)
|
||||
::
|
||||
%add-nodes
|
||||
=* rid resource.q.update
|
||||
@ -208,7 +206,7 @@
|
||||
:: this is awful, but notification kind should always switch
|
||||
:: on the index, so hopefully doesn't matter
|
||||
:: TODO: rethink this
|
||||
++ remove-nodes
|
||||
++ remove-posts
|
||||
|= [rid=resource indices=(set index:graph-store)]
|
||||
=/ to-remove
|
||||
%- ~(gas by *(set [resource index:graph-store]))
|
||||
@ -264,7 +262,6 @@
|
||||
:_ state(watching (~(put in watching) [rid ~]))
|
||||
(weld cards (give:ha ~[/updates] %listen [rid ~]))
|
||||
::
|
||||
::
|
||||
++ check-nodes
|
||||
|= $: nodes=(list node:graph-store)
|
||||
rid=resource
|
||||
@ -417,30 +414,33 @@
|
||||
|= =node:graph-store
|
||||
^+ update-core
|
||||
=. update-core (check-node-children node)
|
||||
?: ?=(%| -.post.node)
|
||||
update-core
|
||||
=* pos p.post.node
|
||||
=+ !< notif-kind=(unit notif-kind:hook)
|
||||
(get-conversion !>([0 post.node]))
|
||||
(get-conversion !>([0 pos]))
|
||||
?~ notif-kind
|
||||
update-core
|
||||
=/ desc=@t
|
||||
?: (is-mention contents.post.node)
|
||||
?: (is-mention contents.pos)
|
||||
%mention
|
||||
name.u.notif-kind
|
||||
=* not-kind u.notif-kind
|
||||
=/ parent=index:post
|
||||
(scag parent.index-len.not-kind index.post.node)
|
||||
(scag parent.index-len.not-kind index.pos)
|
||||
=/ notif-index=index:store
|
||||
[%graph group rid module desc parent]
|
||||
?: =(our.bowl author.post.node)
|
||||
?: =(our.bowl author.pos)
|
||||
(self-post node notif-index not-kind)
|
||||
=. update-core
|
||||
(update-unread-count not-kind notif-index [time-sent index]:post.node)
|
||||
(update-unread-count not-kind notif-index [time-sent index]:pos)
|
||||
=? update-core
|
||||
?| =(desc %mention)
|
||||
(~(has in watching) [rid parent])
|
||||
==
|
||||
=/ =contents:store
|
||||
[%graph (limo post.node ~)]
|
||||
(add-unread notif-index [time-sent.post.node %.n contents])
|
||||
[%graph (limo pos ~)]
|
||||
(add-unread notif-index [time-sent.pos %.n contents])
|
||||
update-core
|
||||
::
|
||||
++ update-unread-count
|
||||
@ -459,19 +459,19 @@
|
||||
=notif-kind:hook
|
||||
==
|
||||
^+ update-core
|
||||
?> ?=(%& -.post.node)
|
||||
=/ =stats-index:store
|
||||
(to-stats-index:store index)
|
||||
=. update-core
|
||||
(hark %seen-index time-sent.post.node stats-index)
|
||||
(hark %seen-index time-sent.p.post.node stats-index)
|
||||
=? update-core ?=(%count mode.notif-kind)
|
||||
(hark %read-count stats-index)
|
||||
=? update-core watch-on-self
|
||||
(new-watch index.post.node [watch-for index-len]:notif-kind)
|
||||
(new-watch index.p.post.node [watch-for index-len]:notif-kind)
|
||||
update-core
|
||||
::
|
||||
++ add-unread
|
||||
|= [=index:store =notification:store]
|
||||
(hark %add-note index notification)
|
||||
::
|
||||
--
|
||||
--
|
||||
|
@ -202,7 +202,7 @@
|
||||
++ convert-graph-contents-4
|
||||
|= con=(list post:post-zero:post)
|
||||
^- (list post:post)
|
||||
(turn con post-to-one:graph-store)
|
||||
(turn con post-to-one:upgrade:graph-store)
|
||||
::
|
||||
++ convert-notifications-3
|
||||
|= old=notifications:state-two:store
|
||||
|
@ -24,6 +24,6 @@
|
||||
<div id="portal-root"></div>
|
||||
<script src="/~landscape/js/channel.js"></script>
|
||||
<script src="/~landscape/js/session.js"></script>
|
||||
<script src="/~landscape/js/bundle/index.59e682153138f604d358.js"></script>
|
||||
<script src="/~landscape/js/bundle/index.2eee573a41d00825e88a.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -5,6 +5,6 @@
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=resource mark=(unit mark) overwrite=? ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%add-graph resource (gas:orm ~ ~) mark overwrite]]
|
||||
|
@ -12,9 +12,9 @@
|
||||
contents.post contents
|
||||
==
|
||||
::
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
:- now
|
||||
:+ %add-nodes [our name]
|
||||
%- ~(gas by *(map index node))
|
||||
~[[[now]~ [post [%empty ~]]]]
|
||||
~[[[now]~ [[%& post] [%empty ~]]]]
|
||||
|
@ -5,6 +5,6 @@
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[[=resource =index] =signatures ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%add-signatures [resource index] signatures]]
|
||||
|
@ -3,8 +3,8 @@
|
||||
/- *graph-store
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=term =resource ~] ~]
|
||||
[[=term =uid ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%add-tag term resource]]
|
||||
[now [%add-tag term uid]]
|
||||
|
@ -5,6 +5,6 @@
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=resource ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%archive-graph resource]]
|
||||
|
@ -4,7 +4,7 @@
|
||||
|= $: [now=@da eny=@uvJ bec=beak]
|
||||
[[=ship graph=term ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
=/ our (scot %p p.bec)
|
||||
=/ wen (scot %da now)
|
||||
=/ who (scot %p ship)
|
||||
|
@ -4,6 +4,6 @@
|
||||
|= $: [now=@da eny=@uvJ bec=beak]
|
||||
[[graph=term =path ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
=- ~& update=- -
|
||||
.^(=update:graph-store %cx path)
|
||||
|
@ -5,6 +5,6 @@
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=resource ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%remove-graph resource]]
|
||||
|
@ -1,10 +1,10 @@
|
||||
:: graph-store|remove-nodes: remove nodes from a graph at indices
|
||||
:: graph-store|remove-posts: remove nodes from a graph at indices
|
||||
::
|
||||
/- *graph-store
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=resource indices=(set index) ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%remove-nodes resource indices]]
|
||||
[now [%remove-posts resource indices]]
|
@ -6,6 +6,6 @@
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[[=resource =index] =signatures ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%remove-signatures [resource index] signatures]]
|
||||
|
@ -3,8 +3,8 @@
|
||||
/- *graph-store
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=term =resource ~] ~]
|
||||
[[=term =uid ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%remove-tag term resource]]
|
||||
[now [%remove-tag term uid]]
|
||||
|
@ -5,6 +5,6 @@
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=resource ~] ~]
|
||||
==
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
^- update
|
||||
[now [%unarchive-graph resource]]
|
||||
|
@ -67,7 +67,7 @@
|
||||
=/ real=(set resource:re)
|
||||
=/ upd=update:ga
|
||||
%+ scry update:ga
|
||||
[%x %graph-store /keys/graph-update-1]
|
||||
[%x %graph-store /keys/graph-update-2]
|
||||
?> ?=(%keys -.q.upd)
|
||||
resources.q.upd
|
||||
:: count activity per channel
|
||||
@ -92,8 +92,11 @@
|
||||
:- (lent week)
|
||||
%~ wyt in
|
||||
%+ roll week
|
||||
|= [[* [author=ship *] *] a=(set ship)]
|
||||
(~(put in a) author)
|
||||
|= [[* mp=maybe-post:ga *] a=(set ship)]
|
||||
?- -.mp
|
||||
%| a
|
||||
%& (~(put in a) author.p.mp)
|
||||
==
|
||||
:: render results
|
||||
::
|
||||
:- (tac 'the date is ' (scot %da now))
|
||||
|
@ -1,105 +1,10 @@
|
||||
/- sur=graph-store, pos=post
|
||||
/+ res=resource
|
||||
/+ res=resource, migrate
|
||||
=< [sur .]
|
||||
=< [pos .]
|
||||
=, sur
|
||||
=, pos
|
||||
|%
|
||||
::
|
||||
++ update-log-to-one
|
||||
|= =update-log:zero
|
||||
^- ^update-log
|
||||
%+ gas:orm-log *^update-log
|
||||
%+ turn (tap:orm-log:zero update-log)
|
||||
|= [=time =logged-update:zero]
|
||||
:- time
|
||||
:- p.logged-update
|
||||
(logged-update-to-one q.logged-update)
|
||||
::
|
||||
++ logged-update-to-one
|
||||
|= upd=logged-update-0:zero
|
||||
?+ -.upd upd
|
||||
%add-graph upd(graph (graph-to-one graph.upd))
|
||||
%add-nodes upd(nodes (~(run by nodes.upd) node-to-one))
|
||||
==
|
||||
::
|
||||
++ node-to-one
|
||||
|= =node:zero
|
||||
(node:(upgrade ,post:zero ,post) node post-to-one)
|
||||
::
|
||||
++ graph-to-one
|
||||
|= =graph:zero
|
||||
(graph:(upgrade ,post:zero ,post) graph post-to-one)
|
||||
::
|
||||
++ marked-graph-to-one
|
||||
|= [=graph:zero m=(unit mark)]
|
||||
[(graph-to-one graph) m]
|
||||
::
|
||||
++ post-to-one
|
||||
|= p=post:zero
|
||||
^- post
|
||||
p(contents (contents-to-one contents.p))
|
||||
::
|
||||
++ contents-to-one
|
||||
|= cs=(list content:zero)
|
||||
^- (list content)
|
||||
%+ murn cs
|
||||
|= =content:zero
|
||||
^- (unit ^content)
|
||||
?: ?=(%reference -.content) ~
|
||||
`content
|
||||
::
|
||||
++ upgrade
|
||||
|* [in-pst=mold out-pst=mold]
|
||||
=>
|
||||
|%
|
||||
++ in-orm
|
||||
((ordered-map atom in-node) gth)
|
||||
+$ in-node
|
||||
[post=in-pst children=in-internal-graph]
|
||||
+$ in-graph
|
||||
((mop atom in-node) gth)
|
||||
+$ in-internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=in-graph]
|
||||
[%empty ~]
|
||||
==
|
||||
::
|
||||
++ out-orm
|
||||
((ordered-map atom out-node) gth)
|
||||
+$ out-node
|
||||
[post=out-pst children=out-internal-graph]
|
||||
+$ out-graph
|
||||
((mop atom out-node) gth)
|
||||
+$ out-internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=out-graph]
|
||||
[%empty ~]
|
||||
==
|
||||
--
|
||||
|%
|
||||
::
|
||||
++ graph
|
||||
|= $: gra=in-graph
|
||||
fn=$-(in-pst out-pst)
|
||||
==
|
||||
^- out-graph
|
||||
%+ gas:out-orm *out-graph
|
||||
^- (list [atom out-node])
|
||||
%+ turn (tap:in-orm gra)
|
||||
|= [a=atom n=in-node]
|
||||
^- [atom out-node]
|
||||
[a (node n fn)]
|
||||
::
|
||||
++ node
|
||||
|= [nod=in-node fn=$-(in-pst out-pst)]
|
||||
^- out-node
|
||||
:- (fn post.nod)
|
||||
^- out-internal-graph
|
||||
?: ?=(%empty -.children.nod)
|
||||
[%empty ~]
|
||||
[%graph (graph p.children.nod fn)]
|
||||
--
|
||||
:: NOTE: move these functions to zuse
|
||||
++ nu :: parse number as hex
|
||||
|= jon=json
|
||||
@ -211,6 +116,14 @@
|
||||
s+(enjs-path:res grp)
|
||||
--
|
||||
::
|
||||
++ maybe-post
|
||||
|= mp=^maybe-post
|
||||
^- json
|
||||
?- -.mp
|
||||
%| s+(scot %ux p.mp)
|
||||
%& (post p.mp)
|
||||
==
|
||||
::
|
||||
++ post
|
||||
|= p=^post
|
||||
^- json
|
||||
@ -251,8 +164,8 @@
|
||||
[%nodes (nodes nodes.upd)]
|
||||
==
|
||||
::
|
||||
%remove-nodes
|
||||
:- %remove-nodes
|
||||
%remove-posts
|
||||
:- %remove-posts
|
||||
%- pairs
|
||||
:~ [%resource (enjs:res resource.upd)]
|
||||
[%indices (indices indices.upd)]
|
||||
@ -276,14 +189,14 @@
|
||||
:- %add-tag
|
||||
%- pairs
|
||||
:~ [%term s+term.upd]
|
||||
[%resource (enjs:res resource.upd)]
|
||||
[%uid (uid uid.upd)]
|
||||
==
|
||||
::
|
||||
%remove-tag
|
||||
:- %remove-tag
|
||||
%- pairs
|
||||
:~ [%term s+term.upd]
|
||||
[%resource (enjs:res resource.upd)]
|
||||
[%uid (uid uid.upd)]
|
||||
==
|
||||
::
|
||||
%archive-graph
|
||||
@ -305,9 +218,9 @@
|
||||
:- %tag-queries
|
||||
%- pairs
|
||||
%+ turn ~(tap by tag-queries.upd)
|
||||
|= [=term =resources]
|
||||
|= [=term uids=(set ^uid)]
|
||||
^- [cord json]
|
||||
[term [%a (turn ~(tap in resources) enjs:res)]]
|
||||
[term [%a (turn ~(tap in uids) uid)]]
|
||||
==
|
||||
::
|
||||
++ graph
|
||||
@ -327,7 +240,7 @@
|
||||
|= n=^node
|
||||
^- json
|
||||
%- pairs
|
||||
:~ [%post (post post.n)]
|
||||
:~ [%post (maybe-post post.n)]
|
||||
:- %children
|
||||
?- -.children.n
|
||||
%empty ~
|
||||
@ -335,7 +248,6 @@
|
||||
==
|
||||
==
|
||||
::
|
||||
::
|
||||
++ nodes
|
||||
|= m=(map ^index ^node)
|
||||
^- json
|
||||
@ -369,7 +281,7 @@
|
||||
++ decode
|
||||
%- of
|
||||
:~ [%add-nodes add-nodes]
|
||||
[%remove-nodes remove-nodes]
|
||||
[%remove-posts remove-posts]
|
||||
[%add-signatures add-signatures]
|
||||
[%remove-signatures remove-signatures]
|
||||
::
|
||||
@ -421,7 +333,7 @@
|
||||
::
|
||||
++ node
|
||||
%- ot
|
||||
:~ [%post post]
|
||||
:~ [%post maybe-post]
|
||||
[%children internal-graph]
|
||||
==
|
||||
::
|
||||
@ -432,6 +344,15 @@
|
||||
[%empty ~]
|
||||
[%graph (graph jon)]
|
||||
::
|
||||
++ maybe-post
|
||||
|= jon=json
|
||||
^- ^maybe-post
|
||||
?~ jon !!
|
||||
?+ -.jon !!
|
||||
%s [%| (nu jon)]
|
||||
%o [%& (post jon)]
|
||||
==
|
||||
::
|
||||
++ post
|
||||
%- ot
|
||||
:~ [%author (su ;~(pfix sig fed:ag))]
|
||||
@ -488,9 +409,8 @@
|
||||
:~ expression+so
|
||||
output+tang
|
||||
==
|
||||
|
||||
::
|
||||
++ remove-nodes
|
||||
++ remove-posts
|
||||
%- ot
|
||||
:~ [%resource dejs:res]
|
||||
[%indices (as index)]
|
||||
@ -526,13 +446,13 @@
|
||||
++ add-tag
|
||||
%- ot
|
||||
:~ [%term so]
|
||||
[%resource dejs:res]
|
||||
[%uid uid]
|
||||
==
|
||||
::
|
||||
++ remove-tag
|
||||
%- ot
|
||||
:~ [%term so]
|
||||
[%resource dejs:res]
|
||||
[%uid uid]
|
||||
==
|
||||
::
|
||||
++ keys
|
||||
@ -567,4 +487,391 @@
|
||||
*signatures
|
||||
==
|
||||
--
|
||||
::
|
||||
++ upgrade
|
||||
|%
|
||||
::
|
||||
:: +two
|
||||
::
|
||||
++ marked-graph-to-two
|
||||
|= [=graph:one m=(unit mark)]
|
||||
[(graph-to-two graph) m]
|
||||
::
|
||||
++ graph-to-two
|
||||
|= =graph:one
|
||||
(graph:(upgrade ,post:one ,maybe-post) graph post-to-two)
|
||||
::
|
||||
++ post-to-two
|
||||
|= p=post:one
|
||||
^- maybe-post
|
||||
[%& p]
|
||||
::
|
||||
::
|
||||
:: +one
|
||||
::
|
||||
++ update-log-to-one
|
||||
|= =update-log:zero
|
||||
^- update-log:one
|
||||
%+ gas:orm-log:one *update-log:one
|
||||
%+ turn (tap:orm-log:zero update-log)
|
||||
|= [=time =logged-update:zero]
|
||||
^- [^time logged-update:one]
|
||||
:- time
|
||||
:- p.logged-update
|
||||
(logged-update-to-one q.logged-update)
|
||||
::
|
||||
++ logged-update-to-one
|
||||
|= upd=logged-update-0:zero
|
||||
^- logged-action:one
|
||||
?+ -.upd upd
|
||||
%add-graph upd(graph (graph-to-one graph.upd))
|
||||
%add-nodes upd(nodes (~(run by nodes.upd) node-to-one))
|
||||
==
|
||||
::
|
||||
++ node-to-one
|
||||
|= =node:zero
|
||||
(node:(upgrade ,post:zero ,post) node post-to-one)
|
||||
::
|
||||
++ graph-to-one
|
||||
|= =graph:zero
|
||||
(graph:(upgrade ,post:zero ,post) graph post-to-one)
|
||||
::
|
||||
++ marked-graph-to-one
|
||||
|= [=graph:zero m=(unit mark)]
|
||||
[(graph-to-one graph) m]
|
||||
::
|
||||
++ post-to-one
|
||||
|= p=post:zero
|
||||
^- post
|
||||
p(contents (contents-to-one contents.p))
|
||||
::
|
||||
++ contents-to-one
|
||||
|= cs=(list content:zero)
|
||||
^- (list content)
|
||||
%+ murn cs
|
||||
|= =content:zero
|
||||
^- (unit ^content)
|
||||
?: ?=(%reference -.content) ~
|
||||
`content
|
||||
::
|
||||
++ upgrade
|
||||
|* [in-pst=mold out-pst=mold]
|
||||
=>
|
||||
|%
|
||||
++ in-orm
|
||||
((ordered-map atom in-node) gth)
|
||||
+$ in-node
|
||||
[post=in-pst children=in-internal-graph]
|
||||
+$ in-graph
|
||||
((mop atom in-node) gth)
|
||||
+$ in-internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=in-graph]
|
||||
[%empty ~]
|
||||
==
|
||||
::
|
||||
++ out-orm
|
||||
((ordered-map atom out-node) gth)
|
||||
+$ out-node
|
||||
[post=out-pst children=out-internal-graph]
|
||||
+$ out-graph
|
||||
((mop atom out-node) gth)
|
||||
+$ out-internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=out-graph]
|
||||
[%empty ~]
|
||||
==
|
||||
--
|
||||
|%
|
||||
::
|
||||
++ graph
|
||||
|= $: gra=in-graph
|
||||
fn=$-(in-pst out-pst)
|
||||
==
|
||||
^- out-graph
|
||||
%+ gas:out-orm *out-graph
|
||||
^- (list [atom out-node])
|
||||
%+ turn (tap:in-orm gra)
|
||||
|= [a=atom n=in-node]
|
||||
^- [atom out-node]
|
||||
[a (node n fn)]
|
||||
::
|
||||
++ node
|
||||
|= [nod=in-node fn=$-(in-pst out-pst)]
|
||||
^- out-node
|
||||
:- (fn post.nod)
|
||||
^- out-internal-graph
|
||||
?: ?=(%empty -.children.nod)
|
||||
[%empty ~]
|
||||
[%graph (graph p.children.nod fn)]
|
||||
--
|
||||
::
|
||||
++ zero-load
|
||||
:: =* infinitely recurses
|
||||
=, store=zero
|
||||
=, orm=orm:zero
|
||||
=, orm-log=orm-log:zero
|
||||
|%
|
||||
++ change-revision-graph
|
||||
|= [=graph:store q=(unit mark)]
|
||||
^- [graph:store (unit mark)]
|
||||
|^
|
||||
:_ q
|
||||
?+ q graph
|
||||
[~ %graph-validator-link] convert-links
|
||||
[~ %graph-validator-publish] convert-publish
|
||||
==
|
||||
::
|
||||
++ convert-links
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm graph)
|
||||
|= [=atom =node:store]
|
||||
^- [^atom node:store]
|
||||
:: top-level
|
||||
::
|
||||
:+ atom post.node
|
||||
?: ?=(%empty -.children.node)
|
||||
[%empty ~]
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm p.children.node)
|
||||
|= [=^atom =node:store]
|
||||
^- [^^atom node:store]
|
||||
:: existing comments get turned into containers for revisions
|
||||
::
|
||||
:^ atom
|
||||
post.node(contents ~, hash ~)
|
||||
%graph
|
||||
%+ gas:orm *graph:store
|
||||
:_ ~ :- %0
|
||||
:_ [%empty ~]
|
||||
post.node(index (snoc index.post.node atom), hash ~)
|
||||
::
|
||||
++ convert-publish
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm graph)
|
||||
|= [=atom =node:store]
|
||||
^- [^atom node:store]
|
||||
:: top-level
|
||||
::
|
||||
:+ atom post.node
|
||||
?: ?=(%empty -.children.node)
|
||||
[%empty ~]
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm p.children.node)
|
||||
|= [=^atom =node:store]
|
||||
^- [^^atom node:store]
|
||||
:: existing container for publish note revisions
|
||||
::
|
||||
?+ atom !!
|
||||
%1 [atom node]
|
||||
%2
|
||||
:+ atom post.node
|
||||
?: ?=(%empty -.children.node)
|
||||
[%empty ~]
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn (tap:orm p.children.node)
|
||||
|= [=^^atom =node:store]
|
||||
^- [^^^atom node:store]
|
||||
:+ atom post.node(contents ~, hash ~)
|
||||
:- %graph
|
||||
%+ gas:orm *graph:store
|
||||
:_ ~ :- %1
|
||||
:_ [%empty ~]
|
||||
post.node(index (snoc index.post.node atom), hash ~)
|
||||
==
|
||||
--
|
||||
::
|
||||
++ maybe-unix-to-da
|
||||
|= =atom
|
||||
^- @
|
||||
:: (bex 127) is roughly 226AD
|
||||
?. (lte atom (bex 127))
|
||||
atom
|
||||
(add ~1970.1.1 (div (mul ~s1 atom) 1.000))
|
||||
::
|
||||
++ convert-unix-timestamped-node
|
||||
|= =node:store
|
||||
^- node:store
|
||||
=. index.post.node
|
||||
(convert-unix-timestamped-index index.post.node)
|
||||
?. ?=(%graph -.children.node)
|
||||
node
|
||||
:+ post.node
|
||||
%graph
|
||||
(convert-unix-timestamped-graph p.children.node)
|
||||
::
|
||||
++ convert-unix-timestamped-index
|
||||
|= =index:store
|
||||
(turn index maybe-unix-to-da)
|
||||
::
|
||||
++ convert-unix-timestamped-graph
|
||||
|= =graph:store
|
||||
%+ gas:orm *graph:store
|
||||
%+ turn
|
||||
(tap:orm graph)
|
||||
|= [=atom =node:store]
|
||||
^- [^atom node:store]
|
||||
:- (maybe-unix-to-da atom)
|
||||
(convert-unix-timestamped-node node)
|
||||
--
|
||||
--
|
||||
++ import
|
||||
|= [arc=* our=ship]
|
||||
^- (quip card:agent:gall [%5 network])
|
||||
|^
|
||||
=/ sty [%5 (remake-network ;;(tree-network +.arc))]
|
||||
:_ sty
|
||||
%+ turn ~(tap by graphs.sty)
|
||||
|= [rid=resource =marked-graph]
|
||||
^- card:agent:gall
|
||||
?: =(our entity.rid)
|
||||
=/ =cage [%push-hook-action !>([%add rid])]
|
||||
[%pass / %agent [our %graph-push-hook] %poke cage]
|
||||
(try-rejoin rid 0)
|
||||
::
|
||||
+$ tree-network
|
||||
$: graphs=tree-graphs
|
||||
tag-queries=(tree [term (tree uid)])
|
||||
update-logs=tree-update-logs
|
||||
archive=tree-graphs
|
||||
~
|
||||
==
|
||||
+$ tree-graphs (tree [resource tree-marked-graph])
|
||||
+$ tree-marked-graph [p=tree-graph q=(unit ^mark)]
|
||||
+$ tree-graph (tree [atom tree-node])
|
||||
+$ tree-node [post=tree-maybe-post children=tree-internal-graph]
|
||||
+$ tree-internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=tree-graph]
|
||||
[%empty ~]
|
||||
==
|
||||
+$ tree-update-logs (tree [resource tree-update-log])
|
||||
+$ tree-update-log (tree [time tree-logged-update])
|
||||
+$ tree-logged-update
|
||||
$: p=time
|
||||
$= q
|
||||
$% [%add-graph =resource =tree-graph mark=(unit ^mark) ow=?]
|
||||
[%add-nodes =resource nodes=(tree [index tree-node])]
|
||||
[%remove-posts =resource indices=(tree index)]
|
||||
[%add-signatures =uid signatures=tree-signatures]
|
||||
[%remove-signatures =uid signatures=tree-signatures]
|
||||
==
|
||||
==
|
||||
+$ tree-signatures (tree signature)
|
||||
+$ tree-maybe-post (each tree-post hash)
|
||||
+$ tree-post
|
||||
$: author=ship
|
||||
=index
|
||||
time-sent=time
|
||||
contents=(list content)
|
||||
hash=(unit hash)
|
||||
signatures=tree-signatures
|
||||
==
|
||||
::
|
||||
++ remake-network
|
||||
|= t=tree-network
|
||||
^- network
|
||||
:* (remake-graphs graphs.t)
|
||||
(remake-jug:migrate tag-queries.t)
|
||||
(remake-update-logs update-logs.t)
|
||||
(remake-graphs archive.t)
|
||||
~
|
||||
==
|
||||
::
|
||||
++ remake-graphs
|
||||
|= t=tree-graphs
|
||||
^- graphs
|
||||
%- remake-map:migrate
|
||||
(~(run by t) remake-marked-graph)
|
||||
::
|
||||
++ remake-marked-graph
|
||||
|= t=tree-marked-graph
|
||||
^- marked-graph
|
||||
[(remake-graph p.t) q.t]
|
||||
::
|
||||
++ remake-graph
|
||||
|= t=tree-graph
|
||||
^- graph
|
||||
%+ gas:orm *graph
|
||||
%+ turn ~(tap by t)
|
||||
|= [a=atom tn=tree-node]
|
||||
^- [atom node]
|
||||
[a (remake-node tn)]
|
||||
::
|
||||
++ remake-internal-graph
|
||||
|= t=tree-internal-graph
|
||||
^- internal-graph
|
||||
?: ?=(%empty -.t)
|
||||
[%empty ~]
|
||||
[%graph (remake-graph p.t)]
|
||||
::
|
||||
++ remake-node
|
||||
|= t=tree-node
|
||||
^- node
|
||||
:- (remake-post post.t)
|
||||
(remake-internal-graph children.t)
|
||||
::
|
||||
++ remake-update-logs
|
||||
|= t=tree-update-logs
|
||||
^- update-logs
|
||||
%- remake-map:migrate
|
||||
(~(run by t) remake-update-log)
|
||||
::
|
||||
++ remake-update-log
|
||||
|= t=tree-update-log
|
||||
^- update-log
|
||||
=/ ulm ((ordered-map time logged-update) gth)
|
||||
%+ gas:ulm *update-log
|
||||
%+ turn ~(tap by t)
|
||||
|= [=time tlu=tree-logged-update]
|
||||
^- [^time logged-update]
|
||||
[time (remake-logged-update tlu)]
|
||||
::
|
||||
++ remake-logged-update
|
||||
|= t=tree-logged-update
|
||||
^- logged-update
|
||||
:- p.t
|
||||
?- -.q.t
|
||||
%add-graph
|
||||
:* %add-graph
|
||||
resource.q.t
|
||||
(remake-graph tree-graph.q.t)
|
||||
mark.q.t
|
||||
ow.q.t
|
||||
==
|
||||
::
|
||||
%add-nodes
|
||||
:- %add-nodes
|
||||
:- resource.q.t
|
||||
%- remake-map:migrate
|
||||
(~(run by nodes.q.t) remake-node)
|
||||
::
|
||||
%remove-posts
|
||||
[%remove-posts resource.q.t (remake-set:migrate indices.q.t)]
|
||||
::
|
||||
%add-signatures
|
||||
[%add-signatures uid.q.t (remake-set:migrate signatures.q.t)]
|
||||
::
|
||||
%remove-signatures
|
||||
[%remove-signatures uid.q.t (remake-set:migrate signatures.q.t)]
|
||||
==
|
||||
::
|
||||
++ remake-post
|
||||
|= t=tree-maybe-post
|
||||
^- maybe-post
|
||||
?- -.t
|
||||
%| t
|
||||
%& t(signatures.p (remake-set:migrate signatures.p.t))
|
||||
==
|
||||
::
|
||||
++ try-rejoin
|
||||
|= [rid=resource nack-count=@]
|
||||
^- card:agent:gall
|
||||
=/ res-path (en-path:res rid)
|
||||
=/ wire [%try-rejoin (scot %ud nack-count) res-path]
|
||||
[%pass wire %agent [entity.rid %graph-push-hook] %watch resource+res-path]
|
||||
--
|
||||
--
|
||||
|
@ -19,7 +19,7 @@
|
||||
%add-graph ~[resource.q.update]
|
||||
%remove-graph ~[resource.q.update]
|
||||
%add-nodes ~[resource.q.update]
|
||||
%remove-nodes ~[resource.q.update]
|
||||
%remove-posts ~[resource.q.update]
|
||||
%add-signatures ~[resource.uid.q.update]
|
||||
%remove-signatures ~[resource.uid.q.update]
|
||||
%archive-graph ~[resource.q.update]
|
||||
@ -76,6 +76,7 @@
|
||||
++ get-graph
|
||||
|= res=resource
|
||||
^- update:store
|
||||
=- -(p *time)
|
||||
%+ scry-for update:store
|
||||
/graph/(scot %p entity.res)/[name.res]
|
||||
::
|
||||
|
@ -90,7 +90,12 @@
|
||||
$: tracking=(map resource track)
|
||||
inner-state=vase
|
||||
==
|
||||
|
||||
::
|
||||
+$ base-state-3
|
||||
$: prev-version=@ud
|
||||
prev-min-version=@ud
|
||||
base-state-2
|
||||
==
|
||||
::
|
||||
+$ state-0 [%0 base-state-0]
|
||||
::
|
||||
@ -100,11 +105,14 @@
|
||||
::
|
||||
+$ state-3 [%3 base-state-2]
|
||||
::
|
||||
+$ state-4 [%4 base-state-3]
|
||||
::
|
||||
+$ versioned-state
|
||||
$% state-0
|
||||
state-1
|
||||
state-2
|
||||
state-3
|
||||
state-4
|
||||
==
|
||||
::
|
||||
++ default
|
||||
@ -198,7 +206,7 @@
|
||||
++ agent
|
||||
|* =config
|
||||
|= =(pull-hook config)
|
||||
=| state-3
|
||||
=| state-4
|
||||
=* state -
|
||||
^- agent:gall
|
||||
=<
|
||||
@ -224,13 +232,20 @@
|
||||
=| cards=(list card:agent:gall)
|
||||
|^
|
||||
?- -.old
|
||||
%3
|
||||
%4
|
||||
=^ og-cards pull-hook
|
||||
(on-load:og inner-state.old)
|
||||
=. state old
|
||||
=/ kick=(list card)
|
||||
?: ?& =(min-version.config prev-min-version.old)
|
||||
=(version.config prev-version.old)
|
||||
==
|
||||
~
|
||||
(poke-self:pass kick+!>(%kick))^~
|
||||
:_ this
|
||||
:(weld cards og-cards (poke-self:pass kick+!>(%kick))^~)
|
||||
:(weld cards og-cards kick)
|
||||
::
|
||||
%3 $(old [%4 0 0 +.old])
|
||||
%2 $(old (state-to-3 old))
|
||||
%1 $(old [%2 +.old ~])
|
||||
%0 !! :: pre-breach
|
||||
@ -255,8 +270,10 @@
|
||||
::
|
||||
++ on-save
|
||||
^- vase
|
||||
=. inner-state
|
||||
on-save:og
|
||||
=: inner-state on-save:og
|
||||
prev-min-version min-version.config
|
||||
prev-version version.config
|
||||
==
|
||||
!>(state)
|
||||
::
|
||||
++ on-poke
|
||||
@ -472,6 +489,7 @@
|
||||
::
|
||||
++ tr-add
|
||||
|= [s=^ship r=resource]
|
||||
?< =(s our.bowl)
|
||||
=: ship s
|
||||
rid r
|
||||
status [%active ~]
|
||||
|
@ -57,13 +57,21 @@
|
||||
inner-state=vase
|
||||
==
|
||||
::
|
||||
+$ base-state-1
|
||||
$: prev-version=@ud
|
||||
prev-min-version=@ud
|
||||
base-state-0
|
||||
==
|
||||
::
|
||||
+$ state-0 [%0 base-state-0]
|
||||
::
|
||||
+$ state-1 [%1 base-state-0]
|
||||
+$ state-2 [%2 base-state-1]
|
||||
::
|
||||
+$ versioned-state
|
||||
$% state-0
|
||||
state-1
|
||||
state-2
|
||||
==
|
||||
++ push-hook
|
||||
|* =config
|
||||
@ -153,7 +161,7 @@
|
||||
++ agent
|
||||
|* =config
|
||||
|= =(push-hook config)
|
||||
=| state-1
|
||||
=| state-2
|
||||
=* state -
|
||||
^- agent:gall
|
||||
=<
|
||||
@ -179,16 +187,21 @@
|
||||
=| cards=(list card:agent:gall)
|
||||
|^
|
||||
?- -.old
|
||||
%1
|
||||
%2
|
||||
=^ og-cards push-hook
|
||||
(on-load:og inner-state.old)
|
||||
=/ old-subs
|
||||
find-old-subs
|
||||
(find-old-subs [prev-version prev-min-version]:old)
|
||||
=/ version-cards
|
||||
:- (fact:io version+!>(version.config) /version ~)
|
||||
?~ old-subs ~
|
||||
(kick:io old-subs)^~
|
||||
[:(weld cards og-cards version-cards) this(state old)]
|
||||
::
|
||||
%1
|
||||
%_ $
|
||||
old [%2 0 0 +.old]
|
||||
==
|
||||
::
|
||||
::
|
||||
%0
|
||||
@ -205,6 +218,12 @@
|
||||
==
|
||||
::
|
||||
++ find-old-subs
|
||||
|= [prev-min-version=@ud prev-version=@ud]
|
||||
?: ?& =(min-version.config prev-min-version)
|
||||
=(prev-version version.config)
|
||||
==
|
||||
:: bail on kick if we didn't change versions
|
||||
~
|
||||
%~ tap in
|
||||
%+ roll
|
||||
~(val by sup.bowl)
|
||||
@ -230,8 +249,10 @@
|
||||
--
|
||||
::
|
||||
++ on-save
|
||||
=. inner-state
|
||||
on-save:og
|
||||
=: prev-version version.config
|
||||
prev-min-version min-version.config
|
||||
inner-state on-save:og
|
||||
==
|
||||
!>(state)
|
||||
::
|
||||
++ on-poke
|
||||
|
@ -1,19 +1,17 @@
|
||||
/+ *graph-store
|
||||
=* as-octs as-octs:mimes:html
|
||||
::
|
||||
|_ upd=update
|
||||
|_ upd=update:one
|
||||
++ grad %noun
|
||||
++ grow
|
||||
|%
|
||||
++ noun upd
|
||||
++ json (update:enjs upd)
|
||||
++ mime [/application/x-urb-graph-update (as-octs (jam upd))]
|
||||
--
|
||||
::
|
||||
++ grab
|
||||
|%
|
||||
++ noun update
|
||||
++ json update:dejs
|
||||
++ noun update:one
|
||||
++ mime |=([* =octs] ;;(update (cue q.octs)))
|
||||
--
|
||||
--
|
||||
|
19
pkg/arvo/mar/graph/update-2.hoon
Normal file
19
pkg/arvo/mar/graph/update-2.hoon
Normal file
@ -0,0 +1,19 @@
|
||||
/+ *graph-store
|
||||
=* as-octs as-octs:mimes:html
|
||||
::
|
||||
|_ upd=update
|
||||
++ grad %noun
|
||||
++ grow
|
||||
|%
|
||||
++ noun upd
|
||||
++ json (update:enjs upd)
|
||||
++ mime [/application/x-urb-graph-update (as-octs (jam upd))]
|
||||
--
|
||||
::
|
||||
++ grab
|
||||
|%
|
||||
++ noun update
|
||||
++ json update:dejs
|
||||
++ mime |=([* =octs] ;;(update (cue q.octs)))
|
||||
--
|
||||
--
|
@ -1,5 +1,61 @@
|
||||
/- *post
|
||||
|%
|
||||
+$ graph ((mop atom node) gth)
|
||||
+$ marked-graph [p=graph q=(unit mark)]
|
||||
::
|
||||
+$ maybe-post (each post hash)
|
||||
+$ node [post=maybe-post children=internal-graph]
|
||||
+$ graphs (map resource marked-graph)
|
||||
::
|
||||
+$ tag-queries (jug term uid)
|
||||
::
|
||||
+$ update-log ((mop time logged-update) gth)
|
||||
+$ update-logs (map resource update-log)
|
||||
::
|
||||
+$ internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=graph]
|
||||
[%empty ~]
|
||||
==
|
||||
::
|
||||
+$ network
|
||||
$: =graphs
|
||||
=tag-queries
|
||||
=update-logs
|
||||
archive=graphs
|
||||
~
|
||||
==
|
||||
::
|
||||
+$ update [p=time q=action]
|
||||
::
|
||||
+$ logged-update [p=time q=logged-action]
|
||||
|
||||
::
|
||||
+$ logged-action
|
||||
$% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
|
||||
[%add-nodes =resource nodes=(map index node)]
|
||||
[%remove-posts =resource indices=(set index)]
|
||||
[%add-signatures =uid =signatures]
|
||||
[%remove-signatures =uid =signatures]
|
||||
==
|
||||
::
|
||||
+$ action
|
||||
$% logged-action
|
||||
[%remove-graph =resource]
|
||||
::
|
||||
[%add-tag =term =uid]
|
||||
[%remove-tag =term =uid]
|
||||
::
|
||||
[%archive-graph =resource]
|
||||
[%unarchive-graph =resource]
|
||||
[%run-updates =resource =update-log]
|
||||
::
|
||||
:: NOTE: cannot be sent as pokes
|
||||
::
|
||||
[%keys =resources]
|
||||
[%tags tags=(set term)]
|
||||
[%tag-queries =tag-queries]
|
||||
==
|
||||
::
|
||||
+$ permissions
|
||||
[admin=permission-level writer=permission-level reader=permission-level]
|
||||
@ -13,11 +69,75 @@
|
||||
+$ permission-level
|
||||
?(%no %self %yes)
|
||||
::
|
||||
:: %graph-store types version 1
|
||||
::
|
||||
++ one
|
||||
|%
|
||||
++ orm ((ordered-map atom node) gth)
|
||||
++ orm-log ((ordered-map time logged-update) gth)
|
||||
::
|
||||
+$ graph ((mop atom node) gth)
|
||||
+$ marked-graph [p=graph q=(unit mark)]
|
||||
::
|
||||
+$ node [=post children=internal-graph]
|
||||
+$ graphs (map resource marked-graph)
|
||||
::
|
||||
+$ tag-queries (jug term resource)
|
||||
::
|
||||
+$ update-log ((mop time logged-update) gth)
|
||||
+$ update-logs (map resource update-log)
|
||||
::
|
||||
+$ internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=graph]
|
||||
[%empty ~]
|
||||
==
|
||||
::
|
||||
+$ network
|
||||
$: =graphs
|
||||
=tag-queries
|
||||
=update-logs
|
||||
archive=graphs
|
||||
validators=(set mark)
|
||||
==
|
||||
::
|
||||
+$ update [p=time q=action]
|
||||
::
|
||||
+$ logged-update [p=time q=logged-action]
|
||||
::
|
||||
+$ logged-action
|
||||
$% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
|
||||
[%add-nodes =resource nodes=(map index node)]
|
||||
[%remove-nodes =resource indices=(set index)]
|
||||
[%add-signatures =uid =signatures]
|
||||
[%remove-signatures =uid =signatures]
|
||||
==
|
||||
::
|
||||
+$ action
|
||||
$% logged-action
|
||||
[%remove-graph =resource]
|
||||
::
|
||||
[%add-tag =term =resource]
|
||||
[%remove-tag =term =resource]
|
||||
::
|
||||
[%archive-graph =resource]
|
||||
[%unarchive-graph =resource]
|
||||
[%run-updates =resource =update-log]
|
||||
::
|
||||
:: NOTE: cannot be sent as pokes
|
||||
::
|
||||
[%keys =resources]
|
||||
[%tags tags=(set term)]
|
||||
[%tag-queries =tag-queries]
|
||||
==
|
||||
--
|
||||
::
|
||||
:: %graph-store types version 0
|
||||
::
|
||||
++ zero
|
||||
=< [. post-zero]
|
||||
=, post-zero
|
||||
|%
|
||||
::
|
||||
++ orm ((ordered-map atom node) gth)
|
||||
++ orm-log ((ordered-map time logged-update) gth)
|
||||
::
|
||||
@ -81,61 +201,4 @@
|
||||
[%tag-queries =tag-queries]
|
||||
==
|
||||
--
|
||||
|
||||
+$ graph ((mop atom node) gth)
|
||||
+$ marked-graph [p=graph q=(unit mark)]
|
||||
::
|
||||
+$ node [=post children=internal-graph]
|
||||
+$ graphs (map resource marked-graph)
|
||||
::
|
||||
+$ tag-queries (jug term resource)
|
||||
::
|
||||
+$ update-log ((mop time logged-update) gth)
|
||||
+$ update-logs (map resource update-log)
|
||||
::
|
||||
::
|
||||
+$ internal-graph
|
||||
$~ [%empty ~]
|
||||
$% [%graph p=graph]
|
||||
[%empty ~]
|
||||
==
|
||||
::
|
||||
+$ network
|
||||
$: =graphs
|
||||
=tag-queries
|
||||
=update-logs
|
||||
archive=graphs
|
||||
validators=(set mark)
|
||||
==
|
||||
::
|
||||
+$ update [p=time q=action]
|
||||
::
|
||||
+$ logged-update [p=time q=logged-action]
|
||||
|
||||
::
|
||||
+$ logged-action
|
||||
$% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
|
||||
[%add-nodes =resource nodes=(map index node)]
|
||||
[%remove-nodes =resource indices=(set index)]
|
||||
[%add-signatures =uid =signatures]
|
||||
[%remove-signatures =uid =signatures]
|
||||
==
|
||||
::
|
||||
+$ action
|
||||
$% logged-action
|
||||
[%remove-graph =resource]
|
||||
::
|
||||
[%add-tag =term =resource]
|
||||
[%remove-tag =term =resource]
|
||||
::
|
||||
[%archive-graph =resource]
|
||||
[%unarchive-graph =resource]
|
||||
[%run-updates =resource =update-log]
|
||||
::
|
||||
:: NOTE: cannot be sent as pokes
|
||||
::
|
||||
[%keys =resources]
|
||||
[%tags tags=(set term)]
|
||||
[%tag-queries =tag-queries]
|
||||
==
|
||||
--
|
||||
|
@ -1,27 +1,5 @@
|
||||
/- *resource
|
||||
|%
|
||||
::
|
||||
++ post-zero
|
||||
|%
|
||||
::
|
||||
+$ content
|
||||
$% [%text text=cord]
|
||||
[%mention =ship]
|
||||
[%url url=cord]
|
||||
[%code expression=cord output=(list tank)]
|
||||
[%reference =uid]
|
||||
==
|
||||
::
|
||||
+$ post
|
||||
$: author=ship
|
||||
=index
|
||||
time-sent=time
|
||||
contents=(list content)
|
||||
hash=(unit hash)
|
||||
=signatures
|
||||
==
|
||||
--
|
||||
|
||||
+$ index (list atom)
|
||||
+$ uid [=resource =index]
|
||||
::
|
||||
@ -60,4 +38,25 @@
|
||||
[%code expression=cord output=(list tank)]
|
||||
[%reference =reference]
|
||||
==
|
||||
::
|
||||
++ post-zero
|
||||
|%
|
||||
::
|
||||
+$ content
|
||||
$% [%text text=cord]
|
||||
[%mention =ship]
|
||||
[%url url=cord]
|
||||
[%code expression=cord output=(list tank)]
|
||||
[%reference =uid]
|
||||
==
|
||||
::
|
||||
+$ post
|
||||
$: author=ship
|
||||
=index
|
||||
time-sent=time
|
||||
contents=(list content)
|
||||
hash=(unit hash)
|
||||
=signatures
|
||||
==
|
||||
--
|
||||
--
|
||||
|
@ -32,7 +32,7 @@
|
||||
=/ hashes (nodes-to-pending-indices nodes.q.update)
|
||||
;< ~ bind:m
|
||||
%^ poke-our %graph-push-hook
|
||||
%graph-update-1
|
||||
%graph-update-2
|
||||
!>(update)
|
||||
(pure:m !>(`action:graph-view`[%pending-indices hashes]))
|
||||
::
|
||||
@ -75,7 +75,8 @@
|
||||
^- [index:store node:store]
|
||||
=* loop $
|
||||
:- index
|
||||
=* p post.node
|
||||
?> ?=(%& -.post.node)
|
||||
=* p p.post.node
|
||||
=/ =hash:store
|
||||
=- `@ux`(sham -)
|
||||
:^ ?^ parent-hash
|
||||
@ -85,9 +86,9 @@
|
||||
time-sent.p
|
||||
contents.p
|
||||
%_ node
|
||||
hash.post `hash
|
||||
hash.p.post `hash
|
||||
::
|
||||
signatures.post
|
||||
signatures.p.post
|
||||
%- ~(gas in *signatures:store)
|
||||
[(sign:sig our.bowl now.bowl hash)]~
|
||||
::
|
||||
@ -115,7 +116,8 @@
|
||||
?: ?=([@ ~] index)
|
||||
~
|
||||
=/ node (got-deep:gra graph (snip `(list atom)`index))
|
||||
hash.post.node
|
||||
?> ?=(%& -.post.node)
|
||||
hash.p.post.node
|
||||
::
|
||||
++ nodes-to-pending-indices
|
||||
|= nodes=(map index:store node:store)
|
||||
@ -124,6 +126,7 @@
|
||||
%+ turn ~(tap by nodes)
|
||||
|= [=index:store =node:store]
|
||||
^- [hash:store index:store]
|
||||
?> ?=(^ hash.post.node)
|
||||
[u.hash.post.node index]
|
||||
?> ?=(%& -.post.node)
|
||||
?> ?=(^ hash.p.post.node)
|
||||
[u.hash.p.post.node index]
|
||||
--
|
||||
|
@ -39,7 +39,7 @@
|
||||
==
|
||||
;< ~ bind:m
|
||||
%+ poke-our %graph-store
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
!> ^- update:graph
|
||||
[now.bowl %add-graph feed-rid *graph:graph `%graph-validator-post %&]
|
||||
;< ~ bind:m
|
||||
|
@ -54,7 +54,7 @@
|
||||
=/ =update:graph
|
||||
[now.bowl %add-graph rid.action *graph:graph mark.action overwrite]
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-store graph-update-1+!>(update))
|
||||
(poke-our %graph-store graph-update-2+!>(update))
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-push-hook %push-hook-action !>([%add rid.action]))
|
||||
::
|
||||
|
@ -36,7 +36,7 @@
|
||||
^- form:m
|
||||
;< =bowl:spider bind:m get-bowl:strandio
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-store %graph-update-1 !>([now.bowl %remove-graph rid]))
|
||||
(poke-our %graph-store %graph-update-2 !>([now.bowl %remove-graph rid]))
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-push-hook %push-hook-action !>([%remove rid]))
|
||||
;< ~ bind:m
|
||||
|
@ -40,7 +40,7 @@
|
||||
?: ?=([~ ^] feed.config.metadatum)
|
||||
;< ~ bind:m
|
||||
%+ poke-our %graph-store
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
!> ^- update:graph
|
||||
[now.bowl [%archive-graph resource.u.u.feed.config.metadatum]]
|
||||
(pure:m !>(~))
|
||||
|
@ -39,7 +39,7 @@
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-pull-hook %pull-hook-action !>([%remove rid]))
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-store %graph-update-1 !>([now [%remove-graph rid]]))
|
||||
(poke-our %graph-store %graph-update-2 !>([now [%remove-graph rid]]))
|
||||
(pure:m ~)
|
||||
--
|
||||
::
|
||||
|
@ -17,7 +17,7 @@
|
||||
;< =bowl:spider bind:m get-bowl:strandio
|
||||
:: unarchive graph and share it
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-store %graph-update-1 !>([now.bowl %unarchive-graph rid]))
|
||||
(poke-our %graph-store %graph-update-2 !>([now.bowl %unarchive-graph rid]))
|
||||
;< ~ bind:m
|
||||
(poke-our %graph-push-hook %push-hook-action !>([%add rid]))
|
||||
::
|
||||
|
@ -70,7 +70,7 @@
|
||||
;< ~ bind:m
|
||||
%+ raw-poke
|
||||
[our.bowl %graph-store]
|
||||
:- %graph-update-1
|
||||
:- %graph-update-2
|
||||
!> ^- update:gra
|
||||
[now.bowl [%archive-graph app-resource]]
|
||||
;< ~ bind:m
|
||||
|
@ -12,9 +12,9 @@
|
||||
|= [our=@p wen=@da rid=resource body=cord id=@]
|
||||
=/ =index:post [id]~
|
||||
=/ =post:post [our index wen [%text body]~ ~ ~]
|
||||
=/ =node:graph-store [post %empty ~]
|
||||
=/ =node:graph-store [[%& post] %empty ~]
|
||||
=/ act=update:graph-store [wen %add-nodes rid (my [index node] ~)]
|
||||
(poke-app our %graph-push-hook %graph-update-1 act)
|
||||
(poke-app our %graph-push-hook %graph-update-2 act)
|
||||
--
|
||||
::
|
||||
^- thread:spider
|
||||
|
@ -12,9 +12,9 @@
|
||||
|= [our=@p wen=@da rid=resource body=cord id=@]
|
||||
=/ =index:post [id]~
|
||||
=/ =post:post [our index wen [%text body]~ ~ ~]
|
||||
=/ =node:graph-store [post %empty ~]
|
||||
=/ =node:graph-store [[%& post] %empty ~]
|
||||
=/ act=update:graph-store [wen %add-nodes rid (my [index node] ~)]
|
||||
(poke-app our %graph-push-hook %graph-update-1 act)
|
||||
(poke-app our %graph-push-hook %graph-update-2 act)
|
||||
--
|
||||
::
|
||||
^- thread:spider
|
||||
|
@ -25,12 +25,13 @@ The first two options result in Urbit attempting to boot either the ship named b
|
||||
In consequence, it is safe to remove the container and start a new container which mounts the same volume, e.g. to upgrade the version of the urbit binary by running a later container version. It is also possible to stop the container and then move the pier away e.g. to a location where you will run it directly with the Urbit binary.
|
||||
|
||||
### Ports
|
||||
The image includes `EXPOSE` directives for TCP port 80 and UDP port 34343. Port `80` is used for Urbit's HTTP interface for both [Landscape](https://urbit.org/docs/glossary/landscape/) and for [API calls](https://urbit.org/using/integrating-api/) to the ship. Port `34343` is used by [Ames](https://urbit.org/docs/glossary/ames/) for ship-to-ship communication.
|
||||
The image includes `EXPOSE` directives for TCP port 80 and UDP port 34343. Port `80` is used for Urbit's HTTP interface for both [Landscape](https://urbit.org/docs/glossary/landscape/) and for [API calls](https://urbit.org/using/integrating-api/) to the ship. Port `34343` is set by default to be used by [Ames](https://urbit.org/docs/glossary/ames/) for ship-to-ship communication.
|
||||
|
||||
You can either pass the `-P` flag to docker to map ports directly to the corresponding ports on the host, or map them individually with `-p` flags. For local testing the latter is often convenient, for instance to remap port 80 to an unprivileged port.
|
||||
You can either pass the `-P` flag to docker to map ports directly to the corresponding ports on the host, or map them individually with `-p` flags. For local testing the latter is often convenient, for instance to remap port 80 to an unprivileged port.
|
||||
|
||||
You should be able to use port mapping for most purposes but you can force Ames to use a custom port.
|
||||
`--port=$AMES_PORT` can be passed as an argument to the `docker start` command. Passing `--port=13436` for example, would use port 13436.
|
||||
For best performance, you must map the Ames UDP port to the *same* port on the host. If you map to a different port Ames will not be able to make direct connections and your network performance may suffer somewhat. Note that using the same port is required for direct connections but is not by itself sufficient for them. If you are behind a NAT router or the host is not on a public IP address or you are firewalled, you may not achive direct connections regardless.
|
||||
|
||||
For this purpose you can force Ames to use a custom port. `/bin/start-urbit --port=$AMES_PORT` can be passed as an argument to the `docker start` command. Passing `/bin/start-urbit --port=13436` for example, would use port 13436. You must pass the name of the start script `/bin/start-urbit` in order to also pass arguments, if this is omitted your container will not start.
|
||||
|
||||
### Examples
|
||||
Creating a volume for ~sampel=palnet:
|
||||
@ -38,23 +39,23 @@ Creating a volume for ~sampel=palnet:
|
||||
docker volume create sampel-palnet
|
||||
```
|
||||
|
||||
Copying key to sampel-palnet's volume (assumes default docker location)
|
||||
Copying key to sampel-palnet's volume (assumes default docker location):
|
||||
```
|
||||
sudo cp ~/sampel-palnet.key /var/lib/docker/volumes/sampel-palnet/_data/sampel-palnet.key
|
||||
```
|
||||
|
||||
Using that volume and launching ~sampel-palnet on host port 8080 with Ames talking on host port 27000:
|
||||
Using that volume and launching ~sampel-palnet on host port 8080 with Ames talking on the default host port 34343:
|
||||
```
|
||||
docker run -d -p 8080:80 -p 27000:34343/udp --name sampel-palnet \
|
||||
docker run -d -p 8080:80 -p 34343:34343/udp --name sampel-palnet \
|
||||
--mount type=volume,source=sampel-palnet,destination=/urbit \
|
||||
tloncorp/urbit
|
||||
```
|
||||
|
||||
Using host port 8088 with Ames talking on host port 23232 while forcing Ames to start internally on port 13436:
|
||||
Using host port 8088 with Ames talking on host port 23232:
|
||||
```
|
||||
docker run -d -p 8088:80 -p 23232:13436/udp --name sampel-palnet \
|
||||
docker run -d -p 8088:80 -p 23232:23232/udp --name sampel-palnet \
|
||||
--mount type=volume,source=sampel-palnet,destination=/urbit \
|
||||
tloncorp/urbit --port=13436
|
||||
tloncorp/urbit /bin/start-urbit --port=23232
|
||||
```
|
||||
|
||||
### Getting and resetting the Landscape +code
|
||||
|
@ -25,10 +25,10 @@ module Urbit.Arvo.Common
|
||||
import Urbit.Prelude
|
||||
|
||||
import Control.Monad.Fail (fail)
|
||||
import Data.Bits
|
||||
import Data.Serialize
|
||||
|
||||
import qualified Network.HTTP.Types.Method as H
|
||||
import qualified Network.Socket as N
|
||||
import qualified Urbit.Ob as Ob
|
||||
|
||||
|
||||
@ -159,6 +159,19 @@ deriveNoun ''JsonNode
|
||||
|
||||
-- Ames Destinations -------------------------------------------------
|
||||
|
||||
serializeToNoun :: Serialize a => a -> Noun
|
||||
serializeToNoun = A . bytesAtom . encode
|
||||
|
||||
serializeParseNoun :: Serialize a => String -> Int -> Noun -> Parser a
|
||||
serializeParseNoun desc len = named (pack desc) . \case
|
||||
A (atomBytes -> bs)
|
||||
-- Atoms lose leading 0s, but since lsb, these become trailing NULs
|
||||
| length bs <= len -> case decode $ bs <> replicate (len - length bs) 0 of
|
||||
Right aa -> pure aa
|
||||
Left msg -> fail msg
|
||||
| otherwise -> fail ("putative " <> desc <> " " <> show bs <> " too long")
|
||||
C{} -> fail ("unexpected cell in " <> desc)
|
||||
|
||||
newtype Patp a = Patp { unPatp :: a }
|
||||
deriving newtype (Eq, Ord, Enum, Real, Integral, Num, ToNoun, FromNoun)
|
||||
|
||||
@ -167,17 +180,29 @@ newtype Port = Port { unPort :: Word16 }
|
||||
deriving newtype (Eq, Ord, Show, Enum, Real, Integral, Num, ToNoun, FromNoun)
|
||||
|
||||
-- @if
|
||||
newtype Ipv4 = Ipv4 { unIpv4 :: Word32 }
|
||||
deriving newtype (Eq, Ord, Enum, Real, Integral, Num, ToNoun, FromNoun)
|
||||
newtype Ipv4 = Ipv4 { unIpv4 :: N.HostAddress }
|
||||
deriving newtype (Eq, Ord, Enum)
|
||||
|
||||
instance Serialize Ipv4 where
|
||||
get = (\a b c d -> Ipv4 $ N.tupleToHostAddress $ (d, c, b, a))
|
||||
<$> getWord8 <*> getWord8 <*> getWord8 <*> getWord8
|
||||
put (Ipv4 (N.hostAddressToTuple -> (a, b, c, d))) = for_ [d, c, b, a] putWord8
|
||||
|
||||
instance ToNoun Ipv4 where
|
||||
toNoun = serializeToNoun
|
||||
|
||||
instance FromNoun Ipv4 where
|
||||
parseNoun = serializeParseNoun "Ipv4" 4
|
||||
|
||||
instance Show Ipv4 where
|
||||
show (Ipv4 i) =
|
||||
show ((shiftR i 24) .&. 0xff) ++ "." ++
|
||||
show ((shiftR i 16) .&. 0xff) ++ "." ++
|
||||
show ((shiftR i 8) .&. 0xff) ++ "." ++
|
||||
show (i .&. 0xff)
|
||||
show (Ipv4 (N.hostAddressToTuple -> (a, b, c, d))) =
|
||||
show a ++ "." ++
|
||||
show b ++ "." ++
|
||||
show c ++ "." ++
|
||||
show d
|
||||
|
||||
-- @is
|
||||
-- should probably use hostAddress6ToTuple here, but no one uses it right now
|
||||
newtype Ipv6 = Ipv6 { unIpv6 :: Word128 }
|
||||
deriving newtype (Eq, Ord, Show, Enum, Real, Integral, Num, ToNoun, FromNoun)
|
||||
|
||||
@ -190,21 +215,14 @@ data AmesAddress = AAIpv4 Ipv4 Port
|
||||
deriving (Eq, Ord, Show)
|
||||
|
||||
instance Serialize AmesAddress where
|
||||
get = AAIpv4 <$> (Ipv4 <$> getWord32le) <*> (Port <$> getWord16le)
|
||||
put (AAIpv4 (Ipv4 ip) (Port port)) = putWord32le ip >> putWord16le port
|
||||
get = AAIpv4 <$> get <*> (Port <$> getWord16le)
|
||||
put (AAIpv4 ip (Port port)) = put ip >> putWord16le port
|
||||
|
||||
instance FromNoun AmesAddress where
|
||||
parseNoun = named "AmesAddress" . \case
|
||||
A (atomBytes -> bs)
|
||||
-- Atoms lose leading 0s, but since lsb, these become trailing NULs
|
||||
| length bs <= 6 -> case decode $ bs <> replicate (6 - length bs) 0 of
|
||||
Right aa -> pure aa
|
||||
Left msg -> fail msg
|
||||
| otherwise -> fail ("putative address " <> show bs <> " too long")
|
||||
C{} -> fail "unexpected cell in ames address"
|
||||
parseNoun = serializeParseNoun "AmesAddress" 6
|
||||
|
||||
instance ToNoun AmesAddress where
|
||||
toNoun = A . bytesAtom . encode
|
||||
toNoun = serializeToNoun
|
||||
|
||||
type AmesDest = Each Galaxy AmesAddress
|
||||
|
||||
|
@ -80,10 +80,6 @@ data ShipClass
|
||||
muk :: ByteString -> Word20
|
||||
muk bs = mugBS bs .&. (2 ^ 20 - 1)
|
||||
|
||||
-- XX check this
|
||||
getAmesAddress :: Get AmesAddress
|
||||
getAmesAddress = AAIpv4 <$> (Ipv4 <$> getWord32le) <*> (Port <$> getWord16le)
|
||||
|
||||
putAmesAddress :: Putter AmesAddress
|
||||
putAmesAddress = \case
|
||||
AAIpv4 (Ipv4 ip) (Port port) -> putWord32le ip >> putWord16le port
|
||||
@ -104,7 +100,7 @@ instance Serialize Packet where
|
||||
guard isAmes
|
||||
|
||||
pktOrigin <- if isRelayed
|
||||
then Just <$> getAmesAddress
|
||||
then Just <$> get
|
||||
else pure Nothing
|
||||
|
||||
-- body
|
||||
@ -157,9 +153,10 @@ instance Serialize Packet where
|
||||
|
||||
putWord32le head
|
||||
case pktOrigin of
|
||||
Just o -> putAmesAddress o
|
||||
Just o -> put o
|
||||
Nothing -> pure ()
|
||||
putByteString body
|
||||
|
||||
where
|
||||
putShipGetRank s@(Ship (LargeKey p q)) = case () of
|
||||
_ | s < 2 ^ 16 -> (0, putWord16le $ fromIntegral s) -- lord
|
||||
|
@ -4,8 +4,12 @@
|
||||
1. Opens a UDP socket and makes sure that it stays open.
|
||||
|
||||
- If can't open the port, wait and try again repeatedly.
|
||||
- If there is an error reading or writting from the open socket,
|
||||
close it and open another.
|
||||
- If there is an error reading to or writing from the open socket,
|
||||
close it and open another, making sure, however, to reuse the
|
||||
same port
|
||||
NOTE: It's not clear what, if anything, closing and reopening
|
||||
the socket does. We're keeping this behavior out of conservatism
|
||||
until we understand it better.
|
||||
|
||||
2. Receives packets from the socket.
|
||||
|
||||
@ -158,7 +162,7 @@ realUdpServ
|
||||
-> HostAddress
|
||||
-> AmesStat
|
||||
-> RIO e UdpServ
|
||||
realUdpServ por hos sat = do
|
||||
realUdpServ startPort hos sat = do
|
||||
logInfo $ displayShow ("AMES", "UDP", "Starting real UDP server.")
|
||||
|
||||
env <- ask
|
||||
@ -202,23 +206,30 @@ realUdpServ por hos sat = do
|
||||
did <- atomically (tryWriteTBQueue qSend (a, b))
|
||||
when (did == False) $ do
|
||||
logWarn "AMES: UDP: Dropping outbound packet because queue is full."
|
||||
let opener por = do
|
||||
logInfo $ displayShow $ ("AMES", "UDP", "Trying to open socket, port",)
|
||||
por
|
||||
sk <- forceBind por hos
|
||||
sn <- io $ getSocketName sk
|
||||
sp <- io $ socketPort sk
|
||||
logInfo $ displayShow $ ("AMES", "UDP", "Got socket", sn, sp)
|
||||
|
||||
tOpen <- async $ forever $ do
|
||||
sk <- forceBind por hos
|
||||
sn <- io $ getSocketName sk
|
||||
let waitForRelease = do
|
||||
atomically (writeTVar vSock (Just sk))
|
||||
broken <- atomically (takeTMVar vFail)
|
||||
logWarn "AMES: UDP: Closing broken socket."
|
||||
io (close broken)
|
||||
|
||||
let waitForRelease = do
|
||||
atomically (writeTVar vSock (Just sk))
|
||||
broken <- atomically (takeTMVar vFail)
|
||||
logWarn "AMES: UDP: Closing broken socket."
|
||||
io (close broken)
|
||||
case sn of
|
||||
(SockAddrInet boundPort _) ->
|
||||
-- When we're on IPv4, maybe port forward at the NAT.
|
||||
rwith (requestPortAccess $ fromIntegral boundPort) $
|
||||
\() -> waitForRelease
|
||||
_ -> waitForRelease
|
||||
|
||||
case sn of
|
||||
(SockAddrInet boundPort _) ->
|
||||
-- When we're on IPv4, maybe port forward at the NAT.
|
||||
rwith (requestPortAccess $ fromIntegral boundPort) $
|
||||
\() -> waitForRelease
|
||||
_ -> waitForRelease
|
||||
opener sp
|
||||
|
||||
tOpen <- async $ opener startPort
|
||||
|
||||
tSend <- async $ forever $ join $ atomically $ do
|
||||
(adr, byt) <- readTBQueue qSend
|
||||
|
@ -37,12 +37,12 @@ textPlain = Path [(MkKnot "text"), (MkKnot "plain")]
|
||||
|
||||
-- | Filter for dotfiles, tempfiles and backup files.
|
||||
validClaySyncPath :: FilePath -> Bool
|
||||
validClaySyncPath fp = hasPeriod && notTildeFile && notDotHash && notDoubleHash
|
||||
validClaySyncPath fp = hasPeriod && notTildeFile && notDotFile && notDoubleHash
|
||||
where
|
||||
fileName = takeFileName fp
|
||||
hasPeriod = elem '.' fileName
|
||||
notTildeFile = not $ "~" `isSuffixOf` fileName
|
||||
notDotHash = not $ ".#" `isPrefixOf` fileName
|
||||
notDotFile = not $ "." `isPrefixOf` fileName
|
||||
notDoubleHash =
|
||||
not $ ("#" `isPrefixOf` fileName) && ("#" `isSuffixOf` fileName)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: urbit-king
|
||||
version: 1.3
|
||||
version: 1.5
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
data-files:
|
||||
|
@ -2,6 +2,7 @@ import BaseApi from './base';
|
||||
import { StoreState } from '../store/type';
|
||||
import { Patp } from '@urbit/api';
|
||||
import { ContactEdit } from '@urbit/api/contacts';
|
||||
import _ from 'lodash';
|
||||
|
||||
export default class ContactsApi extends BaseApi<StoreState> {
|
||||
add(ship: Patp, contact: any) {
|
||||
@ -73,6 +74,28 @@ export default class ContactsApi extends BaseApi<StoreState> {
|
||||
);
|
||||
}
|
||||
|
||||
async disallowedShipsForOurContact(ships: string[]): Promise<string[]> {
|
||||
return _.compact(
|
||||
await Promise.all(
|
||||
ships.map(
|
||||
async s => {
|
||||
const ship = `~${s}`;
|
||||
if(s === window.ship) {
|
||||
return null
|
||||
}
|
||||
const allowed = await this.fetchIsAllowed(
|
||||
`~${window.ship}`,
|
||||
'personal',
|
||||
ship,
|
||||
true
|
||||
)
|
||||
return allowed ? null : ship;
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
retrieve(ship: string) {
|
||||
const resource = { ship, name: '' };
|
||||
return this.action('contact-pull-hook', 'pull-hook-action', {
|
||||
|
@ -83,7 +83,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
joiningGraphs = new Set<string>();
|
||||
|
||||
private storeAction(action: any): Promise<any> {
|
||||
return this.action('graph-store', 'graph-update-1', action);
|
||||
return this.action('graph-store', 'graph-update-2', action);
|
||||
}
|
||||
|
||||
private viewAction(threadName: string, action: any) {
|
||||
@ -91,7 +91,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
private hookAction(ship: Patp, action: any): Promise<any> {
|
||||
return this.action('graph-push-hook', 'graph-update-1', action);
|
||||
return this.action('graph-push-hook', 'graph-update-2', action);
|
||||
}
|
||||
|
||||
createManagedGraph(
|
||||
@ -227,7 +227,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
};
|
||||
|
||||
const pendingPromise = this.spider(
|
||||
'graph-update-1',
|
||||
'graph-update-2',
|
||||
'graph-view-action',
|
||||
'graph-add-nodes',
|
||||
action
|
||||
@ -283,9 +283,9 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
|
||||
removeNodes(ship: Patp, name: string, indices: string[]) {
|
||||
removePosts(ship: Patp, name: string, indices: string[]) {
|
||||
return this.hookAction(ship, {
|
||||
'remove-nodes': {
|
||||
'remove-posts': {
|
||||
resource: { ship, name },
|
||||
indices
|
||||
}
|
||||
|
@ -99,9 +99,11 @@ export default function index(contacts, associations, apps, currentGroup, groups
|
||||
Object.keys(associations).filter((e) => {
|
||||
// skip apps with no metadata
|
||||
return Object.keys(associations[e]).length > 0;
|
||||
}).map((e) => {
|
||||
// iterate through each app's metadata object
|
||||
Object.keys(associations[e]).map((association) => {
|
||||
}).map((e) => {
|
||||
// iterate through each app's metadata object
|
||||
Object.keys(associations[e])
|
||||
.filter((association) => !associations?.[e]?.[association]?.metadata?.hidden)
|
||||
.map((association) => {
|
||||
const each = associations[e][association];
|
||||
let title = each.resource;
|
||||
if (each.metadata.title !== '') {
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
const ua = window.navigator.userAgent;
|
||||
|
||||
export const IS_IOS = ua.includes('iPhone');
|
||||
export const IS_IOS = ua.includes('iPhone') || ua.includes('iPad');
|
||||
|
||||
export const IS_SAFARI = ua.includes('Safari') && !ua.includes('Chrome');
|
||||
|
||||
|
@ -73,8 +73,8 @@ export function editPost(rev: number, noteId: BigInteger, title: string, body: s
|
||||
}
|
||||
|
||||
export function getLatestRevision(node: GraphNode): [number, string, string, Post] {
|
||||
const revs = node.children?.get(bigInt(1));
|
||||
const empty = [1, '', '', buntPost()] as [number, string, string, Post];
|
||||
const revs = node.children?.get(bigInt(1));
|
||||
if(!revs) {
|
||||
return empty;
|
||||
}
|
||||
|
@ -43,8 +43,8 @@ export function useVirtualResizeState(s: boolean) {
|
||||
[_setState, save]
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
restore();
|
||||
useEffect(() => {
|
||||
requestAnimationFrame(restore);
|
||||
}, [state]);
|
||||
|
||||
return [state, setState] as const;
|
||||
@ -58,7 +58,7 @@ export function useVirtualResizeProp(prop: Primitive) {
|
||||
save();
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
useEffect(() => {
|
||||
requestAnimationFrame(restore);
|
||||
}, [prop]);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import BigIntOrderedMap from "@urbit/api/lib/BigIntOrderedMap";
|
||||
import produce from 'immer';
|
||||
import bigInt, { BigInteger } from "big-integer";
|
||||
import useGraphState, { GraphState } from '../state/graph';
|
||||
import { reduceState } from '../state/base';
|
||||
@ -13,7 +14,7 @@ export const GraphReducer = (json) => {
|
||||
addGraph,
|
||||
removeGraph,
|
||||
addNodes,
|
||||
removeNodes
|
||||
removePosts
|
||||
]);
|
||||
}
|
||||
const loose = _.get(json, 'graph-update-loose', false);
|
||||
@ -51,23 +52,18 @@ const keys = (json, state: GraphState): GraphState => {
|
||||
const processNode = (node) => {
|
||||
// is empty
|
||||
if (!node.children) {
|
||||
node.children = new BigIntOrderedMap();
|
||||
return node;
|
||||
return produce(node, draft => {
|
||||
draft.children = new BigIntOrderedMap();
|
||||
});
|
||||
}
|
||||
|
||||
// is graph
|
||||
let converted = new BigIntOrderedMap();
|
||||
for (let idx in node.children) {
|
||||
let item = node.children[idx];
|
||||
let index = bigInt(idx);
|
||||
|
||||
converted.set(
|
||||
index,
|
||||
processNode(item)
|
||||
);
|
||||
}
|
||||
node.children = converted;
|
||||
return node;
|
||||
return produce(node, draft => {
|
||||
draft.children = new BigIntOrderedMap()
|
||||
.gas(_.map(draft.children, (item, idx) =>
|
||||
[bigInt(idx), processNode(item)] as [BigInteger, any]
|
||||
));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -85,17 +81,10 @@ const addGraph = (json, state: GraphState): GraphState => {
|
||||
state.graphTimesentMap[resource] = {};
|
||||
|
||||
|
||||
for (let idx in data.graph) {
|
||||
let item = data.graph[idx];
|
||||
let index = bigInt(idx);
|
||||
|
||||
let node = processNode(item);
|
||||
state.graphs[resource] = state.graphs[resource].gas(Object.keys(data.graph).map(idx => {
|
||||
return [bigInt(idx), processNode(data.graph[idx])];
|
||||
}));
|
||||
|
||||
state.graphs[resource].set(
|
||||
index,
|
||||
node
|
||||
);
|
||||
}
|
||||
state.graphKeys.add(resource);
|
||||
}
|
||||
return state;
|
||||
@ -116,7 +105,7 @@ const removeGraph = (json, state: GraphState): GraphState => {
|
||||
};
|
||||
|
||||
const mapifyChildren = (children) => {
|
||||
return new BigIntOrderedMap(
|
||||
return new BigIntOrderedMap().gas(
|
||||
_.map(children, (node, idx) => {
|
||||
idx = idx && idx.startsWith('/') ? idx.slice(1) : idx;
|
||||
const nd = {...node, children: mapifyChildren(node.children || {}) };
|
||||
@ -128,8 +117,7 @@ const addNodes = (json, state) => {
|
||||
const _addNode = (graph, index, node) => {
|
||||
// set child of graph
|
||||
if (index.length === 1) {
|
||||
graph.set(index[0], node);
|
||||
return graph;
|
||||
return graph.set(index[0], node);
|
||||
}
|
||||
|
||||
// set parent of graph
|
||||
@ -138,19 +126,20 @@ const addNodes = (json, state) => {
|
||||
console.error('parent node does not exist, cannot add child');
|
||||
return graph;
|
||||
}
|
||||
parNode.children = _addNode(parNode.children, index.slice(1), node);
|
||||
graph.set(index[0], parNode);
|
||||
return graph;
|
||||
return graph.set(index[0], produce(parNode, draft => {
|
||||
draft.children = _addNode(draft.children, index.slice(1), node);
|
||||
}));
|
||||
};
|
||||
|
||||
const _remove = (graph, index) => {
|
||||
if (index.length === 1) {
|
||||
graph.delete(index[0]);
|
||||
return graph.delete(index[0]);
|
||||
} else {
|
||||
const child = graph.get(index[0]);
|
||||
if (child) {
|
||||
child.children = _remove(child.children, index.slice(1));
|
||||
graph.set(index[0], child);
|
||||
return graph.set(index[0], produce(child, draft => {
|
||||
draft.children = _remove(draft.children, index.slice(1));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,10 +155,9 @@ const addNodes = (json, state) => {
|
||||
return bigInt(ind);
|
||||
});
|
||||
|
||||
graph = _remove(graph, indexArr);
|
||||
delete state.graphTimesentMap[resource][timestamp];
|
||||
return _remove(graph, indexArr);
|
||||
}
|
||||
|
||||
return graph;
|
||||
};
|
||||
|
||||
@ -181,7 +169,6 @@ const addNodes = (json, state) => {
|
||||
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent']);
|
||||
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'] - 1);
|
||||
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'] + 1);
|
||||
|
||||
return graph;
|
||||
};
|
||||
|
||||
@ -208,11 +195,12 @@ const addNodes = (json, state) => {
|
||||
return aArr.length - bArr.length;
|
||||
});
|
||||
|
||||
let graph = state.graphs[resource];
|
||||
|
||||
indices.forEach((index) => {
|
||||
let node = data.nodes[index];
|
||||
graph = _removePending(graph, node.post, resource);
|
||||
const old = state.graphs[resource].size;
|
||||
state.graphs[resource] = _removePending(state.graphs[resource], node.post, resource);
|
||||
const newSize = state.graphs[resource].size;
|
||||
|
||||
|
||||
if (index.split('/').length === 0) { return; }
|
||||
let indexArr = index.split('/').slice(1).map((ind) => {
|
||||
@ -225,35 +213,52 @@ const addNodes = (json, state) => {
|
||||
state.graphTimesentMap[resource][node.post['time-sent']] = index;
|
||||
}
|
||||
|
||||
node.children = mapifyChildren(node?.children || {});
|
||||
|
||||
|
||||
graph = _addNode(
|
||||
graph,
|
||||
state.graphs[resource] = _addNode(
|
||||
state.graphs[resource],
|
||||
indexArr,
|
||||
node
|
||||
produce(node, draft => {
|
||||
draft.children = mapifyChildren(draft?.children || {});
|
||||
})
|
||||
);
|
||||
if(newSize !== old) {
|
||||
console.log(`${resource}, (${old}, ${newSize}, ${state.graphs[resource].size})`);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
state.graphs[resource] = graph;
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
||||
const removeNodes = (json, state: GraphState): GraphState => {
|
||||
const removePosts = (json, state: GraphState): GraphState => {
|
||||
const _remove = (graph, index) => {
|
||||
const child = graph.get(index[0]);
|
||||
if (index.length === 1) {
|
||||
graph.delete(index[0]);
|
||||
if (child) {
|
||||
return graph.set(index[0], {
|
||||
post: child.post.hash || '',
|
||||
children: child.children
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (child) {
|
||||
_remove(child.children, index.slice(1));
|
||||
return graph.set(index[0], child);
|
||||
} else {
|
||||
const child = graph.get(index[0]);
|
||||
if (child) {
|
||||
_remove(child.children, index.slice(1));
|
||||
graph.set(index[0], child);
|
||||
return graph.set(index[0], produce(draft => {
|
||||
draft.children = _remove(draft.children, index.slice(1))
|
||||
}));
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const data = _.get(json, 'remove-nodes', false);
|
||||
const data = _.get(json, 'remove-posts', false);
|
||||
if (data) {
|
||||
const { ship, name } = data.resource;
|
||||
const res = `${ship}/${name}`;
|
||||
@ -264,7 +269,7 @@ const removeNodes = (json, state: GraphState): GraphState => {
|
||||
let indexArr = index.split('/').slice(1).map((ind) => {
|
||||
return bigInt(ind);
|
||||
});
|
||||
_remove(state.graphs[res], indexArr);
|
||||
state.graphs[res] = _remove(state.graphs[res], indexArr);
|
||||
});
|
||||
}
|
||||
return state;
|
||||
|
@ -329,9 +329,9 @@ function added(json: any, state: HarkState): HarkState {
|
||||
);
|
||||
if (arrIdx !== -1) {
|
||||
timebox[arrIdx] = { index, notification };
|
||||
state.notifications.set(time, timebox);
|
||||
state.notifications = state.notifications.set(time, timebox);
|
||||
} else {
|
||||
state.notifications.set(time, [...timebox, { index, notification }]);
|
||||
state.notifications = state.notifications.set(time, [...timebox, { index, notification }]);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
@ -350,7 +350,7 @@ const timebox = (json: any, state: HarkState): HarkState => {
|
||||
if (data) {
|
||||
const time = makePatDa(data.time);
|
||||
if (!data.archive) {
|
||||
state.notifications.set(time, data.notifications);
|
||||
state.notifications = state.notifications.set(time, data.notifications);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
@ -403,7 +403,7 @@ function setRead(
|
||||
return state;
|
||||
}
|
||||
timebox[arrIdx].notification.read = read;
|
||||
state.notifications.set(patDa, timebox);
|
||||
state.notifications = state.notifications.set(patDa, timebox);
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -443,9 +443,9 @@ function archive(json: any, state: HarkState): HarkState {
|
||||
);
|
||||
if(unarchived.length === 0) {
|
||||
console.log('deleting entire timebox');
|
||||
state.notifications.delete(time);
|
||||
state.notifications = state.notifications.delete(time);
|
||||
} else {
|
||||
state.notifications.set(time, unarchived);
|
||||
state.notifications = state.notifications.set(time, unarchived);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
|
@ -35,4 +35,8 @@ export function useContact(ship: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export function useOurContact() {
|
||||
return useContact(`~${window.ship}`)
|
||||
}
|
||||
|
||||
export default useContactState;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Graphs, decToUd, numToUd, GraphNode } from "@urbit/api";
|
||||
import { Graphs, decToUd, numToUd, GraphNode, deSig, Association, resourceFromPath } from "@urbit/api";
|
||||
import {useCallback} from "react";
|
||||
|
||||
import { BaseState, createState } from "./base";
|
||||
|
||||
@ -128,6 +129,20 @@ const useGraphState = createState<GraphState>('Graph', {
|
||||
// });
|
||||
// graphReducer(node);
|
||||
// },
|
||||
}, ['graphs', 'graphKeys', 'looseNodes']);
|
||||
}, ['graphs', 'graphKeys', 'looseNodes', 'graphTimesentMap']);
|
||||
|
||||
export function useGraph(ship: string, name: string) {
|
||||
return useGraphState(
|
||||
useCallback(s => s.graphs[`${deSig(ship)}/${name}`], [ship, name])
|
||||
);
|
||||
}
|
||||
|
||||
export function useGraphForAssoc(association: Association) {
|
||||
const { resource } = association;
|
||||
const { ship, name } = resourceFromPath(resource);
|
||||
return useGraph(ship, name);
|
||||
}
|
||||
|
||||
window.useGraphState = useGraphState;
|
||||
|
||||
export default useGraphState;
|
||||
|
@ -90,8 +90,8 @@ const useLocalState = create<LocalStateZus>(persist((set, get) => ({
|
||||
name: 'localReducer'
|
||||
}));
|
||||
|
||||
function withLocalState<P, S extends keyof LocalState>(Component: any, stateMemberKeys?: S[]) {
|
||||
return React.forwardRef((props: Omit<P, S>, ref) => {
|
||||
function withLocalState<P, S extends keyof LocalState, C extends React.ComponentType<P>>(Component: C, stateMemberKeys?: S[]) {
|
||||
return React.forwardRef<C, Omit<P, S>>((props, ref) => {
|
||||
const localState = stateMemberKeys ? useLocalState(
|
||||
state => stateMemberKeys.reduce(
|
||||
(object, key) => ({ ...object, [key]: state[key] }), {}
|
||||
|
@ -1,8 +1,14 @@
|
||||
import React, { useRef, useCallback, useEffect, useState } from 'react';
|
||||
import React, {
|
||||
useRef,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useState,
|
||||
useMemo,
|
||||
} from 'react';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import { Col } from '@tlon/indigo-react';
|
||||
import _ from 'lodash';
|
||||
import bigInt from 'big-integer';
|
||||
import bigInt, { BigInteger } from 'big-integer';
|
||||
|
||||
import { Association } from '@urbit/api/metadata';
|
||||
import { StoreState } from '~/logic/store/type';
|
||||
@ -16,176 +22,148 @@ import { useLocalStorageState } from '~/logic/lib/useLocalStorageState';
|
||||
import { Loading } from '~/views/components/Loading';
|
||||
import { isWriter, resourceFromPath } from '~/logic/lib/group';
|
||||
|
||||
import './css/custom.css';
|
||||
import useContactState from '~/logic/state/contact';
|
||||
import useGraphState from '~/logic/state/graph';
|
||||
import useGroupState from '~/logic/state/group';
|
||||
import useGraphState, { useGraphForAssoc } from '~/logic/state/graph';
|
||||
import useGroupState, { useGroupForAssoc } from '~/logic/state/group';
|
||||
import useHarkState from '~/logic/state/hark';
|
||||
import {Post} from '@urbit/api';
|
||||
import {getPermalinkForGraph} from '~/logic/lib/permalinks';
|
||||
import { Content, createPost, Post } from '@urbit/api';
|
||||
import { getPermalinkForGraph } from '~/logic/lib/permalinks';
|
||||
import { ChatPane } from './components/ChatPane';
|
||||
|
||||
const getCurrGraphSize = (ship: string, name: string) => {
|
||||
const { graphs } = useGraphState.getState();
|
||||
const graph = graphs[`${ship}/${name}`];
|
||||
return graph?.size ?? 0;
|
||||
};
|
||||
|
||||
|
||||
type ChatResourceProps = StoreState & {
|
||||
association: Association;
|
||||
api: GlobalApi;
|
||||
baseUrl: string;
|
||||
} & RouteComponentProps;
|
||||
};
|
||||
|
||||
export function ChatResource(props: ChatResourceProps) {
|
||||
const station = props.association.resource;
|
||||
const groupPath = props.association.group;
|
||||
const groups = useGroupState(state => state.groups);
|
||||
const group = groups[groupPath];
|
||||
const contacts = useContactState(state => state.contacts);
|
||||
const graphs = useGraphState(state => state.graphs);
|
||||
const graphPath = station.slice(7);
|
||||
const graph = graphs[graphPath];
|
||||
const unreads = useHarkState(state => state.unreads);
|
||||
const unreadCount = unreads.graph?.[station]?.['/']?.unreads || 0;
|
||||
const graphTimesentMap = useGraphState(state => state.graphTimesentMap);
|
||||
const [,, owner, name] = station.split('/');
|
||||
const ourContact = contacts?.[`~${window.ship}`];
|
||||
const chatInput = useRef<ChatInput>();
|
||||
const canWrite = isWriter(group, station);
|
||||
function ChatResource(props: ChatResourceProps) {
|
||||
const { association, api } = props;
|
||||
const { resource } = association;
|
||||
const [toShare, setToShare] = useState<string[] | string | undefined>();
|
||||
const group = useGroupForAssoc(association)!;
|
||||
const graph = useGraphForAssoc(association);
|
||||
const unreads = useHarkState((state) => state.unreads);
|
||||
const unreadCount =
|
||||
(unreads.graph?.[resource]?.['/']?.unreads as number) || 0;
|
||||
const canWrite = group ? isWriter(group, resource) : false;
|
||||
|
||||
useEffect(() => {
|
||||
const count = 100 + unreadCount;
|
||||
props.api.graph.getNewest(owner, name, count);
|
||||
}, [station]);
|
||||
|
||||
const onFileDrag = useCallback(
|
||||
(files: FileList | File[]) => {
|
||||
if (!chatInput.current) {
|
||||
return;
|
||||
}
|
||||
chatInput.current?.uploadFiles(files);
|
||||
},
|
||||
[chatInput.current]
|
||||
);
|
||||
|
||||
const { bind, dragging } = useFileDrag(onFileDrag);
|
||||
|
||||
const [unsent, setUnsent] = useLocalStorageState<Record<string, string>>(
|
||||
'chat-unsent',
|
||||
{}
|
||||
);
|
||||
|
||||
const appendUnsent = useCallback(
|
||||
(u: string) => setUnsent(s => ({ ...s, [station]: u })),
|
||||
[station]
|
||||
);
|
||||
|
||||
const clearUnsent = useCallback(
|
||||
() => setUnsent(s => _.omit(s, station)),
|
||||
[station]
|
||||
);
|
||||
|
||||
const scrollTo = new URLSearchParams(location.search).get('msg');
|
||||
|
||||
const [showBanner, setShowBanner] = useState(false);
|
||||
const [hasLoadedAllowed, setHasLoadedAllowed] = useState(false);
|
||||
const [recipients, setRecipients] = useState([]);
|
||||
|
||||
const res = resourceFromPath(groupPath);
|
||||
const onReply = useCallback((msg: Post) => {
|
||||
const url = getPermalinkForGraph(
|
||||
props.association.group,
|
||||
props.association.resource,
|
||||
msg.index
|
||||
);
|
||||
const message = `${url}\n~${msg.author} : `;
|
||||
setUnsent(s => ({...s, [props.association.resource]: message }));
|
||||
}, [props.association, group, setUnsent]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (!res) { return; }
|
||||
if (!group) { return; }
|
||||
if (group.hidden) {
|
||||
const members = _.compact(await Promise.all(
|
||||
const count = Math.min(400, 100 + unreadCount);
|
||||
const { ship, name } = resourceFromPath(resource);
|
||||
props.api.graph.getNewest(ship, name, count);
|
||||
setToShare(undefined);
|
||||
(async function() {
|
||||
if(group.hidden) {
|
||||
const members = await props.api.contacts.disallowedShipsForOurContact(
|
||||
Array.from(group.members)
|
||||
.map(s => {
|
||||
const ship = `~${s}`;
|
||||
if(s === window.ship) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return props.api.contacts.fetchIsAllowed(
|
||||
`~${window.ship}`,
|
||||
'personal',
|
||||
ship,
|
||||
true
|
||||
).then(isAllowed => {
|
||||
return isAllowed ? null : ship;
|
||||
});
|
||||
})
|
||||
));
|
||||
|
||||
);
|
||||
if(members.length > 0) {
|
||||
setShowBanner(true);
|
||||
setRecipients(members);
|
||||
} else {
|
||||
setShowBanner(false);
|
||||
setToShare(members);
|
||||
}
|
||||
} else {
|
||||
const groupShared = await props.api.contacts.fetchIsAllowed(
|
||||
const { ship: groupHost } = resourceFromPath(association.group);
|
||||
const shared = await props.api.contacts.fetchIsAllowed(
|
||||
`~${window.ship}`,
|
||||
'personal',
|
||||
res.ship,
|
||||
groupHost,
|
||||
true
|
||||
);
|
||||
setShowBanner(!groupShared);
|
||||
if(!shared) {
|
||||
setToShare(association.group);
|
||||
}
|
||||
}
|
||||
|
||||
setHasLoadedAllowed(true);
|
||||
})();
|
||||
}, [groupPath, group]);
|
||||
}, [resource]);
|
||||
|
||||
if(!graph) {
|
||||
const onReply = useCallback(
|
||||
(msg: Post) => {
|
||||
const url = getPermalinkForGraph(
|
||||
props.association.group,
|
||||
props.association.resource,
|
||||
msg.index
|
||||
);
|
||||
return `${url}\n~${msg.author} : `;
|
||||
},
|
||||
[association]
|
||||
);
|
||||
|
||||
const isAdmin = useMemo(
|
||||
() => (group ? group.tags.role.admin.has(`~${window.ship}`) : false),
|
||||
[group]
|
||||
);
|
||||
|
||||
const fetchMessages = useCallback(async (newer: boolean) => {
|
||||
const { api } = props;
|
||||
const pageSize = 100;
|
||||
|
||||
const [, , ship, name] = resource.split('/');
|
||||
const graphSize = graph?.size ?? 0;
|
||||
const expectedSize = graphSize + pageSize;
|
||||
if (newer) {
|
||||
const index = graph.peekLargest()?.[0];
|
||||
if(!index) {
|
||||
return true;
|
||||
}
|
||||
await api.graph.getYoungerSiblings(
|
||||
ship,
|
||||
name,
|
||||
pageSize,
|
||||
`/${index.toString()}`
|
||||
);
|
||||
return expectedSize !== getCurrGraphSize(ship.slice(1), name);
|
||||
} else {
|
||||
const index = graph.peekSmallest()?.[0];
|
||||
if(!index) {
|
||||
return true;
|
||||
}
|
||||
await api.graph.getOlderSiblings(ship, name, pageSize, `/${index.toString()}`);
|
||||
const done = expectedSize !== getCurrGraphSize(ship.slice(1), name);
|
||||
return done;
|
||||
}
|
||||
}, [graph, resource]);
|
||||
|
||||
const onSubmit = useCallback((contents: Content[]) => {
|
||||
const { ship, name } = resourceFromPath(resource);
|
||||
api.graph.addPost(ship, name, createPost(window.ship, contents))
|
||||
}, [resource]);
|
||||
|
||||
const dismissUnread = useCallback(() => {
|
||||
api.hark.markCountAsRead(association, '/', 'message');
|
||||
}, [association]);
|
||||
|
||||
const getPermalink = useCallback(
|
||||
(index: BigInteger) =>
|
||||
getPermalinkForGraph(association.group, resource, `/${index.toString()}`),
|
||||
[association]
|
||||
);
|
||||
|
||||
if (!graph) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Col {...bind} height="100%" overflow="hidden" position="relative">
|
||||
<ShareProfile
|
||||
our={ourContact}
|
||||
api={props.api}
|
||||
recipient={owner}
|
||||
recipients={recipients}
|
||||
showBanner={showBanner}
|
||||
setShowBanner={setShowBanner}
|
||||
group={group}
|
||||
groupPath={groupPath}
|
||||
/>
|
||||
{dragging && <SubmitDragger />}
|
||||
<ChatWindow
|
||||
key={station}
|
||||
history={props.history}
|
||||
graph={graph}
|
||||
graphSize={graph.size}
|
||||
unreadCount={unreadCount}
|
||||
showOurContact={ !showBanner && hasLoadedAllowed }
|
||||
association={props.association}
|
||||
pendingSize={Object.keys(graphTimesentMap[graphPath] || {}).length}
|
||||
group={group}
|
||||
ship={owner}
|
||||
onReply={onReply}
|
||||
station={station}
|
||||
api={props.api}
|
||||
scrollTo={scrollTo ? bigInt(scrollTo) : undefined}
|
||||
/>
|
||||
{ canWrite && (
|
||||
<ChatInput
|
||||
ref={chatInput}
|
||||
api={props.api}
|
||||
station={station}
|
||||
ourContact={
|
||||
(!showBanner && hasLoadedAllowed) ? ourContact : null
|
||||
}
|
||||
envelopes={[]}
|
||||
onUnmount={appendUnsent}
|
||||
placeholder="Message..."
|
||||
message={unsent[station] || ''}
|
||||
deleteMessage={clearUnsent}
|
||||
/> )}
|
||||
</Col>
|
||||
<ChatPane
|
||||
id={resource.slice(7)}
|
||||
graph={graph}
|
||||
unreadCount={unreadCount}
|
||||
api={api}
|
||||
canWrite={canWrite}
|
||||
onReply={onReply}
|
||||
fetchMessages={fetchMessages}
|
||||
dismissUnread={dismissUnread}
|
||||
getPermalink={getPermalink}
|
||||
isAdmin={isAdmin}
|
||||
onSubmit={onSubmit}
|
||||
promptShare={toShare}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { ChatResource };
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { Component } from 'react';
|
||||
import React, { Component, ReactNode } from 'react';
|
||||
import ChatEditor from './chat-editor';
|
||||
import { IuseStorage } from '~/logic/lib/useStorage';
|
||||
import { uxToHex } from '~/logic/lib/util';
|
||||
@ -8,28 +8,29 @@ import tokenizeMessage, { isUrl } from '~/logic/lib/tokenizeMessage';
|
||||
import GlobalApi from '~/logic/api/global';
|
||||
import { Envelope } from '~/types/chat-update';
|
||||
import { StorageState } from '~/types';
|
||||
import { Contacts, Content } from '@urbit/api';
|
||||
import { Contact, Contacts, Content, Post } from '@urbit/api';
|
||||
import { Row, BaseImage, Box, Icon, LoadingSpinner } from '@tlon/indigo-react';
|
||||
import withStorage from '~/views/components/withStorage';
|
||||
import { withLocalState } from '~/logic/state/local';
|
||||
import { MOBILE_BROWSER_REGEX } from "~/logic/lib/util";
|
||||
|
||||
type ChatInputProps = IuseStorage & {
|
||||
api: GlobalApi;
|
||||
numMsgs: number;
|
||||
station: unknown;
|
||||
ourContact: unknown;
|
||||
envelopes: Envelope[];
|
||||
ourContact?: Contact;
|
||||
onUnmount(msg: string): void;
|
||||
placeholder: string;
|
||||
message: string;
|
||||
deleteMessage(): void;
|
||||
hideAvatars: boolean;
|
||||
onSubmit: (contents: Content[]) => void;
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
interface ChatInputState {
|
||||
inCodeMode: boolean;
|
||||
submitFocus: boolean;
|
||||
uploadingPaste: boolean;
|
||||
currentInput: string;
|
||||
}
|
||||
|
||||
class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
@ -41,7 +42,8 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
this.state = {
|
||||
inCodeMode: false,
|
||||
submitFocus: false,
|
||||
uploadingPaste: false
|
||||
uploadingPaste: false,
|
||||
currentInput: props.message
|
||||
};
|
||||
|
||||
this.chatEditor = React.createRef();
|
||||
@ -50,6 +52,7 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
this.toggleCode = this.toggleCode.bind(this);
|
||||
this.uploadSuccess = this.uploadSuccess.bind(this);
|
||||
this.uploadError = this.uploadError.bind(this);
|
||||
this.eventHandler = this.eventHandler.bind(this);
|
||||
}
|
||||
|
||||
toggleCode() {
|
||||
@ -58,39 +61,30 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
});
|
||||
}
|
||||
|
||||
submit(text) {
|
||||
async submit(text) {
|
||||
const { props, state } = this;
|
||||
const [, , ship, name] = props.station.split('/');
|
||||
if (state.inCodeMode) {
|
||||
this.setState(
|
||||
{
|
||||
inCodeMode: false
|
||||
},
|
||||
async () => {
|
||||
const output = await props.api.graph.eval(text);
|
||||
const contents: Content[] = [{ code: { output, expression: text } }];
|
||||
const post = createPost(contents);
|
||||
props.api.graph.addPost(ship, name, post);
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const post = createPost(tokenizeMessage(text));
|
||||
|
||||
const { onSubmit, api } = this.props;
|
||||
this.setState({
|
||||
inCodeMode: false
|
||||
});
|
||||
props.deleteMessage();
|
||||
|
||||
props.api.graph.addPost(ship, name, post);
|
||||
if(state.inCodeMode) {
|
||||
const output = await api.graph.eval(text) as string[];
|
||||
onSubmit([{ code: { output, expression: text } }]);
|
||||
} else {
|
||||
onSubmit(tokenizeMessage(text));
|
||||
}
|
||||
this.chatEditor.current.editor.focus();
|
||||
this.setState({ currentInput: '' });
|
||||
}
|
||||
|
||||
uploadSuccess(url) {
|
||||
uploadSuccess(url: string) {
|
||||
const { props } = this;
|
||||
if (this.state.uploadingPaste) {
|
||||
this.chatEditor.current.editor.setValue(url);
|
||||
this.setState({ uploadingPaste: false });
|
||||
} else {
|
||||
const [, , ship, name] = props.station.split('/');
|
||||
props.api.graph.addPost(ship, name, createPost([{ url }]));
|
||||
props.onSubmit([{ url }])
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,6 +114,10 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
});
|
||||
}
|
||||
|
||||
eventHandler(value) {
|
||||
this.setState({ currentInput: value });
|
||||
}
|
||||
|
||||
render() {
|
||||
const { props, state } = this;
|
||||
|
||||
@ -130,6 +128,7 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
const avatar =
|
||||
props.ourContact && props.ourContact?.avatar && !props.hideAvatars ? (
|
||||
<BaseImage
|
||||
flexShrink={0}
|
||||
src={props.ourContact.avatar}
|
||||
height={24}
|
||||
width={24}
|
||||
@ -170,7 +169,7 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
className='cf'
|
||||
zIndex={0}
|
||||
>
|
||||
<Row p='12px 4px 12px 12px' alignItems='center'>
|
||||
<Row p='12px 4px 12px 12px' flexShrink={0} alignItems='center'>
|
||||
{avatar}
|
||||
</Row>
|
||||
<ChatEditor
|
||||
@ -180,15 +179,25 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
onUnmount={props.onUnmount}
|
||||
message={props.message}
|
||||
onPaste={this.onPaste.bind(this)}
|
||||
changeEvent={this.eventHandler}
|
||||
placeholder='Message...'
|
||||
/>
|
||||
<Box mx={2} flexShrink={0} height='16px' width='16px' flexBasis='16px'>
|
||||
<Box mx='12px' flexShrink={0} height='16px' width='16px' flexBasis='16px'>
|
||||
<Icon
|
||||
icon='Dojo'
|
||||
cursor='pointer'
|
||||
onClick={this.toggleCode}
|
||||
color={state.inCodeMode ? 'blue' : 'black'}
|
||||
/>
|
||||
</Box>
|
||||
<Box ml='12px' mr={3} flexShrink={0} height='16px' width='16px' flexBasis='16px'>
|
||||
{this.props.canUpload ? (
|
||||
this.props.uploading ? (
|
||||
<LoadingSpinner />
|
||||
) : (
|
||||
<Icon
|
||||
icon='Attachment'
|
||||
cursor='pointer'
|
||||
width='16'
|
||||
height='16'
|
||||
onClick={() =>
|
||||
@ -198,18 +207,30 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
)
|
||||
) : null}
|
||||
</Box>
|
||||
<Box mr={2} flexShrink={0} height='16px' width='16px' flexBasis='16px'>
|
||||
<Icon
|
||||
icon='Dojo'
|
||||
onClick={this.toggleCode}
|
||||
color={state.inCodeMode ? 'blue' : 'black'}
|
||||
/>
|
||||
</Box>
|
||||
{MOBILE_BROWSER_REGEX.test(navigator.userAgent) ?
|
||||
<Box
|
||||
ml={2}
|
||||
mr="12px"
|
||||
flexShrink={0}
|
||||
display="flex"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
width="24px"
|
||||
height="24px"
|
||||
borderRadius="50%"
|
||||
backgroundColor={state.currentInput !== '' ? 'blue' : 'gray'}
|
||||
cursor={state.currentInput !== '' ? 'pointer' : 'default'}
|
||||
onClick={() => this.chatEditor.current.submit()}
|
||||
>
|
||||
<Icon icon="ArrowEast" color="white" />
|
||||
</Box>
|
||||
: null}
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withLocalState(withStorage(ChatInput, { accept: 'image/*' }), [
|
||||
'hideAvatars'
|
||||
]);
|
||||
export default withLocalState<Omit<ChatInputProps, keyof IuseStorage>, 'hideAvatars', ChatInput>(
|
||||
withStorage<ChatInputProps, ChatInput>(ChatInput, { accept: 'image/*' }),
|
||||
['hideAvatars']
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ import bigInt from 'big-integer';
|
||||
import React, {
|
||||
useState,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
Component,
|
||||
PureComponent,
|
||||
@ -40,11 +41,13 @@ import styled from 'styled-components';
|
||||
import useLocalState from '~/logic/state/local';
|
||||
import useSettingsState, { selectCalmState } from '~/logic/state/settings';
|
||||
import Timestamp from '~/views/components/Timestamp';
|
||||
import useContactState from '~/logic/state/contact';
|
||||
import useContactState, {useContact} from '~/logic/state/contact';
|
||||
import { useIdlingState } from '~/logic/lib/idling';
|
||||
import ProfileOverlay from '~/views/components/ProfileOverlay';
|
||||
import {useCopy} from '~/logic/lib/useCopy';
|
||||
import {GraphContentWide} from '~/views/landscape/components/Graph/GraphContentWide';
|
||||
import {Contact} from '@urbit/api';
|
||||
import GlobalApi from '~/logic/api/global';
|
||||
|
||||
|
||||
export const DATESTAMP_FORMAT = '[~]YYYY.M.D';
|
||||
@ -80,16 +83,13 @@ export const DayBreak = ({ when, shimTop = false }: DayBreakProps) => (
|
||||
);
|
||||
|
||||
export const UnreadMarker = React.forwardRef(
|
||||
({ dayBreak, when, api, association }, ref) => {
|
||||
({ dismissUnread }: any, ref) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const idling = useIdlingState();
|
||||
const dismiss = useCallback(() => {
|
||||
api.hark.markCountAsRead(association, '/', 'message');
|
||||
}, [api, association]);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && !idling) {
|
||||
dismiss();
|
||||
dismissUnread();
|
||||
}
|
||||
}, [visible, idling]);
|
||||
|
||||
@ -141,10 +141,9 @@ const MessageActionItem = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
const MessageActions = ({ api, onReply, association, history, msg, group }) => {
|
||||
const isAdmin = () => group.tags.role.admin.has(window.ship);
|
||||
const MessageActions = ({ api, onReply, association, msg, isAdmin, permalink }) => {
|
||||
const isOwn = () => msg.author === window.ship;
|
||||
const { doCopy, copyDisplay } = useCopy(`web+urbitgraph://group${association.group.slice(5)}/graph${association.resource.slice(5)}${msg.index}`, 'Copy Message Link');
|
||||
const { doCopy, copyDisplay } = useCopy(permalink, 'Copy Message Link');
|
||||
|
||||
return (
|
||||
<Box
|
||||
@ -235,176 +234,161 @@ interface ChatMessageProps {
|
||||
previousMsg?: Post;
|
||||
nextMsg?: Post;
|
||||
isLastRead: boolean;
|
||||
group: Group;
|
||||
association: Association;
|
||||
permalink: string;
|
||||
transcluded?: number;
|
||||
className?: string;
|
||||
isPending: boolean;
|
||||
style?: unknown;
|
||||
scrollWindow: HTMLDivElement;
|
||||
isLastMessage?: boolean;
|
||||
unreadMarkerRef: React.RefObject<HTMLDivElement>;
|
||||
history: unknown;
|
||||
dismissUnread: () => void;
|
||||
api: GlobalApi;
|
||||
highlighted?: boolean;
|
||||
renderSigil?: boolean;
|
||||
hideHover?: boolean;
|
||||
innerRef: (el: HTMLDivElement | null) => void;
|
||||
onReply?: (msg: Post) => void;
|
||||
showOurContact: boolean;
|
||||
}
|
||||
|
||||
class ChatMessage extends Component<ChatMessageProps> {
|
||||
private divRef: React.RefObject<HTMLDivElement>;
|
||||
function ChatMessage(props: ChatMessageProps) {
|
||||
let { highlighted } = props;
|
||||
const {
|
||||
msg,
|
||||
previousMsg,
|
||||
nextMsg,
|
||||
isLastRead,
|
||||
group,
|
||||
association,
|
||||
className = '',
|
||||
isPending,
|
||||
style,
|
||||
isLastMessage,
|
||||
api,
|
||||
showOurContact,
|
||||
fontSize,
|
||||
hideHover,
|
||||
dismissUnread,
|
||||
permalink
|
||||
} = props;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.divRef = React.createRef();
|
||||
}
|
||||
let onReply = props?.onReply ?? (() => {});
|
||||
const transcluded = props?.transcluded ?? 0;
|
||||
const renderSigil = props.renderSigil ?? (Boolean(nextMsg && msg.author !== nextMsg.author) ||
|
||||
!nextMsg ||
|
||||
msg.number === 1
|
||||
);
|
||||
|
||||
componentDidMount() {}
|
||||
const ourMention = msg?.contents?.some((e) => {
|
||||
return e?.mention && e?.mention === window.ship;
|
||||
});
|
||||
|
||||
render() {
|
||||
const {
|
||||
msg,
|
||||
previousMsg,
|
||||
nextMsg,
|
||||
isLastRead,
|
||||
group,
|
||||
association,
|
||||
className = '',
|
||||
isPending,
|
||||
style,
|
||||
scrollWindow,
|
||||
isLastMessage,
|
||||
unreadMarkerRef,
|
||||
history,
|
||||
api,
|
||||
highlighted,
|
||||
showOurContact,
|
||||
fontSize,
|
||||
hideHover
|
||||
} = this.props;
|
||||
|
||||
let onReply = this.props?.onReply ?? (() => {});
|
||||
const transcluded = this.props?.transcluded ?? 0;
|
||||
let { renderSigil } = this.props;
|
||||
|
||||
if (renderSigil === undefined) {
|
||||
renderSigil = Boolean(
|
||||
(nextMsg && msg.author !== nextMsg.author) ||
|
||||
!nextMsg ||
|
||||
msg.number === 1
|
||||
);
|
||||
if (!highlighted) {
|
||||
if (ourMention) {
|
||||
highlighted = true;
|
||||
}
|
||||
}
|
||||
|
||||
const date = daToUnix(bigInt(msg.index.split('/')[1]));
|
||||
const nextDate = nextMsg ? (
|
||||
daToUnix(bigInt(nextMsg.index.split('/')[1]))
|
||||
) : null;
|
||||
const date = useMemo(() => daToUnix(bigInt(msg.index.split('/')[1])), [msg.index]);
|
||||
const nextDate = useMemo(() => nextMsg ? (
|
||||
daToUnix(bigInt(nextMsg.index.split('/')[1]))
|
||||
) : null,
|
||||
[nextMsg]
|
||||
);
|
||||
|
||||
const dayBreak =
|
||||
nextMsg &&
|
||||
new Date(date).getDate() !==
|
||||
new Date(nextDate).getDate();
|
||||
const dayBreak = useMemo(() =>
|
||||
nextDate &&
|
||||
new Date(date).getDate() !==
|
||||
new Date(nextDate).getDate()
|
||||
, [nextDate, date])
|
||||
|
||||
const containerClass = `${isPending ? 'o-40' : ''} ${className}`;
|
||||
const containerClass = `${isPending ? 'o-40' : ''} ${className}`;
|
||||
|
||||
const timestamp = moment
|
||||
.unix(date / 1000)
|
||||
.format(renderSigil ? 'h:mm A' : 'h:mm');
|
||||
const timestamp = useMemo(() => moment
|
||||
.unix(date / 1000)
|
||||
.format(renderSigil ? 'h:mm A' : 'h:mm'),
|
||||
[date, renderSigil]
|
||||
);
|
||||
|
||||
const messageProps = {
|
||||
msg,
|
||||
timestamp,
|
||||
association,
|
||||
group,
|
||||
style,
|
||||
containerClass,
|
||||
isPending,
|
||||
showOurContact,
|
||||
history,
|
||||
api,
|
||||
scrollWindow,
|
||||
highlighted,
|
||||
fontSize,
|
||||
hideHover,
|
||||
transcluded,
|
||||
onReply
|
||||
};
|
||||
const messageProps = {
|
||||
msg,
|
||||
timestamp,
|
||||
association,
|
||||
isPending,
|
||||
showOurContact,
|
||||
api,
|
||||
highlighted,
|
||||
fontSize,
|
||||
hideHover,
|
||||
transcluded,
|
||||
onReply
|
||||
};
|
||||
|
||||
const unreadContainerStyle = {
|
||||
height: isLastRead ? '2rem' : '0'
|
||||
};
|
||||
const message = useMemo(() => (
|
||||
<Message
|
||||
msg={msg}
|
||||
timestamp={timestamp}
|
||||
timestampHover={!renderSigil}
|
||||
api={api}
|
||||
transcluded={transcluded}
|
||||
showOurContact={showOurContact}
|
||||
/>
|
||||
), [renderSigil, msg, timestamp, api, transcluded, showOurContact]);
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={this.props.innerRef}
|
||||
pt={renderSigil ? 2 : 0}
|
||||
width="100%"
|
||||
pb={isLastMessage ? '20px' : 0}
|
||||
className={containerClass}
|
||||
style={style}
|
||||
>
|
||||
{dayBreak && !isLastRead ? (
|
||||
<DayBreak when={date} shimTop={renderSigil} />
|
||||
const unreadContainerStyle = {
|
||||
height: isLastRead ? '2rem' : '0'
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={props.innerRef}
|
||||
pt={renderSigil ? 2 : 0}
|
||||
width="100%"
|
||||
pb={isLastMessage ? '20px' : 0}
|
||||
className={containerClass}
|
||||
style={style}
|
||||
>
|
||||
{dayBreak && !isLastRead ? (
|
||||
<DayBreak when={date} shimTop={renderSigil} />
|
||||
) : null}
|
||||
<MessageWrapper permalink={permalink} {...messageProps}>
|
||||
{ renderSigil && <MessageAuthor {...messageProps} />}
|
||||
{message}
|
||||
</MessageWrapper>
|
||||
<Box style={unreadContainerStyle}>
|
||||
{isLastRead ? (
|
||||
<UnreadMarker dismissUnread={dismissUnread} />
|
||||
) : null}
|
||||
{renderSigil ? (
|
||||
<MessageWrapper {...messageProps}>
|
||||
<MessageAuthor pb={1} {...messageProps} />
|
||||
<Message pl={'44px'} pr={4} {...messageProps} />
|
||||
</MessageWrapper>
|
||||
) : (
|
||||
<MessageWrapper {...messageProps}>
|
||||
<Message pl={'44px'} pr={4} timestampHover {...messageProps} />
|
||||
</MessageWrapper>
|
||||
)}
|
||||
<Box style={unreadContainerStyle}>
|
||||
{isLastRead ? (
|
||||
<UnreadMarker
|
||||
association={association}
|
||||
api={api}
|
||||
dayBreak={dayBreak}
|
||||
when={date}
|
||||
ref={unreadMarkerRef}
|
||||
/>
|
||||
) : null}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.forwardRef((props, ref) => (
|
||||
export default React.forwardRef((props: Omit<ChatMessageProps, 'innerRef'>, ref: any) => (
|
||||
<ChatMessage {...props} innerRef={ref} />
|
||||
));
|
||||
|
||||
export const MessageAuthor = ({
|
||||
timestamp,
|
||||
msg,
|
||||
group,
|
||||
api,
|
||||
history,
|
||||
scrollWindow,
|
||||
showOurContact,
|
||||
...rest
|
||||
}) => {
|
||||
const osDark = useLocalState((state) => state.dark);
|
||||
|
||||
const theme = useSettingsState((s) => s.display.theme);
|
||||
const dark = theme === 'dark' || (theme === 'auto' && osDark);
|
||||
const contacts = useContactState((state) => state.contacts);
|
||||
let contact: Contact | null = useContact(`~${msg.author}`);
|
||||
|
||||
const date = daToUnix(bigInt(msg.index.split('/')[1]));
|
||||
|
||||
const datestamp = moment
|
||||
.unix(date / 1000)
|
||||
.format(DATESTAMP_FORMAT);
|
||||
const contact =
|
||||
contact =
|
||||
((msg.author === window.ship && showOurContact) ||
|
||||
msg.author !== window.ship) &&
|
||||
`~${msg.author}` in contacts
|
||||
? contacts[`~${msg.author}`]
|
||||
: undefined;
|
||||
msg.author !== window.ship)
|
||||
? contact
|
||||
: null;
|
||||
|
||||
const showNickname = useShowNickname(contact);
|
||||
const { hideAvatars } = useSettingsState(selectCalmState);
|
||||
@ -457,7 +441,7 @@ export const MessageAuthor = ({
|
||||
</Box>
|
||||
);
|
||||
return (
|
||||
<Box display='flex' alignItems='flex-start' {...rest}>
|
||||
<Box pb="1" display='flex' alignItems='flex-start'>
|
||||
<Box
|
||||
height={24}
|
||||
pr={2}
|
||||
@ -509,20 +493,20 @@ export const MessageAuthor = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const Message = ({
|
||||
type MessageProps = { timestamp: string; timestampHover: boolean; }
|
||||
& Pick<ChatMessageProps, "msg" | "api" | "transcluded" | "showOurContact">
|
||||
|
||||
export const Message = React.memo(({
|
||||
timestamp,
|
||||
msg,
|
||||
group,
|
||||
api,
|
||||
scrollWindow,
|
||||
timestampHover,
|
||||
transcluded,
|
||||
showOurContact,
|
||||
...rest
|
||||
}) => {
|
||||
showOurContact
|
||||
}: MessageProps) => {
|
||||
const { hovering, bind } = useHovering();
|
||||
return (
|
||||
<Box width="100%" position='relative' {...rest}>
|
||||
<Box pl="44px" width="100%" position='relative'>
|
||||
{timestampHover ? (
|
||||
<Text
|
||||
display={hovering ? 'block' : 'none'}
|
||||
@ -549,7 +533,9 @@ export const Message = ({
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
Message.displayName = 'Message';
|
||||
|
||||
export const MessagePlaceholder = ({
|
||||
height,
|
||||
@ -578,7 +564,7 @@ export const MessagePlaceholder = ({
|
||||
>
|
||||
<Text
|
||||
display='block'
|
||||
background='gray'
|
||||
background='washedGray'
|
||||
width='24px'
|
||||
height='24px'
|
||||
borderRadius='50%'
|
||||
@ -601,12 +587,13 @@ export const MessagePlaceholder = ({
|
||||
display='inline-block'
|
||||
verticalAlign='middle'
|
||||
fontSize='0'
|
||||
gray
|
||||
washedGray
|
||||
cursor='default'
|
||||
>
|
||||
<Text maxWidth='32rem' display='block'>
|
||||
<Text
|
||||
backgroundColor='gray'
|
||||
backgroundColor='washedGray'
|
||||
borderRadius='2'
|
||||
display='block'
|
||||
width='100%'
|
||||
height='100%'
|
||||
@ -618,10 +605,11 @@ export const MessagePlaceholder = ({
|
||||
mono
|
||||
verticalAlign='middle'
|
||||
fontSize='0'
|
||||
gray
|
||||
washedGray
|
||||
>
|
||||
<Text
|
||||
background='gray'
|
||||
background='washedGray'
|
||||
borderRadius='2'
|
||||
display='block'
|
||||
height='1em'
|
||||
style={{ width: `${((index % 3) + 1) * 3}em` }}
|
||||
@ -632,12 +620,14 @@ export const MessagePlaceholder = ({
|
||||
verticalAlign='middle'
|
||||
fontSize='0'
|
||||
ml='2'
|
||||
gray
|
||||
washedGray
|
||||
borderRadius='2'
|
||||
display={['none', 'inline-block']}
|
||||
className='child'
|
||||
>
|
||||
<Text
|
||||
backgroundColor='gray'
|
||||
backgroundColor='washedGray'
|
||||
borderRadius='2'
|
||||
display='block'
|
||||
width='100%'
|
||||
height='100%'
|
||||
@ -646,7 +636,8 @@ export const MessagePlaceholder = ({
|
||||
</Box>
|
||||
<Text
|
||||
display='block'
|
||||
backgroundColor='gray'
|
||||
backgroundColor='washedGray'
|
||||
borderRadius='2'
|
||||
height='1em'
|
||||
style={{ width: `${(index % 5) * 20}%` }}
|
||||
></Text>
|
||||
|
183
pkg/interface/src/views/apps/chat/components/ChatPane.tsx
Normal file
183
pkg/interface/src/views/apps/chat/components/ChatPane.tsx
Normal file
@ -0,0 +1,183 @@
|
||||
import React, { useRef, useCallback, useEffect, useState } from 'react';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import { Col } from '@tlon/indigo-react';
|
||||
import _ from 'lodash';
|
||||
import bigInt, { BigInteger } from 'big-integer';
|
||||
|
||||
import { Association } from '@urbit/api/metadata';
|
||||
import { StoreState } from '~/logic/store/type';
|
||||
import { useFileDrag } from '~/logic/lib/useDrag';
|
||||
import ChatWindow from './ChatWindow';
|
||||
import ChatInput from './ChatInput';
|
||||
import GlobalApi from '~/logic/api/global';
|
||||
import { ShareProfile } from '~/views/apps/chat/components/ShareProfile';
|
||||
import SubmitDragger from '~/views/components/SubmitDragger';
|
||||
import { useLocalStorageState } from '~/logic/lib/useLocalStorageState';
|
||||
import { Loading } from '~/views/components/Loading';
|
||||
import { isWriter, resourceFromPath } from '~/logic/lib/group';
|
||||
|
||||
import useContactState, { useOurContact } from '~/logic/state/contact';
|
||||
import useGraphState from '~/logic/state/graph';
|
||||
import useGroupState from '~/logic/state/group';
|
||||
import useHarkState from '~/logic/state/hark';
|
||||
import { Post, Graph, Content } from '@urbit/api';
|
||||
import { getPermalinkForGraph } from '~/logic/lib/permalinks';
|
||||
|
||||
interface ChatPaneProps {
|
||||
/**
|
||||
* A key to uniquely identify a ChatPane instance. Should be either the
|
||||
* resource for group chats or the @p for DMs
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The graph of the chat to render
|
||||
*/
|
||||
graph: Graph;
|
||||
unreadCount: number;
|
||||
/**
|
||||
* User able to write to chat
|
||||
*/
|
||||
canWrite: boolean;
|
||||
api: GlobalApi;
|
||||
/**
|
||||
* Get contents of reply message
|
||||
*/
|
||||
onReply: (msg: Post) => string;
|
||||
/**
|
||||
* Fetch more messages
|
||||
*
|
||||
* @param newer Get newer or older backlog
|
||||
* @returns Whether backlog is finished loading in that direction
|
||||
*/
|
||||
fetchMessages: (newer: boolean) => Promise<boolean>;
|
||||
/**
|
||||
* Dismiss unreads for chat
|
||||
*/
|
||||
dismissUnread: () => void;
|
||||
/**
|
||||
* Get permalink for a node
|
||||
*/
|
||||
getPermalink: (idx: BigInteger) => string;
|
||||
isAdmin: boolean;
|
||||
/**
|
||||
* Post message with contents to channel
|
||||
*/
|
||||
onSubmit: (contents: Content[]) => void;
|
||||
/**
|
||||
*
|
||||
* Users or group we haven't shared our contact with yet
|
||||
*
|
||||
* string[] - array of ships
|
||||
* string - path of group
|
||||
*/
|
||||
promptShare?: string[] | string;
|
||||
}
|
||||
|
||||
export function ChatPane(props: ChatPaneProps) {
|
||||
const {
|
||||
api,
|
||||
graph,
|
||||
unreadCount,
|
||||
canWrite,
|
||||
id,
|
||||
getPermalink,
|
||||
isAdmin,
|
||||
dismissUnread,
|
||||
onSubmit,
|
||||
promptShare = [],
|
||||
fetchMessages
|
||||
} = props;
|
||||
const graphTimesentMap = useGraphState((state) => state.graphTimesentMap);
|
||||
const ourContact = useOurContact();
|
||||
const chatInput = useRef<ChatInput>();
|
||||
|
||||
const onFileDrag = useCallback(
|
||||
(files: FileList | File[]) => {
|
||||
if (!chatInput.current) {
|
||||
return;
|
||||
}
|
||||
chatInput.current?.uploadFiles(files);
|
||||
},
|
||||
[chatInput.current]
|
||||
);
|
||||
|
||||
const { bind, dragging } = useFileDrag(onFileDrag);
|
||||
|
||||
const [unsent, setUnsent] = useLocalStorageState<Record<string, string>>(
|
||||
'chat-unsent',
|
||||
{}
|
||||
);
|
||||
|
||||
const appendUnsent = useCallback(
|
||||
(u: string) => setUnsent((s) => ({ ...s, [id]: u })),
|
||||
[id]
|
||||
);
|
||||
|
||||
const clearUnsent = useCallback(() => {
|
||||
setUnsent((s) => {
|
||||
if (id in s) {
|
||||
return _.omit(s, id);
|
||||
}
|
||||
return s;
|
||||
});
|
||||
}, [id]);
|
||||
|
||||
const scrollTo = new URLSearchParams(location.search).get('msg');
|
||||
|
||||
const [showBanner, setShowBanner] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setShowBanner(promptShare.length > 0);
|
||||
}, [promptShare]);
|
||||
|
||||
const onReply = useCallback(
|
||||
(msg: Post) => {
|
||||
const message = props.onReply(msg);
|
||||
setUnsent((s) => ({ ...s, [id]: message }));
|
||||
},
|
||||
[id, props.onReply]
|
||||
);
|
||||
|
||||
if (!graph) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Col {...bind} height="100%" overflow="hidden" position="relative">
|
||||
<ShareProfile
|
||||
our={ourContact}
|
||||
api={api}
|
||||
recipients={showBanner ? promptShare : []}
|
||||
onShare={() => setShowBanner(false)}
|
||||
/>
|
||||
{dragging && <SubmitDragger />}
|
||||
<ChatWindow
|
||||
key={id}
|
||||
graph={graph}
|
||||
graphSize={graph.size}
|
||||
unreadCount={unreadCount}
|
||||
showOurContact={promptShare.length === 0 && !showBanner}
|
||||
pendingSize={Object.keys(graphTimesentMap[id] || {}).length}
|
||||
onReply={onReply}
|
||||
dismissUnread={dismissUnread}
|
||||
fetchMessages={fetchMessages}
|
||||
isAdmin={isAdmin}
|
||||
getPermalink={getPermalink}
|
||||
api={api}
|
||||
scrollTo={scrollTo ? bigInt(scrollTo) : undefined}
|
||||
/>
|
||||
{canWrite && (
|
||||
<ChatInput
|
||||
ref={chatInput}
|
||||
api={props.api}
|
||||
onSubmit={onSubmit}
|
||||
ourContact={(promptShare.length === 0 && ourContact) || undefined}
|
||||
onUnmount={appendUnsent}
|
||||
placeholder="Message..."
|
||||
message={unsent[id] || ''}
|
||||
deleteMessage={clearUnsent}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import React, { Component } from 'react';
|
||||
import React, { useEffect, Component, useRef, useState, useCallback } from 'react';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import _ from 'lodash';
|
||||
import bigInt, { BigInteger } from 'big-integer';
|
||||
@ -11,7 +11,9 @@ import {
|
||||
Associations,
|
||||
Group,
|
||||
Groups,
|
||||
Graph
|
||||
Graph,
|
||||
Post,
|
||||
GraphNode
|
||||
} from '@urbit/api';
|
||||
|
||||
import GlobalApi from '~/logic/api/global';
|
||||
@ -30,20 +32,21 @@ const DEFAULT_BACKLOG_SIZE = 100;
|
||||
const IDLE_THRESHOLD = 64;
|
||||
const MAX_BACKLOG_SIZE = 1000;
|
||||
|
||||
type ChatWindowProps = RouteComponentProps<{
|
||||
ship: Patp;
|
||||
station: string;
|
||||
}> & {
|
||||
|
||||
type ChatWindowProps = {
|
||||
unreadCount: number;
|
||||
graph: Graph;
|
||||
graphSize: number;
|
||||
association: Association;
|
||||
group: Group;
|
||||
ship: Patp;
|
||||
station: any;
|
||||
fetchMessages: (newer: boolean) => Promise<boolean>;
|
||||
api: GlobalApi;
|
||||
scrollTo?: BigInteger;
|
||||
onReply: (msg: Post) => void;
|
||||
dismissUnread: () => void;
|
||||
pendingSize?: number;
|
||||
showOurContact: boolean;
|
||||
getPermalink: (index: BigInteger) => string;
|
||||
isAdmin: boolean;
|
||||
};
|
||||
|
||||
interface ChatWindowState {
|
||||
@ -55,12 +58,12 @@ interface ChatWindowState {
|
||||
|
||||
const virtScrollerStyle = { height: '100%' };
|
||||
|
||||
|
||||
class ChatWindow extends Component<
|
||||
ChatWindowProps,
|
||||
ChatWindowState
|
||||
> {
|
||||
private virtualList: VirtualScroller | null;
|
||||
private unreadMarkerRef: React.RefObject<HTMLDivElement>;
|
||||
private virtualList: VirtualScroller<GraphNode> | null;
|
||||
private prevSize = 0;
|
||||
private unreadSet = false;
|
||||
|
||||
@ -76,14 +79,12 @@ class ChatWindow extends Component<
|
||||
unreadIndex: bigInt.zero
|
||||
};
|
||||
|
||||
this.dismissUnread = this.dismissUnread.bind(this);
|
||||
this.scrollToUnread = this.scrollToUnread.bind(this);
|
||||
this.handleWindowBlur = this.handleWindowBlur.bind(this);
|
||||
this.handleWindowFocus = this.handleWindowFocus.bind(this);
|
||||
this.stayLockedIfActive = this.stayLockedIfActive.bind(this);
|
||||
|
||||
this.virtualList = null;
|
||||
this.unreadMarkerRef = React.createRef();
|
||||
this.prevSize = props.graph.size;
|
||||
}
|
||||
|
||||
@ -92,10 +93,9 @@ class ChatWindow extends Component<
|
||||
setTimeout(() => {
|
||||
this.setState({ initialized: true }, () => {
|
||||
if(this.props.scrollTo) {
|
||||
this.virtualList.scrollToIndex(this.props.scrollTo);
|
||||
|
||||
this.virtualList!.scrollLocked = false;
|
||||
this.virtualList!.scrollToIndex(this.props.scrollTo);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}, this.INITIALIZATION_MAX_TIME);
|
||||
@ -109,9 +109,11 @@ class ChatWindow extends Component<
|
||||
}
|
||||
const unreadIndex = graph.keys()[unreadCount];
|
||||
if (!unreadIndex || unreadCount === 0) {
|
||||
this.setState({
|
||||
unreadIndex: bigInt.zero
|
||||
});
|
||||
if(state.unreadIndex.neq(bigInt.zero)) {
|
||||
this.setState({
|
||||
unreadIndex: bigInt.zero
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
@ -122,8 +124,8 @@ class ChatWindow extends Component<
|
||||
dismissedInitialUnread() {
|
||||
const { unreadCount, graph } = this.props;
|
||||
|
||||
return this.state.unreadIndex.neq(bigInt.zero) &&
|
||||
this.state.unreadIndex.neq(graph.keys()?.[unreadCount]?.[0] ?? bigInt.zero);
|
||||
return this.state.unreadIndex.eq(bigInt.zero) ? unreadCount > graph.size :
|
||||
this.state.unreadIndex.neq(graph.keys()?.[unreadCount]?.[0] ?? bigInt.zero);
|
||||
}
|
||||
|
||||
handleWindowBlur() {
|
||||
@ -133,12 +135,12 @@ class ChatWindow extends Component<
|
||||
handleWindowFocus() {
|
||||
this.setState({ idle: false });
|
||||
if (this.virtualList?.window?.scrollTop === 0) {
|
||||
this.dismissUnread();
|
||||
this.props.dismissUnread();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: ChatWindowProps, prevState) {
|
||||
const { history, graph, unreadCount, graphSize, station } = this.props;
|
||||
const { graph, unreadCount, graphSize, station } = this.props;
|
||||
if(unreadCount === 0 && prevProps.unreadCount !== unreadCount) {
|
||||
this.unreadSet = true;
|
||||
}
|
||||
@ -150,8 +152,8 @@ class ChatWindow extends Component<
|
||||
}
|
||||
if(this.unreadSet &&
|
||||
this.dismissedInitialUnread() &&
|
||||
this.virtualList?.startOffset() < 5) {
|
||||
this.dismissUnread();
|
||||
this.virtualList!.startOffset() < 5) {
|
||||
this.props.dismissUnread();
|
||||
}
|
||||
|
||||
}
|
||||
@ -169,7 +171,7 @@ class ChatWindow extends Component<
|
||||
stayLockedIfActive() {
|
||||
if (this.virtualList && !this.state.idle) {
|
||||
this.virtualList.resetScroll();
|
||||
this.dismissUnread();
|
||||
this.props.dismissUnread();
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,45 +190,6 @@ class ChatWindow extends Component<
|
||||
this.virtualList?.scrollToIndex(this.state.unreadIndex);
|
||||
}
|
||||
|
||||
dismissUnread() {
|
||||
const { association } = this.props;
|
||||
if (this.state.fetchPending) return;
|
||||
if (this.props.unreadCount === 0) return;
|
||||
this.props.api.hark.markCountAsRead(association, '/', 'message');
|
||||
}
|
||||
|
||||
setActive = () => {
|
||||
if(this.state.idle) {
|
||||
this.setState({ idle: false });
|
||||
}
|
||||
}
|
||||
|
||||
fetchMessages = async (newer: boolean): Promise<boolean> => {
|
||||
const { api, station, graph } = this.props;
|
||||
const pageSize = 100;
|
||||
|
||||
const [, , ship, name] = station.split('/');
|
||||
const expectedSize = graph.size + pageSize;
|
||||
if (newer) {
|
||||
const [index] = graph.peekLargest()!;
|
||||
await api.graph.getYoungerSiblings(
|
||||
ship,
|
||||
name,
|
||||
pageSize,
|
||||
`/${index.toString()}`
|
||||
);
|
||||
return expectedSize !== graph.size;
|
||||
} else {
|
||||
const [index] = graph.peekSmallest()!;
|
||||
await api.graph.getOlderSiblings(ship, name, pageSize, `/${index.toString()}`);
|
||||
const done = expectedSize !== graph.size;
|
||||
if(done) {
|
||||
this.calculateUnreadIndex();
|
||||
}
|
||||
return done;
|
||||
}
|
||||
}
|
||||
|
||||
onScroll = ({ scrollTop, scrollHeight, windowHeight }) => {
|
||||
if (!this.state.idle && scrollTop > IDLE_THRESHOLD) {
|
||||
this.setState({ idle: true });
|
||||
@ -237,26 +200,21 @@ class ChatWindow extends Component<
|
||||
renderer = React.forwardRef(({ index, scrollWindow }, ref) => {
|
||||
const {
|
||||
api,
|
||||
association,
|
||||
group,
|
||||
showOurContact,
|
||||
graph,
|
||||
history,
|
||||
groups,
|
||||
associations,
|
||||
onReply
|
||||
onReply,
|
||||
getPermalink,
|
||||
dismissUnread,
|
||||
isAdmin,
|
||||
} = this.props;
|
||||
const { unreadMarkerRef } = this;
|
||||
const permalink = getPermalink(index);
|
||||
const messageProps = {
|
||||
association,
|
||||
group,
|
||||
showOurContact,
|
||||
unreadMarkerRef,
|
||||
history,
|
||||
api,
|
||||
groups,
|
||||
associations,
|
||||
onReply
|
||||
onReply,
|
||||
permalink,
|
||||
dismissUnread,
|
||||
isAdmin
|
||||
};
|
||||
|
||||
const msg = graph.get(index)?.post;
|
||||
@ -275,10 +233,10 @@ class ChatWindow extends Component<
|
||||
graph.peekLargest()?.[0] ?? bigInt.zero
|
||||
);
|
||||
const highlighted = index.eq(this.props.scrollTo ?? bigInt.zero);
|
||||
const keys = graph.keys().reverse();
|
||||
const keys = graph.keys();
|
||||
const graphIdx = keys.findIndex((idx) => idx.eq(index));
|
||||
const prevIdx = keys[graphIdx + 1];
|
||||
const nextIdx = keys[graphIdx - 1];
|
||||
const prevIdx = keys[graphIdx - 1];
|
||||
const nextIdx = keys[graphIdx + 1];
|
||||
const isLastRead: boolean = this.state.unreadIndex.eq(index);
|
||||
const props = {
|
||||
highlighted,
|
||||
@ -305,32 +263,13 @@ class ChatWindow extends Component<
|
||||
const {
|
||||
unreadCount,
|
||||
api,
|
||||
association,
|
||||
group,
|
||||
graph,
|
||||
history,
|
||||
groups,
|
||||
associations,
|
||||
showOurContact,
|
||||
pendingSize,
|
||||
onReply,
|
||||
pendingSize = 0,
|
||||
} = this.props;
|
||||
|
||||
const unreadMarkerRef = this.unreadMarkerRef;
|
||||
const messageProps = {
|
||||
association,
|
||||
group,
|
||||
unreadMarkerRef,
|
||||
history,
|
||||
api,
|
||||
associations
|
||||
};
|
||||
const unreadMsg = graph.get(this.state.unreadIndex);
|
||||
|
||||
// hack to force a re-render when we toggle showing contact
|
||||
const contactsModified =
|
||||
showOurContact ? 0 : 100;
|
||||
|
||||
|
||||
return (
|
||||
<Col height='100%' overflow='hidden' position='relative'>
|
||||
{ this.dismissedInitialUnread() &&
|
||||
@ -343,34 +282,29 @@ class ChatWindow extends Component<
|
||||
? false
|
||||
: unreadMsg
|
||||
}
|
||||
dismissUnread={this.dismissUnread}
|
||||
dismissUnread={this.props.dismissUnread}
|
||||
onClick={this.scrollToUnread}
|
||||
/>)}
|
||||
<VirtualScroller
|
||||
<VirtualScroller<GraphNode>
|
||||
ref={(list) => {
|
||||
this.virtualList = list;
|
||||
}}
|
||||
offset={unreadCount}
|
||||
origin='bottom'
|
||||
style={virtScrollerStyle}
|
||||
onStartReached={this.setActive}
|
||||
onBottomLoaded={this.onBottomLoaded}
|
||||
onScroll={this.onScroll}
|
||||
data={graph}
|
||||
size={graph.size}
|
||||
pendingSize={pendingSize + contactsModified}
|
||||
id={association.resource}
|
||||
pendingSize={pendingSize}
|
||||
averageHeight={22}
|
||||
renderer={this.renderer}
|
||||
loadRows={this.fetchMessages}
|
||||
loadRows={this.props.fetchMessages}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withState(ChatWindow, [
|
||||
[useGroupState, ['groups']],
|
||||
[useMetadataState, ['associations']],
|
||||
[useGraphState, ['pendingSize']]
|
||||
]);
|
||||
|
||||
export default ChatWindow
|
||||
|
@ -40,27 +40,27 @@ export const ShareProfile = (props) => {
|
||||
);
|
||||
|
||||
const onClick = async () => {
|
||||
if(group.hidden && recipients.length > 0) {
|
||||
await api.contacts.allowShips(recipients);
|
||||
await Promise.all(recipients.map(r => api.contacts.share(r)))
|
||||
setShowBanner(false);
|
||||
} else if (!group.hidden) {
|
||||
const [,,ship,name] = groupPath.split('/');
|
||||
if(typeof recipients === 'string') {
|
||||
const [,,ship,name] = recipients.split('/');
|
||||
await api.contacts.allowGroup(ship,name);
|
||||
if(ship !== `~${window.ship}`) {
|
||||
await api.contacts.share(ship);
|
||||
}
|
||||
setShowBanner(false);
|
||||
}
|
||||
} else if(recipients.length > 0) {
|
||||
await api.contacts.allowShips(recipients);
|
||||
await Promise.all(recipients.map(r => api.contacts.share(r)))
|
||||
}
|
||||
props.onShare();
|
||||
};
|
||||
|
||||
return showBanner ? (
|
||||
return props.recipients?.length > 0 ? (
|
||||
<Row
|
||||
height="48px"
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
borderBottom={1}
|
||||
borderColor="lightGray"
|
||||
flexShrink={0}
|
||||
>
|
||||
<Row pl={3} alignItems="center">
|
||||
{image}
|
||||
|
@ -162,6 +162,7 @@ export default class ChatEditor extends Component {
|
||||
editor.showHint(['test', 'foo']);
|
||||
}
|
||||
if (this.state.message !== '' && value == '') {
|
||||
this.props.changeEvent(value);
|
||||
this.setState({
|
||||
message: value
|
||||
});
|
||||
@ -169,6 +170,7 @@ export default class ChatEditor extends Component {
|
||||
if (value == this.props.message || value == '' || value == ' ') {
|
||||
return;
|
||||
}
|
||||
this.props.changeEvent(value);
|
||||
this.setState({
|
||||
message: value
|
||||
});
|
||||
@ -238,17 +240,12 @@ export default class ChatEditor extends Component {
|
||||
rows="1"
|
||||
style={{ width: '100%', background: 'transparent', color: 'currentColor' }}
|
||||
placeholder={inCodeMode ? "Code..." : "Message..."}
|
||||
onChange={event => {
|
||||
this.messageChange(null, null, event.target.value);
|
||||
}}
|
||||
onKeyDown={event => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
this.submit();
|
||||
} else {
|
||||
this.messageChange(null, null, event.target.value);
|
||||
}
|
||||
}}
|
||||
onChange={event =>
|
||||
this.messageChange(null, null, event.target.value)
|
||||
}
|
||||
onKeyDown={event =>
|
||||
this.messageChange(null, null, event.target.value)
|
||||
}
|
||||
ref={input => {
|
||||
if (!input) return;
|
||||
this.editor = inputProxy(input);
|
||||
|
@ -8,22 +8,11 @@ import Timestamp from '~/views/components/Timestamp';
|
||||
export const UnreadNotice = (props) => {
|
||||
const { unreadCount, unreadMsg, dismissUnread, onClick } = props;
|
||||
|
||||
if (!unreadMsg || unreadCount === 0) {
|
||||
if (unreadCount === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const stamp = moment.unix(unreadMsg.post['time-sent'] / 1000);
|
||||
|
||||
let datestamp = moment
|
||||
.unix(unreadMsg.post['time-sent'] / 1000)
|
||||
.format('YYYY.M.D');
|
||||
const timestamp = moment
|
||||
.unix(unreadMsg.post['time-sent'] / 1000)
|
||||
.format('HH:mm');
|
||||
|
||||
if (datestamp === moment().format('YYYY.M.D')) {
|
||||
datestamp = null;
|
||||
}
|
||||
const stamp = unreadMsg && moment.unix(unreadMsg.post['time-sent'] / 1000);
|
||||
|
||||
return (
|
||||
<Box
|
||||
@ -52,15 +41,20 @@ export const UnreadNotice = (props) => {
|
||||
whiteSpace='pre'
|
||||
overflow='hidden'
|
||||
display='flex'
|
||||
cursor='pointer'
|
||||
cursor={unreadMsg ? 'pointer' : null}
|
||||
onClick={onClick}
|
||||
>
|
||||
{unreadCount} new message{unreadCount > 1 ? 's' : ''} since{' '}
|
||||
<Timestamp stamp={stamp} color='black' date={true} fontSize={1} />
|
||||
{unreadCount} new message{unreadCount > 1 ? 's' : ''}
|
||||
{unreadMsg && (
|
||||
<>
|
||||
{' '}since{' '}
|
||||
<Timestamp stamp={stamp} color='black' date={true} fontSize={1} />
|
||||
</>
|
||||
)}
|
||||
</Text>
|
||||
<Icon
|
||||
icon='X'
|
||||
ml='4'
|
||||
ml={unreadMsg ? 4 : 1}
|
||||
color='black'
|
||||
cursor='pointer'
|
||||
textAlign='right'
|
||||
|
@ -23,7 +23,7 @@ type LinkResourceProps = StoreState & {
|
||||
association: Association;
|
||||
api: GlobalApi;
|
||||
baseUrl: string;
|
||||
} & RouteComponentProps;
|
||||
};
|
||||
|
||||
export function LinkResource(props: LinkResourceProps) {
|
||||
const {
|
||||
|
@ -6,7 +6,7 @@ import React, {
|
||||
Component,
|
||||
} from "react";
|
||||
|
||||
import { Col, Text } from "@tlon/indigo-react";
|
||||
import { Box, Col, Text } from "@tlon/indigo-react";
|
||||
import bigInt from "big-integer";
|
||||
import { Association, Graph, Unreads, Group, Rolodex } from "@urbit/api";
|
||||
|
||||
@ -48,7 +48,7 @@ class LinkWindow extends Component<LinkWindowProps, {}> {
|
||||
return isWriter(group, association.resource);
|
||||
}
|
||||
|
||||
renderItem = ({ index, scrollWindow }) => {
|
||||
renderItem = React.forwardRef(({ index, scrollWindow }, ref) => {
|
||||
const { props } = this;
|
||||
const { association, graph, api } = props;
|
||||
const [, , ship, name] = association.resource.split("/");
|
||||
@ -66,6 +66,7 @@ class LinkWindow extends Component<LinkWindowProps, {}> {
|
||||
return (
|
||||
<React.Fragment key={index.toString()}>
|
||||
<Col
|
||||
ref={ref}
|
||||
key={index.toString()}
|
||||
mx="auto"
|
||||
mt="4"
|
||||
@ -80,12 +81,20 @@ class LinkWindow extends Component<LinkWindowProps, {}> {
|
||||
api={api}
|
||||
/>
|
||||
</Col>
|
||||
<LinkItem {...linkProps} />
|
||||
{ typeof post !== 'string' && <LinkItem {...linkProps} /> }
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
return <LinkItem key={index.toString()} {...linkProps} />;
|
||||
};
|
||||
|
||||
if (typeof post === 'string') {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Box ref={ref}>
|
||||
<LinkItem key={index.toString()} {...linkProps} />;
|
||||
</Box>
|
||||
);
|
||||
});
|
||||
|
||||
render() {
|
||||
const { graph, api, association } = this.props;
|
||||
@ -136,4 +145,4 @@ class LinkWindow extends Component<LinkWindowProps, {}> {
|
||||
}
|
||||
}
|
||||
|
||||
export default LinkWindow;
|
||||
export default LinkWindow;
|
||||
|
@ -19,7 +19,7 @@ interface LinkItemProps {
|
||||
node: GraphNode;
|
||||
association: Association;
|
||||
resource: string; api: GlobalApi; group: Group; path: string; }
|
||||
export const LinkItem = (props: LinkItemProps): ReactElement => {
|
||||
export const LinkItem = React.forwardRef((props: LinkItemProps, ref): ReactElement => {
|
||||
const {
|
||||
association,
|
||||
node,
|
||||
@ -30,7 +30,6 @@ export const LinkItem = (props: LinkItemProps): ReactElement => {
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const ref = useRef<HTMLDivElement | null>(null);
|
||||
const remoteRef = useRef<typeof RemoteContent | null>(null);
|
||||
const index = node.post.index.split('/')[1];
|
||||
|
||||
@ -86,10 +85,10 @@ export const LinkItem = (props: LinkItemProps): ReactElement => {
|
||||
permalink,
|
||||
'Copy reference'
|
||||
);
|
||||
|
||||
|
||||
const deleteLink = () => {
|
||||
if (confirm('Are you sure you want to delete this link?')) {
|
||||
api.graph.removeNodes(`~${ship}`, name, [node.post.index]);
|
||||
api.graph.removePosts(`~${ship}`, name, [node.post.index]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -167,9 +166,11 @@ export const LinkItem = (props: LinkItemProps): ReactElement => {
|
||||
<Row minWidth='0' flexShrink={0} width="100%" justifyContent="space-between" py={3} bg="white">
|
||||
<Author
|
||||
showImage
|
||||
isRelativeTime
|
||||
ship={author}
|
||||
date={node.post['time-sent']}
|
||||
group={group}
|
||||
lineHeight="1"
|
||||
/>
|
||||
<Box ml="auto">
|
||||
<Link
|
||||
@ -208,5 +209,5 @@ export const LinkItem = (props: LinkItemProps): ReactElement => {
|
||||
|
||||
</Row>
|
||||
</Box>);
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -4,6 +4,7 @@ import ChatMessage from "../chat/components/ChatMessage";
|
||||
import { Association, GraphNode, Post, Group } from "@urbit/api";
|
||||
import { useGroupForAssoc } from "~/logic/state/group";
|
||||
import { MentionText } from "~/views/components/MentionText";
|
||||
import { GraphContentWide } from '~/views/landscape/components/Graph/GraphContentWide';
|
||||
import Author from "~/views/components/Author";
|
||||
import { NoteContent } from "../publish/components/Note";
|
||||
import { PostContent } from "~/views/landscape/components/Home/Post/PostContent";
|
||||
@ -31,7 +32,7 @@ function TranscludedLinkNode(props: {
|
||||
return <PermalinkEmbed transcluded={transcluded + 1} api={api} link={permalink} association={assoc} />
|
||||
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Box borderRadius="2" p="2" bg="scales.black05">
|
||||
<Anchor underline={false} target="_blank" color="black" href={link.url}>
|
||||
@ -74,11 +75,11 @@ function TranscludedComment(props: {
|
||||
group={group}
|
||||
/>
|
||||
<Box p="2">
|
||||
<MentionText
|
||||
<GraphContentWide
|
||||
api={api}
|
||||
transcluded={transcluded}
|
||||
content={comment.post.contents}
|
||||
group={group}
|
||||
post={comment.post}
|
||||
showOurContact={false}
|
||||
/>
|
||||
</Box>
|
||||
</Col>
|
||||
@ -200,8 +201,8 @@ export function TranscludedNode(props: {
|
||||
<TranscludedPost
|
||||
api={props.api}
|
||||
post={node.post}
|
||||
group={group}
|
||||
transcluded={transcluded}
|
||||
group={group}
|
||||
transcluded={transcluded}
|
||||
/>)
|
||||
;
|
||||
default:
|
||||
|
@ -11,7 +11,7 @@ type PublishResourceProps = StoreState & {
|
||||
association: Association;
|
||||
api: GlobalApi;
|
||||
baseUrl: string;
|
||||
} & RouteComponentProps;
|
||||
};
|
||||
|
||||
export function PublishResource(props: PublishResourceProps) {
|
||||
const { association, api, baseUrl, notebooks } = props;
|
||||
|
@ -54,7 +54,7 @@ export function Note(props: NoteProps & RouteComponentProps) {
|
||||
const deletePost = async () => {
|
||||
setDeleting(true);
|
||||
const indices = [note.post.index];
|
||||
await api.graph.removeNodes(ship, book, indices);
|
||||
await api.graph.removePosts(ship, book, indices);
|
||||
props.history.push(rootUrl);
|
||||
};
|
||||
|
||||
@ -115,11 +115,12 @@ export function Note(props: NoteProps & RouteComponentProps) {
|
||||
<Row alignItems="center">
|
||||
<Author
|
||||
showImage
|
||||
isRelativeTime
|
||||
ship={post?.author}
|
||||
date={post?.['time-sent']}
|
||||
group={group}
|
||||
>
|
||||
<Row px="2" gapX="2" alignItems="flex-end">
|
||||
<Row px="2" gapX="2" alignItems="flex-end" height="14px">
|
||||
<Action bg="white" onClick={doCopy}>{copyDisplay}</Action>
|
||||
{adminLinks}
|
||||
</Row>
|
||||
|
@ -51,7 +51,7 @@ export function NotePreviewContent({ snippet }) {
|
||||
export function NotePreview(props: NotePreviewProps) {
|
||||
const { node, group } = props;
|
||||
const { post } = node;
|
||||
if (!post) {
|
||||
if (!post || typeof post === 'string') {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ interface AuthorProps {
|
||||
unread?: boolean;
|
||||
api?: GlobalApi;
|
||||
size?: number;
|
||||
lineHeight?: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
@ -38,10 +39,11 @@ export default function Author(props: AuthorProps & PropFunc<typeof Box>): React
|
||||
group,
|
||||
isRelativeTime,
|
||||
dontShowTime,
|
||||
lineHeight = 'tall',
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const time = props.time || false;
|
||||
const time = props.time || props.date || false;
|
||||
const size = props.size || 16;
|
||||
const sigilPadding = props.sigilPadding || 2;
|
||||
|
||||
@ -89,7 +91,7 @@ export default function Author(props: AuthorProps & PropFunc<typeof Box>): React
|
||||
) : sigil;
|
||||
|
||||
return (
|
||||
<Row height="20px" {...rest} alignItems='center' width='auto'>
|
||||
<Row {...rest} alignItems='center' width='auto'>
|
||||
<Box
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
@ -110,7 +112,7 @@ export default function Author(props: AuthorProps & PropFunc<typeof Box>): React
|
||||
color='black'
|
||||
fontSize='1'
|
||||
cursor='pointer'
|
||||
lineHeight='tall'
|
||||
lineHeight={lineHeight}
|
||||
fontFamily={showNickname ? 'sans' : 'mono'}
|
||||
fontWeight={showNickname ? '500' : '400'}
|
||||
mr={showNickname ? 0 : "2px"}
|
||||
@ -121,6 +123,7 @@ export default function Author(props: AuthorProps & PropFunc<typeof Box>): React
|
||||
</Box>
|
||||
{ !dontShowTime && time && (
|
||||
<Timestamp
|
||||
height="fit-content"
|
||||
relative={isRelativeTime}
|
||||
stamp={stamp}
|
||||
fontSize={1}
|
||||
|
@ -73,7 +73,7 @@ export function ColorInput(props: ColorInputProps) {
|
||||
height='100%'
|
||||
alignSelf='stretch'
|
||||
onChange={onChange}
|
||||
value={`#${padded}`}
|
||||
value={padded}
|
||||
disabled={disabled || false}
|
||||
type='color'
|
||||
opacity={0}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React, {useEffect, useRef, useCallback} from 'react';
|
||||
import { Link, useHistory } from 'react-router-dom';
|
||||
import styled from 'styled-components';
|
||||
import bigInt from 'big-integer';
|
||||
|
||||
import { Box, Row, Text, Action } from '@tlon/indigo-react';
|
||||
import { Contacts } from '@urbit/api/contacts';
|
||||
@ -35,18 +36,44 @@ interface CommentItemProps {
|
||||
}
|
||||
|
||||
export function CommentItem(props: CommentItemProps): ReactElement {
|
||||
let { highlighted } = props;
|
||||
const { ship, name, api, comment, group } = props;
|
||||
const association = useMetadataState(
|
||||
useCallback(s => s.associations.graph[`/ship/${ship}/${name}`], [ship,name])
|
||||
);
|
||||
const ref = useRef<HTMLElement | null>(null);
|
||||
console.log(comment);
|
||||
const [, post] = getLatestCommentRevision(comment);
|
||||
const disabled = props.pending;
|
||||
|
||||
const onDelete = async () => {
|
||||
await api.graph.removeNodes(ship, name, [comment.post?.index]);
|
||||
const revs = comment.children.get(bigInt(1));
|
||||
const children = Array.from(revs.children);
|
||||
let indices = [];
|
||||
for (let child in children) {
|
||||
let node = children[child];
|
||||
if (!node?.post || typeof node.post !== 'string') {
|
||||
indices.push(node.post?.index);
|
||||
}
|
||||
}
|
||||
|
||||
await api.graph.removePosts(ship, name, [
|
||||
comment.post?.index,
|
||||
revs?.post?.index,
|
||||
...indices
|
||||
]);
|
||||
};
|
||||
|
||||
const ourMention = post?.contents?.some((e) => {
|
||||
return e?.mention && e?.mention === window.ship;
|
||||
});
|
||||
|
||||
if (!highlighted) {
|
||||
if (ourMention) {
|
||||
highlighted = true;
|
||||
}
|
||||
}
|
||||
|
||||
const commentIndexArray = (comment.post?.index || '/').split('/');
|
||||
const commentIndex = commentIndexArray[commentIndexArray.length - 1];
|
||||
|
||||
@ -81,11 +108,16 @@ export function CommentItem(props: CommentItemProps): ReactElement {
|
||||
getPermalinkForGraph(
|
||||
association.group,
|
||||
association.resource,
|
||||
post.index.split('/').slice(0, -1).join('/')
|
||||
post?.index?.split('/').slice(0, -1).join('/')
|
||||
),
|
||||
'Copy Link'
|
||||
);
|
||||
|
||||
if (!post || typeof post === 'string') {
|
||||
// TODO: if typeof post === 'string', show some deleted state
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box ref={ref} mb={4} opacity={post?.pending ? '60%' : '100%'}>
|
||||
<Row px="1" my={3}>
|
||||
@ -95,6 +127,7 @@ export function CommentItem(props: CommentItemProps): ReactElement {
|
||||
date={post?.['time-sent']}
|
||||
unread={props.unread}
|
||||
group={group}
|
||||
isRelativeTime
|
||||
>
|
||||
<Row px="2" gapX="2" height="18px">
|
||||
<Action bg="white" onClick={doCopy}>{copyDisplay}</Action>
|
||||
@ -106,7 +139,7 @@ export function CommentItem(props: CommentItemProps): ReactElement {
|
||||
borderRadius="1"
|
||||
p="1"
|
||||
mb="1"
|
||||
backgroundColor={props.highlighted ? 'washedBlue' : 'white'}
|
||||
backgroundColor={highlighted ? 'washedBlue' : 'white'}
|
||||
transcluded={0}
|
||||
api={api}
|
||||
post={post}
|
||||
|
@ -130,7 +130,7 @@ export function Comments(props: CommentsProps & PropFunc<typeof Col>) {
|
||||
const canComment = isWriter(group, association.resource) || association.metadata.vip === 'reader-comments';
|
||||
|
||||
return (
|
||||
<Col {...rest}>
|
||||
<Col {...rest} minWidth='0'>
|
||||
{( !editCommentId && canComment ? <CommentInput onSubmit={onSubmit} /> : null )}
|
||||
{( editCommentId ? (
|
||||
<CommentInput
|
||||
|
@ -23,6 +23,7 @@ import RichText from './RichText';
|
||||
import { ProfileStatus } from './ProfileStatus';
|
||||
import useSettingsState from '~/logic/state/settings';
|
||||
import {useOutsideClick} from '~/logic/lib/useOutsideClick';
|
||||
import {useCopy} from '~/logic/lib/useCopy';
|
||||
import {useContact} from '~/logic/state/contact';
|
||||
import {useHistory} from 'react-router-dom';
|
||||
import {Portal} from './Portal';
|
||||
@ -59,6 +60,7 @@ const ProfileOverlay = (props: ProfileOverlayProps) => {
|
||||
const hideAvatars = useSettingsState(state => state.calm.hideAvatars);
|
||||
const hideNicknames = useSettingsState(state => state.calm.hideNicknames);
|
||||
const isOwn = useMemo(() => window.ship === ship, [ship]);
|
||||
const { copyDisplay, doCopy, didCopy } = useCopy(`~${ship}`);
|
||||
|
||||
const contact = useContact(`~${ship}`)
|
||||
const color = `#${uxToHex(contact?.color ?? '0x0')}`;
|
||||
@ -188,9 +190,18 @@ const ProfileOverlay = (props: ProfileOverlayProps) => {
|
||||
overflow='hidden'
|
||||
whiteSpace='pre'
|
||||
marginBottom='0'
|
||||
cursor='pointer'
|
||||
display={didCopy ? 'none' : 'block'}
|
||||
onClick={doCopy}
|
||||
>
|
||||
{showNickname ? contact?.nickname : cite(ship)}
|
||||
</Text>
|
||||
<Text
|
||||
fontWeight='600'
|
||||
marginBottom='0'
|
||||
>
|
||||
{copyDisplay}
|
||||
</Text>
|
||||
</Row>
|
||||
{isOwn ? (
|
||||
<ProfileStatus
|
||||
|
@ -48,12 +48,14 @@ class RemoteContent extends Component<RemoteContentProps, RemoteContentState> {
|
||||
this.state = {
|
||||
unfold: props.unfold || false,
|
||||
embed: undefined,
|
||||
noCors: false
|
||||
noCors: false,
|
||||
showArrow: false
|
||||
};
|
||||
this.unfoldEmbed = this.unfoldEmbed.bind(this);
|
||||
this.loadOembed = this.loadOembed.bind(this);
|
||||
this.wrapInLink = this.wrapInLink.bind(this);
|
||||
this.onError = this.onError.bind(this);
|
||||
this.toggleArrow = this.toggleArrow.bind(this);
|
||||
}
|
||||
|
||||
save = () => {
|
||||
@ -128,7 +130,7 @@ return;
|
||||
});
|
||||
}
|
||||
|
||||
wrapInLink(contents, textOnly = false, unfold = false, unfoldEmbed = null, embedContainer = null) {
|
||||
wrapInLink(contents, textOnly = false, unfold = false, unfoldEmbed = null, embedContainer = null, flushPadding = false, noOp = false) {
|
||||
const { style } = this.props;
|
||||
return (
|
||||
<Box borderRadius="1" backgroundColor="washedGray" maxWidth="min(100%, 20rem)">
|
||||
@ -145,8 +147,8 @@ return;
|
||||
)}
|
||||
<BaseAnchor
|
||||
display="flex"
|
||||
p="2"
|
||||
onClick={(e) => { e.stopPropagation(); }}
|
||||
p={flushPadding ? 0 : 2}
|
||||
onClick={(e) => { noOp ? e.preventDefault() : e.stopPropagation() }}
|
||||
href={this.props.url}
|
||||
whiteSpace="nowrap"
|
||||
overflow="hidden"
|
||||
@ -157,7 +159,8 @@ return;
|
||||
style={{ color: 'inherit', textDecoration: 'none', ...style }}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
cursor={noOp ? 'default' : 'pointer'}
|
||||
>
|
||||
{contents}
|
||||
</BaseAnchor>
|
||||
</Row>
|
||||
@ -171,11 +174,16 @@ return;
|
||||
this.setState({ noCors: true });
|
||||
}
|
||||
|
||||
toggleArrow() {
|
||||
this.setState({showArrow: !this.state.showArrow})
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
remoteContentPolicy,
|
||||
url,
|
||||
text,
|
||||
transcluded,
|
||||
renderUrl = true,
|
||||
imageProps = {},
|
||||
audioProps = {},
|
||||
@ -192,22 +200,60 @@ return;
|
||||
const isVideo = VIDEO_REGEX.test(url);
|
||||
const isOembed = hasProvider(url);
|
||||
|
||||
const isTranscluded = () => {
|
||||
return transcluded;
|
||||
}
|
||||
|
||||
if (isImage && remoteContentPolicy.imageShown) {
|
||||
return this.wrapInLink(
|
||||
<BaseImage
|
||||
{...(noCors ? {} : { crossOrigin: "anonymous" })}
|
||||
referrerPolicy="no-referrer"
|
||||
flexShrink={0}
|
||||
src={url}
|
||||
style={style}
|
||||
onLoad={onLoad}
|
||||
onError={this.onError}
|
||||
height="100%"
|
||||
width="100%"
|
||||
objectFit="contain"
|
||||
{...imageProps}
|
||||
{...props}
|
||||
/>
|
||||
<Box
|
||||
position='relative'
|
||||
onMouseEnter={this.toggleArrow}
|
||||
onMouseLeave={this.toggleArrow}
|
||||
>
|
||||
<BaseAnchor
|
||||
position='absolute'
|
||||
top={2}
|
||||
right={2}
|
||||
display={this.state.showArrow ? 'block' : 'none'}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
href={url}
|
||||
>
|
||||
<Box
|
||||
backgroundColor='white'
|
||||
padding={2}
|
||||
borderRadius='50%'
|
||||
display='flex'
|
||||
>
|
||||
<Icon icon='ArrowNorthEast' />
|
||||
</Box>
|
||||
</BaseAnchor>
|
||||
<BaseImage
|
||||
{...(noCors ? {} : { crossOrigin: 'anonymous' })}
|
||||
referrerPolicy='no-referrer'
|
||||
flexShrink={0}
|
||||
src={url}
|
||||
style={style}
|
||||
onLoad={onLoad}
|
||||
onError={this.onError}
|
||||
height='100%'
|
||||
width='100%'
|
||||
objectFit='contain'
|
||||
borderRadius={2}
|
||||
{...imageProps}
|
||||
{...props}
|
||||
/>
|
||||
</Box>,
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
isTranscluded()
|
||||
);
|
||||
} else if (isAudio && remoteContentPolicy.audioShown) {
|
||||
return (
|
||||
@ -271,7 +317,6 @@ return;
|
||||
display={this.state.unfold ? 'block' : 'none'}
|
||||
className='embed-container'
|
||||
style={style}
|
||||
flexShrink={0}
|
||||
onLoad={this.onLoad}
|
||||
{...oembedProps}
|
||||
{...props}
|
||||
|
@ -141,7 +141,7 @@ const StatusBar = (props) => {
|
||||
mr={2}
|
||||
onClick={() => props.history.push('/~landscape/messages')}
|
||||
>
|
||||
<Icon icon='Users' />
|
||||
<Icon icon='Messages' />
|
||||
</StatusBarItem>
|
||||
<Dropdown
|
||||
dropWidth='250px'
|
||||
|
@ -12,6 +12,7 @@ export type TimestampProps = BoxProps & {
|
||||
date?: boolean;
|
||||
time?: boolean;
|
||||
relative?: boolean;
|
||||
height?: string;
|
||||
};
|
||||
|
||||
const Timestamp = (props: TimestampProps): ReactElement | null => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { Component, useCallback } from 'react';
|
||||
import React, { Component, useCallback, SyntheticEvent } from 'react';
|
||||
import _ from 'lodash';
|
||||
import normalizeWheel from 'normalize-wheel';
|
||||
import bigInt, { BigInteger } from 'big-integer';
|
||||
@ -76,7 +76,7 @@ interface VirtualScrollerProps<T> {
|
||||
}
|
||||
|
||||
interface VirtualScrollerState<T> {
|
||||
visibleItems: BigIntOrderedMap<T>;
|
||||
visibleItems: BigInteger[];
|
||||
scrollbar: number;
|
||||
loaded: {
|
||||
top: boolean;
|
||||
@ -91,10 +91,9 @@ const log = (level: LogLevel, message: string) => {
|
||||
if(logLevel.includes(level)) {
|
||||
console.log(`[${level}]: ${message}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const ZONE_SIZE = IS_IOS ? 10 : 40;
|
||||
const ZONE_SIZE = IS_IOS ? 20 : 80;
|
||||
|
||||
|
||||
// nb: in this file, an index refers to a BigInteger and an offset refers to a
|
||||
@ -114,7 +113,7 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
/**
|
||||
* A map of child refs, used to calculate scroll position
|
||||
*/
|
||||
private childRefs = new BigIntOrderedMap<HTMLElement>();
|
||||
private childRefs = new Map<string, HTMLElement>();
|
||||
/**
|
||||
* A set of child refs which have been unmounted
|
||||
*/
|
||||
@ -146,12 +145,10 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
|
||||
private cleanupRefInterval: NodeJS.Timeout | null = null;
|
||||
|
||||
private initScroll: NodeJS.Timeout | null = null;
|
||||
|
||||
constructor(props: VirtualScrollerProps<T>) {
|
||||
super(props);
|
||||
this.state = {
|
||||
visibleItems: new BigIntOrderedMap(),
|
||||
visibleItems: [],
|
||||
scrollbar: 0,
|
||||
loaded: {
|
||||
top: false,
|
||||
@ -162,23 +159,18 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
this.updateVisible = this.updateVisible.bind(this);
|
||||
|
||||
this.invertedKeyHandler = this.invertedKeyHandler.bind(this);
|
||||
this.onScroll = IS_IOS ? _.debounce(this.onScroll.bind(this), 400) : this.onScroll.bind(this);
|
||||
this.onScroll = IS_IOS ? _.debounce(this.onScroll.bind(this), 200) : this.onScroll.bind(this);
|
||||
this.scrollKeyMap = this.scrollKeyMap.bind(this);
|
||||
this.setWindow = this.setWindow.bind(this);
|
||||
this.restore = this.restore.bind(this);
|
||||
this.startOffset = this.startOffset.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.updateVisible(0);
|
||||
this.resetScroll();
|
||||
this.loadTop();
|
||||
this.loadBottom();
|
||||
this.cleanupRefInterval = setInterval(this.cleanupRefs, 5000);
|
||||
this.initScroll = setTimeout(() => {
|
||||
log('scroll', 'initialised scroll');
|
||||
this.restore();
|
||||
this.initScroll = null;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
|
||||
@ -189,11 +181,11 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
}
|
||||
[...this.orphans].forEach(o => {
|
||||
const index = bigInt(o);
|
||||
this.childRefs.delete(index);
|
||||
this.childRefs.delete(index.toString());
|
||||
});
|
||||
this.orphans.clear();
|
||||
};
|
||||
|
||||
|
||||
// manipulate scrollbar manually, to dodge change detection
|
||||
updateScroll = IS_IOS ? () => {} : _.throttle(() => {
|
||||
if(!this.window || !this.scrollRef) {
|
||||
@ -214,13 +206,12 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
|
||||
componentDidUpdate(prevProps: VirtualScrollerProps<T>, _prevState: VirtualScrollerState<T>) {
|
||||
const { id, size, data, offset, pendingSize } = this.props;
|
||||
const { visibleItems } = this.state;
|
||||
|
||||
if(size !== prevProps.size || pendingSize !== prevProps.pendingSize) {
|
||||
if(this.scrollLocked) {
|
||||
if((this.window?.scrollTop ?? 0) < ZONE_SIZE) {
|
||||
this.scrollLocked = true;
|
||||
this.updateVisible(0);
|
||||
this.resetScroll();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -230,17 +221,18 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
if(this.cleanupRefInterval) {
|
||||
clearInterval(this.cleanupRefInterval);
|
||||
}
|
||||
if(this.initScroll) {
|
||||
clearTimeout(this.initScroll);
|
||||
}
|
||||
this.cleanupRefs();
|
||||
this.childRefs.clear();
|
||||
}
|
||||
|
||||
startOffset() {
|
||||
const startIndex = this.state?.visibleItems?.peekLargest()?.[0];
|
||||
const { data } = this.props;
|
||||
const startIndex = this.state.visibleItems?.[0];
|
||||
if(!startIndex) {
|
||||
return 0;
|
||||
}
|
||||
const offset = [...this.props.data].findIndex(([i]) => i.eq(startIndex))
|
||||
const dataList = Array.from(data);
|
||||
const offset = dataList.findIndex(([i]) => i.eq(startIndex))
|
||||
if(offset === -1) {
|
||||
// TODO: revisit when we remove nodes for any other reason than
|
||||
// pending indices being removed
|
||||
@ -260,19 +252,17 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
log('reflow', `from: ${this.startOffset()} to: ${newOffset}`);
|
||||
|
||||
const { data, onCalculateVisibleItems } = this.props;
|
||||
const visibleItems = new BigIntOrderedMap<any>(
|
||||
[...data].slice(newOffset, newOffset + this.pageSize)
|
||||
);
|
||||
const visibleItems = data.keys().slice(newOffset, newOffset + this.pageSize);
|
||||
|
||||
this.save();
|
||||
|
||||
this.setState({
|
||||
visibleItems,
|
||||
}, () => {
|
||||
requestAnimationFrame(() => {
|
||||
this.restore();
|
||||
});
|
||||
});
|
||||
requestAnimationFrame(() => {
|
||||
this.restore();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
scrollKeyMap(): Map<string, number> {
|
||||
@ -304,7 +294,6 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
setWindow(element) {
|
||||
if (!element)
|
||||
return;
|
||||
console.log('resetting window');
|
||||
this.save();
|
||||
|
||||
if (this.window) {
|
||||
@ -317,8 +306,8 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
const { averageHeight } = this.props;
|
||||
|
||||
this.window = element;
|
||||
this.pageSize = Math.floor(element.offsetHeight / Math.floor(averageHeight / 5.5));
|
||||
this.pageDelta = Math.floor(this.pageSize / 3);
|
||||
this.pageSize = Math.floor(element.offsetHeight / Math.floor(averageHeight / 2));
|
||||
this.pageDelta = Math.floor(this.pageSize / 4);
|
||||
if (this.props.origin === 'bottom') {
|
||||
element.addEventListener('wheel', (event) => {
|
||||
event.preventDefault();
|
||||
@ -364,16 +353,12 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
}
|
||||
};
|
||||
|
||||
onScroll(event: UIEvent) {
|
||||
onScroll(event: SyntheticEvent<HTMLElement, ScrollEvent>) {
|
||||
this.updateScroll();
|
||||
if(!this.window) {
|
||||
// bail if we're going to adjust scroll anyway
|
||||
return;
|
||||
}
|
||||
if(this.initScroll) {
|
||||
clearTimeout(this.initScroll);
|
||||
this.initScroll = null;
|
||||
}
|
||||
if(this.saveDepth > 0) {
|
||||
log('bail', 'deep scroll queue');
|
||||
return;
|
||||
@ -383,19 +368,19 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
const { scrollTop, scrollHeight } = this.window;
|
||||
|
||||
const startOffset = this.startOffset();
|
||||
|
||||
const scrollEnd = scrollTop + windowHeight;
|
||||
if (scrollTop < ZONE_SIZE) {
|
||||
log('scroll', `Entered start zone ${scrollTop}`);
|
||||
if (startOffset === 0 && onStartReached) {
|
||||
onStartReached();
|
||||
if (startOffset === 0) {
|
||||
onStartReached && onStartReached();
|
||||
this.scrollLocked = true;
|
||||
}
|
||||
const newOffset = Math.max(0, startOffset - this.pageDelta);
|
||||
if(newOffset < 10) {
|
||||
this.loadBottom();
|
||||
}
|
||||
|
||||
if(newOffset === 0) {
|
||||
this.scrollLocked = true;
|
||||
}
|
||||
if(newOffset !== startOffset) {
|
||||
this.updateVisible(newOffset);
|
||||
}
|
||||
@ -429,47 +414,62 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
log('bail', 'Deep restore');
|
||||
return;
|
||||
}
|
||||
if(this.initScroll) {
|
||||
log('bail', 'still initialising scroll');
|
||||
if(this.scrollLocked) {
|
||||
this.resetScroll();
|
||||
requestAnimationFrame(() => {
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth--;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let ref = this.childRefs.get(this.savedIndex)
|
||||
let ref = this.childRefs.get(this.savedIndex.toString())
|
||||
if(!ref) {
|
||||
return;
|
||||
}
|
||||
const newScrollTop = this.window.scrollHeight - ref.offsetTop - this.savedDistance;
|
||||
|
||||
const newScrollTop = this.props.origin === 'top'
|
||||
? this.savedDistance + ref.offsetTop
|
||||
: this.window.scrollHeight - ref.offsetTop - this.savedDistance;
|
||||
|
||||
|
||||
this.window.scrollTo(0, newScrollTop);
|
||||
requestAnimationFrame(() => {
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth--;
|
||||
});
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth--;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
scrollToIndex = (index: BigInteger) => {
|
||||
let ref = this.childRefs.get(index);
|
||||
let ref = this.childRefs.get(index.toString());
|
||||
if(!ref) {
|
||||
const offset = [...this.props.data].findIndex(([idx]) => idx.eq(index));
|
||||
if(offset === -1) {
|
||||
return;
|
||||
}
|
||||
this.scrollLocked = false;
|
||||
this.updateVisible(Math.max(offset - this.pageDelta, 0));
|
||||
requestAnimationFrame(() => {
|
||||
ref = this.childRefs.get(index);
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth = 0;
|
||||
ref = this.childRefs.get(index.toString());
|
||||
requestAnimationFrame(() => {
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth = 0;
|
||||
});
|
||||
|
||||
ref?.scrollIntoView({ block: 'center' });
|
||||
});
|
||||
} else {
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth = 0;
|
||||
|
||||
ref?.scrollIntoView({ block: 'center' });
|
||||
requestAnimationFrame(() => {
|
||||
this.savedIndex = null;
|
||||
this.savedDistance = 0;
|
||||
this.saveDepth = 0;
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -478,17 +478,20 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
return;
|
||||
}
|
||||
if(this.saveDepth !== 0) {
|
||||
console.log('bail', 'deep save');
|
||||
return;
|
||||
}
|
||||
|
||||
this.saveDepth++;
|
||||
|
||||
let bottomIndex: BigInteger | null = null;
|
||||
log('scroll', 'saving...');
|
||||
|
||||
this.saveDepth++;
|
||||
const { visibleItems } = this.state;
|
||||
|
||||
let bottomIndex = visibleItems[visibleItems.length - 1];
|
||||
const { scrollTop, scrollHeight } = this.window;
|
||||
const topSpacing = scrollHeight - scrollTop;
|
||||
[...Array.from(this.state.visibleItems)].reverse().forEach(([index, datum]) => {
|
||||
const el = this.childRefs.get(index);
|
||||
const topSpacing = this.props.origin === 'top' ? scrollTop : scrollHeight - scrollTop;
|
||||
const items = this.props.origin === 'top' ? visibleItems : [...visibleItems].reverse();
|
||||
items.forEach((index) => {
|
||||
const el = this.childRefs.get(index.toString());
|
||||
if(!el) {
|
||||
return;
|
||||
}
|
||||
@ -501,20 +504,27 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
if(!bottomIndex) {
|
||||
// weird, shouldn't really happen
|
||||
this.saveDepth--;
|
||||
log('bail', 'no index found');
|
||||
return;
|
||||
}
|
||||
|
||||
this.savedIndex = bottomIndex;
|
||||
const ref = this.childRefs.get(bottomIndex)!;
|
||||
const ref = this.childRefs.get(bottomIndex.toString())!;
|
||||
if(!ref) {
|
||||
this.saveDepth--;
|
||||
log('bail', 'missing ref');
|
||||
return;
|
||||
}
|
||||
const { offsetTop } = ref;
|
||||
this.savedDistance = topSpacing - offsetTop
|
||||
}
|
||||
|
||||
shiftLayout = { save: this.save.bind(this), restore: this.restore.bind(this) };
|
||||
// disabled until we work out race conditions with loading new nodes
|
||||
shiftLayout = { save: () => {}, restore: () => {} };
|
||||
|
||||
setRef = (element: HTMLElement | null, index: BigInteger) => {
|
||||
if(element) {
|
||||
this.childRefs.set(index, element);
|
||||
this.childRefs.set(index.toString(), element);
|
||||
this.orphans.delete(index.toString());
|
||||
} else {
|
||||
this.orphans.add(index.toString());
|
||||
@ -536,12 +546,11 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
|
||||
const isTop = origin === 'top';
|
||||
|
||||
const indexesToRender = isTop ? visibleItems.keys() : visibleItems.keys().reverse();
|
||||
|
||||
const transform = isTop ? 'scale3d(1, 1, 1)' : 'scale3d(1, -1, 1)';
|
||||
const children = isTop ? visibleItems : [...visibleItems].reverse();
|
||||
|
||||
const atStart = (this.props.data.peekLargest()?.[0] ?? bigInt.zero).eq(visibleItems.peekLargest()?.[0] || bigInt.zero);
|
||||
const atEnd = this.state.loaded.top;
|
||||
const atStart = (this.props.data.peekLargest()?.[0] ?? bigInt.zero).eq(visibleItems?.[0] || bigInt.zero);
|
||||
const atEnd = (this.props.data.peekSmallest()?.[0] ?? bigInt.zero).eq(visibleItems?.[visibleItems.length -1 ] || bigInt.zero);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -553,7 +562,7 @@ export default class VirtualScroller<T> extends Component<VirtualScrollerProps<T
|
||||
<LoadingSpinner />
|
||||
</Center>)}
|
||||
<VirtualContext.Provider value={this.shiftLayout}>
|
||||
{indexesToRender.map(index => (
|
||||
{children.map(index => (
|
||||
<VirtualChild
|
||||
key={index.toString()}
|
||||
setRef={this.setRef}
|
||||
@ -586,8 +595,10 @@ function VirtualChild(props: VirtualChildProps) {
|
||||
|
||||
const ref = useCallback((el: HTMLElement | null) => {
|
||||
setRef(el, props.index);
|
||||
}, [setRef, props.index])
|
||||
// VirtualChild should always be keyed on the index, so the index should be
|
||||
// valid for the entire lifecycle of the component, hence no dependencies
|
||||
}, []);
|
||||
|
||||
return (<Renderer ref={ref} {...rest} />);
|
||||
return <Renderer ref={ref} {...rest} />
|
||||
};
|
||||
|
||||
|
@ -141,7 +141,7 @@ export class OmniboxResult extends Component {
|
||||
<Icon
|
||||
display='inline-block'
|
||||
verticalAlign='middle'
|
||||
icon='Users'
|
||||
icon='Messages'
|
||||
mr='2'
|
||||
size='18px'
|
||||
color={iconFill}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import useStorage from '~/logic/lib/useStorage';
|
||||
import useStorage, {IuseStorage} from '~/logic/lib/useStorage';
|
||||
|
||||
const withStorage = (Component, params = {}) => {
|
||||
return React.forwardRef((props: any, ref) => {
|
||||
const withStorage = <P, C extends React.ComponentType<P>>(Component: C, params = {}) => {
|
||||
return React.forwardRef<C, Omit<C, keyof IuseStorage>>((props, ref) => {
|
||||
const storage = useStorage(params);
|
||||
|
||||
return <Component ref={ref} {...storage} {...props} />;
|
||||
|
@ -58,7 +58,11 @@ function GraphContentWideInner(
|
||||
width="fit-content"
|
||||
maxWidth="min(500px, 100%)"
|
||||
>
|
||||
<RemoteContent key={content.url} url={content.url} />
|
||||
<RemoteContent
|
||||
key={content.url}
|
||||
url={content.url}
|
||||
transcluded={transcluded}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
case "mention":
|
||||
|
@ -124,7 +124,6 @@ export function GroupsPane(props: GroupsPaneProps) {
|
||||
>
|
||||
<Resource
|
||||
{...props}
|
||||
{...routeProps}
|
||||
association={association}
|
||||
baseUrl={baseUrl}
|
||||
/>
|
||||
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import bigInt from 'big-integer';
|
||||
import VirtualScroller from "~/views/components/VirtualScroller";
|
||||
import PostItem from './PostItem/PostItem';
|
||||
import { Col } from '@tlon/indigo-react';
|
||||
import { Col, Box } from '@tlon/indigo-react';
|
||||
import { resourceFromPath } from '~/logic/lib/group';
|
||||
|
||||
|
||||
@ -15,102 +15,103 @@ export class PostFeed extends React.Component {
|
||||
super(props);
|
||||
|
||||
this.isFetching = false;
|
||||
this.renderItem = React.forwardRef(({ index, scrollWindow }, ref) => {
|
||||
const {
|
||||
graph,
|
||||
graphPath,
|
||||
api,
|
||||
history,
|
||||
baseUrl,
|
||||
parentNode,
|
||||
grandparentNode,
|
||||
association,
|
||||
group,
|
||||
vip
|
||||
} = this.props;
|
||||
const graphResource = resourceFromPath(graphPath);
|
||||
const node = graph.get(index);
|
||||
if (!node) { return null; }
|
||||
|
||||
const first = graph.peekLargest()?.[0];
|
||||
const post = node?.post;
|
||||
if (!node || !post) {
|
||||
return null;
|
||||
}
|
||||
let nodeIndex = parentNode ? parentNode.post.index.split('/').slice(1).map((ind) => {
|
||||
return bigInt(ind);
|
||||
}) : [];
|
||||
|
||||
if (parentNode && index.eq(first ?? bigInt.zero)) {
|
||||
return (
|
||||
<React.Fragment key={index.toString()}>
|
||||
<Col
|
||||
key={index.toString()}
|
||||
mb="3"
|
||||
width="100%"
|
||||
flexShrink={0}
|
||||
>
|
||||
<PostItem
|
||||
key={parentNode.post.index}
|
||||
ref={ref}
|
||||
parentPost={grandparentNode?.post}
|
||||
node={parentNode}
|
||||
parentNode={grandparentNode}
|
||||
graphPath={graphPath}
|
||||
association={association}
|
||||
api={api}
|
||||
index={nodeIndex}
|
||||
baseUrl={baseUrl}
|
||||
history={history}
|
||||
isParent={true}
|
||||
isRelativeTime={false}
|
||||
vip={vip}
|
||||
group={group}
|
||||
/>
|
||||
</Col>
|
||||
<PostItem
|
||||
ref={ref}
|
||||
node={node}
|
||||
graphPath={graphPath}
|
||||
association={association}
|
||||
api={api}
|
||||
index={[...nodeIndex, index]}
|
||||
baseUrl={baseUrl}
|
||||
history={history}
|
||||
isReply={true}
|
||||
parentPost={parentNode.post}
|
||||
isRelativeTime={true}
|
||||
vip={vip}
|
||||
group={group}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<PostItem
|
||||
key={index.toString()}
|
||||
ref={ref}
|
||||
node={node}
|
||||
graphPath={graphPath}
|
||||
association={association}
|
||||
api={api}
|
||||
index={[...nodeIndex, index]}
|
||||
baseUrl={baseUrl}
|
||||
history={history}
|
||||
parentPost={parentNode?.post}
|
||||
isReply={!!parentNode}
|
||||
isRelativeTime={true}
|
||||
vip={vip}
|
||||
group={group}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
this.fetchPosts = this.fetchPosts.bind(this);
|
||||
this.doNotFetch = this.doNotFetch.bind(this);
|
||||
}
|
||||
|
||||
renderItem = React.forwardRef(({ index, scrollWindow }, ref) => {
|
||||
const {
|
||||
graph,
|
||||
graphPath,
|
||||
api,
|
||||
history,
|
||||
baseUrl,
|
||||
parentNode,
|
||||
grandparentNode,
|
||||
association,
|
||||
group,
|
||||
vip
|
||||
} = this.props;
|
||||
const graphResource = resourceFromPath(graphPath);
|
||||
const node = graph.get(index);
|
||||
if (!node) { return null; }
|
||||
|
||||
const first = graph.peekLargest()?.[0];
|
||||
const post = node?.post;
|
||||
if (!node || !post) {
|
||||
return null;
|
||||
}
|
||||
let nodeIndex = parentNode ? parentNode.post.index.split('/').slice(1).map((ind) => {
|
||||
return bigInt(ind);
|
||||
}) : [];
|
||||
|
||||
if (parentNode && index.eq(first ?? bigInt.zero)) {
|
||||
return (
|
||||
<React.Fragment key={index.toString()}>
|
||||
<Col
|
||||
key={index.toString()}
|
||||
ref={ref}
|
||||
mb="3"
|
||||
width="100%"
|
||||
flexShrink={0}
|
||||
>
|
||||
<PostItem
|
||||
key={parentNode.post.index}
|
||||
parentPost={grandparentNode?.post}
|
||||
node={parentNode}
|
||||
parentNode={grandparentNode}
|
||||
graphPath={graphPath}
|
||||
association={association}
|
||||
api={api}
|
||||
index={nodeIndex}
|
||||
baseUrl={baseUrl}
|
||||
history={history}
|
||||
isParent={true}
|
||||
isRelativeTime={false}
|
||||
vip={vip}
|
||||
group={group}
|
||||
/>
|
||||
</Col>
|
||||
<PostItem
|
||||
node={node}
|
||||
graphPath={graphPath}
|
||||
association={association}
|
||||
api={api}
|
||||
index={[...nodeIndex, index]}
|
||||
baseUrl={baseUrl}
|
||||
history={history}
|
||||
isReply={true}
|
||||
parentPost={parentNode.post}
|
||||
isRelativeTime={true}
|
||||
vip={vip}
|
||||
group={group}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box key={index.toString()} ref={ref}>
|
||||
<PostItem
|
||||
node={node}
|
||||
graphPath={graphPath}
|
||||
association={association}
|
||||
api={api}
|
||||
index={[...nodeIndex, index]}
|
||||
baseUrl={baseUrl}
|
||||
history={history}
|
||||
parentPost={parentNode?.post}
|
||||
isReply={!!parentNode}
|
||||
isRelativeTime={true}
|
||||
vip={vip}
|
||||
group={group}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
async fetchPosts(newer) {
|
||||
const { graph, graphPath, api } = this.props;
|
||||
const graphResource = resourceFromPath(graphPath);
|
||||
|
@ -46,6 +46,7 @@ export function PostHeader(props) {
|
||||
isRelativeTime={true}
|
||||
showTime={false}
|
||||
time={true}
|
||||
lineHeight='1'
|
||||
/>
|
||||
<Dropdown
|
||||
dropWidth="200px"
|
||||
|
@ -304,7 +304,7 @@ function Participant(props: {
|
||||
}, [api, contact, association]);
|
||||
|
||||
const avatar =
|
||||
contact?.avatar !== null && !hideAvatars ? (
|
||||
contact?.avatar && !hideAvatars ? (
|
||||
<Image
|
||||
src={contact.avatar}
|
||||
height={32}
|
||||
|
@ -15,12 +15,14 @@ import useGroupState from '~/logic/state/group';
|
||||
import useContactState from '~/logic/state/contact';
|
||||
import useHarkState from '~/logic/state/hark';
|
||||
import useMetadataState from '~/logic/state/metadata';
|
||||
import {Workspace} from '~/types';
|
||||
|
||||
type ResourceProps = StoreState & {
|
||||
association: Association;
|
||||
api: GlobalApi;
|
||||
baseUrl: string;
|
||||
} & RouteComponentProps;
|
||||
workspace: Workspace;
|
||||
};
|
||||
|
||||
export function Resource(props: ResourceProps): ReactElement {
|
||||
const { association, api, notificationsGraphConfig } = props;
|
||||
|
@ -1,6 +1,10 @@
|
||||
import { immerable } from 'immer';
|
||||
import produce, { immerable, castImmutable, castDraft, setAutoFreeze, enablePatches } from 'immer';
|
||||
import bigInt, { BigInteger } from "big-integer";
|
||||
|
||||
setAutoFreeze(false);
|
||||
|
||||
enablePatches();
|
||||
|
||||
function sortBigInt(a: BigInteger, b: BigInteger) {
|
||||
if (a.lt(b)) {
|
||||
return 1;
|
||||
@ -11,19 +15,18 @@ function sortBigInt(a: BigInteger, b: BigInteger) {
|
||||
}
|
||||
}
|
||||
export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
|
||||
private root: Record<string, V> = {}
|
||||
private cachedIter: [BigInteger, V][] | null = null;
|
||||
root: Record<string, V> = {}
|
||||
cachedIter: [BigInteger, V][] = [];
|
||||
[immerable] = true;
|
||||
|
||||
constructor(items: [BigInteger, V][] = []) {
|
||||
items.forEach(([key, val]) => {
|
||||
this.set(key, val);
|
||||
});
|
||||
this.generateCachedIter();
|
||||
}
|
||||
|
||||
get size() {
|
||||
return this.cachedIter?.length ?? Object.keys(this.root).length;
|
||||
return Object.keys(this.root).length;
|
||||
}
|
||||
|
||||
|
||||
@ -31,14 +34,30 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
|
||||
return this.root[key.toString()] ?? null;
|
||||
}
|
||||
|
||||
gas(items: [BigInteger, V][]) {
|
||||
return produce(this, draft => {
|
||||
items.forEach(([key, value]) => {
|
||||
draft.root[key.toString()] = castDraft(value);
|
||||
});
|
||||
draft.generateCachedIter();
|
||||
},
|
||||
(patches) => {
|
||||
//console.log(`gassed with ${JSON.stringify(patches, null, 2)}`);
|
||||
});
|
||||
}
|
||||
|
||||
set(key: BigInteger, value: V) {
|
||||
this.root[key.toString()] = value;
|
||||
this.cachedIter = null;
|
||||
return produce(this, draft => {
|
||||
draft.root[key.toString()] = castDraft(value);
|
||||
draft.generateCachedIter();
|
||||
});
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.cachedIter = null;
|
||||
this.root = {}
|
||||
return produce(this, draft => {
|
||||
draft.cachedIter = [];
|
||||
draft.root = {}
|
||||
});
|
||||
}
|
||||
|
||||
has(key: BigInteger) {
|
||||
@ -46,17 +65,15 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
|
||||
}
|
||||
|
||||
delete(key: BigInteger) {
|
||||
const had = this.has(key);
|
||||
if(had) {
|
||||
delete this.root[key.toString()];
|
||||
this.cachedIter = null;
|
||||
}
|
||||
return had;
|
||||
return produce(this, draft => {
|
||||
delete draft.root[key.toString()];
|
||||
draft.cachedIter = draft.cachedIter.filter(([x]) => x.eq(key));
|
||||
});
|
||||
}
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[BigInteger, V]> {
|
||||
let idx = 0;
|
||||
const result = this.generateCachedIter();
|
||||
let result = [...this.cachedIter];
|
||||
return {
|
||||
[Symbol.iterator]: this[Symbol.iterator],
|
||||
next: (): IteratorResult<[BigInteger, V]> => {
|
||||
@ -79,19 +96,15 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
|
||||
}
|
||||
|
||||
keys() {
|
||||
return Object.keys(this.root).map(k => bigInt(k)).sort(sortBigInt)
|
||||
return Array.from(this).map(([k,v]) => k);
|
||||
}
|
||||
|
||||
private generateCachedIter() {
|
||||
if(this.cachedIter) {
|
||||
return this.cachedIter;
|
||||
}
|
||||
generateCachedIter() {
|
||||
const result = Object.keys(this.root).map(key => {
|
||||
const num = bigInt(key);
|
||||
return [num, this.root[key]] as [BigInteger, V];
|
||||
}).sort(([a], [b]) => sortBigInt(a,b));
|
||||
this.cachedIter = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,3 +65,13 @@
|
||||
*/
|
||||
u3_noun
|
||||
u3s_cue_atom(u3_atom a);
|
||||
|
||||
/* u3s_sift_ud_bytes: parse @ud.
|
||||
*/
|
||||
u3_weak
|
||||
u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y);
|
||||
|
||||
/* u3s_sift_ud: parse @ud.
|
||||
*/
|
||||
u3_weak
|
||||
u3s_sift_ud(u3_atom a);
|
||||
|
@ -5,49 +5,16 @@
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
/* functions
|
||||
*/
|
||||
u3_noun
|
||||
_parse_ud(u3_noun txt) {
|
||||
c3_c* c = u3a_string(txt);
|
||||
static inline u3_noun
|
||||
_parse_ud(u3_noun a)
|
||||
{
|
||||
u3_weak pro;
|
||||
|
||||
// First character must represent a digit
|
||||
c3_c* cur = c;
|
||||
if (cur[0] > '9' || cur[0] < '0') {
|
||||
u3a_free(c);
|
||||
return u3_none;
|
||||
}
|
||||
u3_atom total = cur[0] - '0';
|
||||
cur++;
|
||||
|
||||
int since_last_period = 0;
|
||||
while (cur[0] != 0) {
|
||||
since_last_period++;
|
||||
if (cur[0] == '.') {
|
||||
since_last_period = 0;
|
||||
cur++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cur[0] > '9' || cur[0] < '0') {
|
||||
u3a_free(c);
|
||||
u3z(total);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
total = u3ka_mul(total, 10);
|
||||
total = u3ka_add(total, cur[0] - '0');
|
||||
cur++;
|
||||
|
||||
if (since_last_period > 3) {
|
||||
u3a_free(c);
|
||||
u3z(total);
|
||||
return u3_none;
|
||||
}
|
||||
if ( u3_none == (pro = u3s_sift_ud(u3x_atom(a))) ) {
|
||||
return u3_nul;
|
||||
}
|
||||
|
||||
u3a_free(c);
|
||||
return u3nc(0, total);
|
||||
return u3nc(u3_nul, pro);
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -313,12 +313,17 @@ u3i_word(c3_w dat_w)
|
||||
u3_atom
|
||||
u3i_chub(c3_d dat_d)
|
||||
{
|
||||
c3_w dat_w[2] = {
|
||||
dat_d & 0xffffffffULL,
|
||||
dat_d >> 32
|
||||
};
|
||||
if ( c3y == u3a_is_cat(dat_d) ) {
|
||||
return (u3_atom)dat_d;
|
||||
}
|
||||
else {
|
||||
c3_w dat_w[2] = {
|
||||
dat_d & 0xffffffffULL,
|
||||
dat_d >> 32
|
||||
};
|
||||
|
||||
return u3i_words(2, dat_w);
|
||||
return u3i_words(2, dat_w);
|
||||
}
|
||||
}
|
||||
|
||||
/* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom.
|
||||
|
@ -98,28 +98,22 @@ _cm_punt(u3_noun tax)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _write(int fd, const void *buf, size_t count)
|
||||
{
|
||||
if (count != write(fd, buf, count)){
|
||||
u3l_log("write failed\r\n");
|
||||
c3_assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* _cm_emergency(): write emergency text to stderr, never failing.
|
||||
*/
|
||||
static void
|
||||
_cm_emergency(c3_c* cap_c, c3_l sig_l)
|
||||
{
|
||||
_write(2, "\r\n", 2);
|
||||
_write(2, cap_c, strlen(cap_c));
|
||||
c3_i ret_i;
|
||||
|
||||
ret_i = write(2, "\r\n", 2);
|
||||
ret_i = write(2, cap_c, strlen(cap_c));
|
||||
|
||||
if ( sig_l ) {
|
||||
_write(2, ": ", 2);
|
||||
_write(2, &sig_l, 4);
|
||||
ret_i = write(2, ": ", 2);
|
||||
ret_i = write(2, &sig_l, 4);
|
||||
}
|
||||
_write(2, "\r\n", 2);
|
||||
|
||||
ret_i = write(2, "\r\n", 2);
|
||||
}
|
||||
|
||||
static void _cm_overflow(void *arg1, void *arg2, void *arg3)
|
||||
@ -127,7 +121,7 @@ static void _cm_overflow(void *arg1, void *arg2, void *arg3)
|
||||
(void)(arg1);
|
||||
(void)(arg2);
|
||||
(void)(arg3);
|
||||
siglongjmp(u3_Signal, c3__over);
|
||||
u3m_signal(c3__over);
|
||||
}
|
||||
|
||||
/* _cm_signal_handle(): handle a signal in general.
|
||||
@ -139,7 +133,7 @@ _cm_signal_handle(c3_l sig_l)
|
||||
sigsegv_leave_handler(_cm_overflow, NULL, NULL, NULL);
|
||||
}
|
||||
else {
|
||||
siglongjmp(u3_Signal, sig_l);
|
||||
u3m_signal(sig_l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,7 +655,10 @@ u3m_dump(void)
|
||||
c3_i
|
||||
u3m_bail(u3_noun how)
|
||||
{
|
||||
if ( (c3__exit == how) && (u3R == &u3H->rod_u) ) {
|
||||
if ( &(u3H->rod_u) == u3R ) {
|
||||
// XX set exit code
|
||||
//
|
||||
fprintf(stderr, "home: bailing out\r\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -688,8 +685,9 @@ u3m_bail(u3_noun how)
|
||||
//
|
||||
switch ( how ) {
|
||||
case c3__foul:
|
||||
case c3__meme:
|
||||
case c3__oops: {
|
||||
// XX set exit code
|
||||
//
|
||||
fprintf(stderr, "bailing out\r\n");
|
||||
abort();
|
||||
}
|
||||
@ -700,6 +698,9 @@ u3m_bail(u3_noun how)
|
||||
// choice but to use the signal process; and we require the flat
|
||||
// form of how.
|
||||
//
|
||||
// XX JB: these seem unrecoverable, at least wrt memory management,
|
||||
// so they've been disabled above for now
|
||||
//
|
||||
c3_assert(_(u3a_is_cat(how)));
|
||||
u3m_signal(how);
|
||||
}
|
||||
|
@ -1205,16 +1205,11 @@ u3r_mp(mpz_t a_mp,
|
||||
else {
|
||||
u3a_atom* b_u = u3a_to_ptr(b);
|
||||
c3_w len_w = b_u->len_w;
|
||||
c3_d bit_d = (c3_d)len_w << 5;
|
||||
|
||||
// avoid reallocation on import, if possible
|
||||
//
|
||||
if ( (len_w >> 27) ) {
|
||||
mpz_init(a_mp);
|
||||
}
|
||||
else {
|
||||
mpz_init2(a_mp, len_w << 5);
|
||||
}
|
||||
|
||||
mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX));
|
||||
mpz_import(a_mp, len_w, -1, sizeof(c3_w), 0, 0, b_u->buf_w);
|
||||
}
|
||||
}
|
||||
|
@ -856,3 +856,128 @@ u3s_cue_atom(u3_atom a)
|
||||
|
||||
return u3s_cue_bytes((c3_d)len_w, byt_y);
|
||||
}
|
||||
|
||||
#define DIGIT(a) ( ((a) >= '0') && ((a) <= '9') )
|
||||
#define BLOCK(a) ( ('.' == (a)[0]) \
|
||||
&& DIGIT(a[1]) \
|
||||
&& DIGIT(a[2]) \
|
||||
&& DIGIT(a[3]) )
|
||||
|
||||
/* u3s_sift_ud_bytes: parse @ud
|
||||
*/
|
||||
u3_weak
|
||||
u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y)
|
||||
{
|
||||
c3_y num_y = len_w % 4; // leading digits length
|
||||
c3_s val_s = 0; // leading digits value
|
||||
|
||||
// +ape:ag: just 0
|
||||
//
|
||||
if ( !len_w ) return u3_none;
|
||||
if ( '0' == *byt_y ) return ( 1 == len_w ) ? (u3_noun)0 : u3_none;
|
||||
|
||||
// +ted:ab: leading nonzero (checked above), plus up to 2 digits
|
||||
//
|
||||
#define NEXT() do { \
|
||||
if ( !DIGIT(*byt_y) ) return u3_none; \
|
||||
val_s *= 10; \
|
||||
val_s += *byt_y++ - '0'; \
|
||||
} while (0)
|
||||
|
||||
switch ( num_y ) {
|
||||
case 3: NEXT();
|
||||
case 2: NEXT();
|
||||
case 1: NEXT(); break;
|
||||
case 0: return u3_none;
|
||||
}
|
||||
|
||||
#undef NEXT
|
||||
|
||||
len_w -= num_y;
|
||||
|
||||
// +tid:ab: dot-prefixed 3-digit blocks
|
||||
//
|
||||
// avoid gmp allocation if possible
|
||||
// - 19 decimal digits fit in 64 bits
|
||||
// - 18 digits is 24 bytes with separators
|
||||
//
|
||||
if ( ((1 == num_y) && (24 >= len_w))
|
||||
|| (20 >= len_w) )
|
||||
{
|
||||
c3_d val_d = val_s;
|
||||
|
||||
while ( len_w ) {
|
||||
if ( !BLOCK(byt_y) ) return u3_none;
|
||||
|
||||
byt_y++;
|
||||
|
||||
val_d *= 10;
|
||||
val_d += *byt_y++ - '0';
|
||||
val_d *= 10;
|
||||
val_d += *byt_y++ - '0';
|
||||
val_d *= 10;
|
||||
val_d += *byt_y++ - '0';
|
||||
|
||||
len_w -= 4;
|
||||
}
|
||||
|
||||
return u3i_chub(val_d);
|
||||
}
|
||||
|
||||
{
|
||||
// avoid gmp realloc if possible
|
||||
//
|
||||
mpz_t a_mp;
|
||||
{
|
||||
c3_d bit_d = (c3_d)(len_w / 4) * 10;
|
||||
mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX));
|
||||
mpz_set_ui(a_mp, val_s);
|
||||
}
|
||||
|
||||
while ( len_w ) {
|
||||
if ( !BLOCK(byt_y) ) {
|
||||
mpz_clear(a_mp);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
byt_y++;
|
||||
|
||||
val_s = *byt_y++ - '0';
|
||||
val_s *= 10;
|
||||
val_s += *byt_y++ - '0';
|
||||
val_s *= 10;
|
||||
val_s += *byt_y++ - '0';
|
||||
|
||||
mpz_mul_ui(a_mp, a_mp, 1000);
|
||||
mpz_add_ui(a_mp, a_mp, val_s);
|
||||
|
||||
len_w -= 4;
|
||||
}
|
||||
|
||||
return u3i_mp(a_mp);
|
||||
}
|
||||
}
|
||||
|
||||
#undef BLOCK
|
||||
#undef DIGIT
|
||||
|
||||
/* u3s_sift_ud: parse @ud.
|
||||
*/
|
||||
u3_weak
|
||||
u3s_sift_ud(u3_atom a)
|
||||
{
|
||||
c3_w len_w = u3r_met(3, a);
|
||||
c3_y* byt_y;
|
||||
|
||||
// XX assumes little-endian
|
||||
//
|
||||
if ( c3y == u3a_is_cat(a) ) {
|
||||
byt_y = (c3_y*)&a;
|
||||
}
|
||||
else {
|
||||
u3a_atom* vat_u = u3a_to_ptr(a);
|
||||
byt_y = (c3_y*)vat_u->buf_w;
|
||||
}
|
||||
|
||||
return u3s_sift_ud_bytes(len_w, byt_y);
|
||||
}
|
||||
|
@ -9,6 +9,108 @@ _setup(void)
|
||||
u3m_pave(c3y);
|
||||
}
|
||||
|
||||
static inline c3_i
|
||||
_ud_good(c3_w num_w, const c3_c* num_c)
|
||||
{
|
||||
u3_weak out;
|
||||
if ( num_w != (out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c)) ) {
|
||||
if ( u3_none == out ) {
|
||||
fprintf(stderr, "sift_ud: %s fail; expected %u\r\n", num_c, num_w);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "sift_ud: %s wrong; expected %u: actual %u\r\n", num_c, num_w, out);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline c3_i
|
||||
_ud_fail(const c3_c* num_c)
|
||||
{
|
||||
u3_weak out;
|
||||
if ( u3_none != (out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c)) ) {
|
||||
u3m_p("out", out);
|
||||
fprintf(stderr, "sift_ud: %s expected fail\r\n", num_c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static c3_i
|
||||
_test_sift_ud(void)
|
||||
{
|
||||
c3_i ret_i = 1;
|
||||
|
||||
ret_i &= _ud_good(0, "0");
|
||||
ret_i &= _ud_good(1, "1");
|
||||
ret_i &= _ud_good(12, "12");
|
||||
ret_i &= _ud_good(123, "123");
|
||||
ret_i &= _ud_good(1234, "1.234");
|
||||
ret_i &= _ud_good(12345, "12.345");
|
||||
ret_i &= _ud_good(123456, "123.456");
|
||||
ret_i &= _ud_good(1234567, "1.234.567");
|
||||
ret_i &= _ud_good(12345678, "12.345.678");
|
||||
ret_i &= _ud_good(123456789, "123.456.789");
|
||||
ret_i &= _ud_good(100000000, "100.000.000");
|
||||
ret_i &= _ud_good(101101101, "101.101.101");
|
||||
ret_i &= _ud_good(201201201, "201.201.201");
|
||||
ret_i &= _ud_good(302201100, "302.201.100");
|
||||
|
||||
ret_i &= _ud_fail("01");
|
||||
ret_i &= _ud_fail("02");
|
||||
ret_i &= _ud_fail("003");
|
||||
ret_i &= _ud_fail("1234");
|
||||
ret_i &= _ud_fail("1234.5");
|
||||
ret_i &= _ud_fail("1234.567.8");
|
||||
ret_i &= _ud_fail("1234.56..78.");
|
||||
ret_i &= _ud_fail("123.45a");
|
||||
ret_i &= _ud_fail(".123.456");
|
||||
|
||||
{
|
||||
c3_c* num_c = "4.294.967.296";
|
||||
u3_weak out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c);
|
||||
u3_atom pro = u3qc_bex(32);
|
||||
|
||||
if ( u3_none == out ) {
|
||||
fprintf(stderr, "sift_ud: (bex 32) fail\r\n");
|
||||
ret_i = 0;
|
||||
}
|
||||
|
||||
if ( c3n == u3r_sing(pro, out) ) {
|
||||
u3m_p("out", out);
|
||||
fprintf(stderr, "sift_ud: (bex 32) wrong\r\n");
|
||||
ret_i = 0;
|
||||
}
|
||||
|
||||
u3z(out); u3z(pro);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
c3_c* num_c = "340.282.366.920.938.463.463.374.607.431.768.211.456";
|
||||
u3_weak out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c);
|
||||
u3_atom pro = u3qc_bex(128);
|
||||
|
||||
if ( u3_none == out ) {
|
||||
fprintf(stderr, "sift_ud: (bex 128) fail\r\n");
|
||||
ret_i = 0;
|
||||
}
|
||||
|
||||
if ( c3n == u3r_sing(pro, out) ) {
|
||||
u3m_p("out", out);
|
||||
fprintf(stderr, "sift_ud: (bex 128) wrong\r\n");
|
||||
ret_i = 0;
|
||||
}
|
||||
|
||||
u3z(out); u3z(pro);
|
||||
}
|
||||
|
||||
return ret_i;
|
||||
}
|
||||
|
||||
static c3_i
|
||||
_test_en_base16(void)
|
||||
{
|
||||
@ -400,6 +502,11 @@ _test_jets(void)
|
||||
{
|
||||
c3_i ret_i = 1;
|
||||
|
||||
if ( !_test_sift_ud() ) {
|
||||
fprintf(stderr, "test jets: sift_ud: failed\r\n");
|
||||
ret_i = 0;
|
||||
}
|
||||
|
||||
if ( !_test_base16() ) {
|
||||
fprintf(stderr, "test jets: base16: failed\r\n");
|
||||
ret_i = 0;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user