This commit is contained in:
Liam Fitzgerald 2020-12-16 14:22:23 +10:00
parent 0ab9af0679
commit 610a8730b7
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
4 changed files with 156 additions and 55 deletions

View File

@ -1,7 +1,7 @@
:: hark-graph-hook: notifications for graph-store [landscape]
::
/- store=hark-store, post, group-store, metadata-store, hook=hark-graph-hook
/+ resource, metadata, default-agent, dbug, graph-store, graph, grouplib=group
/- post, group-store, metadata-store, hook=hark-graph-hook
/+ resource, metadata, default-agent, dbug, graph-store, graph, grouplib=group, store=hark-store
::
::
~% %hark-graph-hook-top ..part ~
@ -191,7 +191,8 @@
==
=/ group=(unit resource)
(group-from-app-resource:met %graph rid)
?~ group `state
?~ group
`state
=/ metadata=(unit metadata:metadata-store)
(peek-metadata:met %graph u.group rid)
?~ metadata `state
@ -327,7 +328,7 @@
?: =(our.bowl author.post.node)
(self-post node notif-index [mode watch]:not-kind)
=. update-core
(update-unread-count mode.not-kind notif-index [time-sent index]:post.node)
(update-unread-count not-kind notif-index [time-sent index]:post.node)
=? update-core
?| =(desc %mention)
(~(has in watching) [rid parent])
@ -338,10 +339,13 @@
update-core
::
++ update-unread-count
|= [mode=?(%count %each %none) =index:store time=@da ref=index:graph-store]
?- mode
%count (hark %unread-count index time)
%each (hark %unread-each index ref time)
|= [=notif-kind =index:store time=@da ref=index:graph-store]
=. description.index name.notif-kind
=/ =stats-index:store
(to-stats-index:store index)
?- mode.notif-kind
%count (hark %unread-count stats-index time)
%each (hark %unread-each stats-index ref time)
%none update-core
==
::
@ -352,10 +356,12 @@
watch=?
==
^+ update-core
=/ =stats-index:store
(to-stats-index:store index)
=. update-core
(hark %seen-index time-sent.post.node index)
(hark %seen-index time-sent.post.node stats-index)
=? update-core ?=(%count mode)
(hark %read-count index)
(hark %read-count stats-index)
=? update-core &(watch watch-on-self)
(new-watch index.post.node)
update-core

View File

@ -19,29 +19,30 @@
+$ card card:agent:gall
+$ versioned-state
$% state:state-zero:store
state-1
state:state-one:store
state-2
==
+$ unread-stats
[indices=(set index:graph-store) last=@da]
::
+$ state-1
$: %1
unreads-each=(jug index:store index:graph-store)
unreads-count=(map index:store @ud)
last-seen=(map index:store @da)
+$ state-2
$: unreads-each=(jug stats-index:store index:graph-store)
unreads-count=(map stats-index:store @ud)
last-seen=(map stats-index:store @da)
=notifications:store
archive=notifications:store
current-timebox=@da
dnd=_|
==
::
+$ inflated-state
$: state-1
$: state-2
cache
==
:: $cache: useful to have precalculated, but can be derived from state
:: albeit expensively
+$ cache
$: by-index=(jug index:store @da)
$: by-index=(jug stats-index:store @da)
~
==
::
@ -76,8 +77,10 @@
=| cards=(list card)
|^
?- -.old
%2 [cards this]
::
%1
[cards this(+.state (inflate-cache:ha old), -.state old)]
$(old *state-two)
::
%0
@ -92,6 +95,16 @@
==
==
==
::
++ clear-mention-unreads
|* =mold
|= unreads=(map index mold)
%+ murn
~(gas by unreads)
|= [=index value=mold]
?. ?=(%graph -.index) `[index value]
?: =(description.index 'mention') ~
`[index value]
++ convert-notifications-1
|= old=notifications:state-zero:store
%+ gas:orm *notifications:store
@ -388,7 +401,7 @@
(~(put ^in indices) unread)
::
++ read-index-each
|= [=index:store ref=index:graph-store]
|= [=stats-index:store ref=index:graph-store]
%+ read-boxes index
%+ skim
~(tap ^in (~(get ju by-index) index))
@ -415,11 +428,11 @@
poke-core(unreads-each (jub index f))
::
++ unread-count
|= [=index:store time=@da]
|= [=stats-index:store time=@da]
=/ new-count
+((~(gut by unreads-count) index 0))
+((~(gut by unreads-count) stats-index 0))
=. unreads-count
(~(put by unreads-count) index new-count)
(~(put by unreads-count) stats-index new-count)
(seen-index:(give %unread-count index time) time index)
::
++ read-count
@ -428,16 +441,29 @@
(give:(read-index index) %read-count index)
::
++ read-index
|= =index:store
(read-boxes index ~(tap ^in (~(get ju by-index) index)))
|= =stats-index:store
(read-boxes stats-index ~(tap ^in (~(get ju by-index) stats-index)))
::
++ read-boxes
|= [=index:store boxes=(list @da)]
|= [=stats-index:store boxes=(list @da)]
?~ boxes poke-core
=/ core=_poke-core
(read-note i.boxes index)
$(poke-core core, boxes t.boxes)
::
++ read-stats-index
|= [time=@da =stats-index]
=/ keys
~(tap in ~(key by (get:orm notifications time)))
|- ^+ poke-core
?~ read-note
poke-core
?. (stats-index-is-index:store stats-index i.keys)
$(keys t.keys)
=/ core
(read-note time i.keys)
$(poke-core core, keys t.keys)
::
++ seen-index
|= [time=@da =index:store]
=/ new-time=@da
@ -522,6 +548,7 @@
^- (list [@da timebox:store])
%+ skim (tap:orm notifications)
|=([@da =timebox:store] !=(~(wyt by timebox) 0))
::
++ upd-cache
|= [read=? time=@da =index:store]
@ -529,7 +556,7 @@
%_ +.state
::
by-index
%. [index time]
%. [(to-stats-index:store index) time]
?: read
~(del ju by-index)
~(put ju by-index)

View File

@ -27,6 +27,17 @@
description+so
index+(su ;~(pfix fas (more fas dem)))
==
::
++ stats-index
%- of
:~ graph+graph-stats-index
group+dejs:resource
==
++ graph-stats-index
%- ot
:~ graph+dejs:resource
index+graph-index
==
:: parse date as @ud
:: TODO: move to zuse
++ sd
@ -41,6 +52,8 @@
:~ time+sd
index+index
==
++ graph-index
(su ;~(pfix fas (more fas dem)))
::
++ add
|= jon=json
@ -48,8 +61,8 @@
::
++ read-graph-index
%- ot
:~ index+index
target+(su ;~(pfix fas (more fas dem)))
:~ index+stats-index
target+graph-index
==
::
++ action
@ -61,7 +74,7 @@
read-note+notif-ref
add-note+add
set-dnd+bo
read-count+index
read-count+stats-index
read-each+read-graph-index
==
--
@ -81,7 +94,7 @@
%count (numb count.upd)
%more (more +.upd)
%read-each (read-each +.upd)
%read-count (index +.upd)
%read-count (stats-index +.upd)
%unread-each (unread-each +.upd)
%unread-count (unread-count +.upd)
%seen-index (seen-index +.upd)
@ -91,16 +104,33 @@
(notif-ref +.upd)
==
::
++ stats-index
|= s=^stats-index
%+ frond -.s
|^
?- -.s
%graph (graph-stats-index +.s)
%group (enjs:resource +.s)
==
::
++ graph-stats-index
|= [graph=resource =index:graph-store]
%- pairs
:~ graph+(enjs:resource graph)
index+(index:enjs:graph-store index)
==
--
::
++ unreads
|= l=(list [^index ^index-stats])
|= l=(list [^stats-index ^stats])
^- json
:- %a
^- (list json)
%+ turn l
|= [idx=^index stats=^index-stats]
|= [idx=^stats-index s=^stats]
%- pairs
:~ stats+(index-stats stats)
index+(index idx)
:~ stats+(stats s)
index+(stats-index idx)
==
::
++ unread
@ -114,13 +144,13 @@
(numb num.unreads)
==
::
++ index-stats
|= stats=^index-stats
++ stats
|= s=^stats
^- json
%- pairs
:~ unreads+(unread unreads.stats)
notifications+(numb notifications.stats)
last+(time last-seen.stats)
:~ unreads+(unread unreads.s)
notifications+(numb notifications.s)
last+(time last-seen.s)
==
++ added
|= [tim=@da idx=^index not=^notification]
@ -139,11 +169,11 @@
index+(index idx)
==
++ seen-index
|= [tim=@da idx=^index]
|= [tim=@da idx=^stats-index]
^- json
%- pairs
:~ time+(time tim)
index+(index idx)
index+(stats-index idx)
==
::
++ more
@ -244,26 +274,45 @@
==
::
++ read-each
|= [=^index target=index:graph-store]
|= [s=^stats-index target=index:graph-store]
%- pairs
:~ index+(^index index)
:~ index+(stats-index s)
target+(index:enjs:graph-store target)
==
::
++ unread-each
|= [=^index target=index:graph-store tim=@da]
|= [s=^stats-index target=index:graph-store tim=@da]
%- pairs
:~ index+(^index index)
:~ index+(stats-index s)
target+(index:enjs:graph-store target)
last+(time tim)
==
::
++ unread-count
|= [=^index tim=@da]
|= [s=^stats-index tim=@da]
%- pairs
:~ index+(^index index)
:~ index+(stats-index s)
last+(time tim)
==
--
--
::
++ to-stats-index
|= =index
^- stats-index
?- -.index
%graph [%graph graph.index index.index]
%group [%group group.index]
==
++ stats-index-is-index
|= [=stats-index =index]
?- -.index
%graph
?. ?=(%graph -.stats-index) %.n
=([graph index]:index [graph index]:stats-index)
::
%group
?. ?=(%group -.stats-index) %.n
=(group:index group:stats-index)
==
--

View File

@ -35,6 +35,19 @@
[date=@da read=? =contents]
--
::
++ state-one
|%
+$ state-1
$: unreads-each=(jug index index:graph-store)
unreads-count=(map index @ud)
last-seen=(map index @da)
=notifications
archive=notifications
current-timebox=@da
dnd=_|
==
--
::
+$ index
$% $: %graph
group=resource
@ -70,26 +83,32 @@
$% [%add-note =index =notification]
[%archive time=@da index]
::
[%unread-count =index =time]
[%read-count =index]
[%unread-count =stats-index =time]
[%read-count =stats-index]
::
[%unread-each =index ref=index:graph-store time=@da]
[%read-each index ref=index:graph-store]
::
[%unread-each =stats-index ref=index:graph-store time=@da]
[%read-each =stats-index ref=index:graph-store]
::
[%read-note time=@da index]
[%unread-note time=@da index]
::
[%seen-index time=@da =index]
[%seen-index time=@da =stats-index]
::
[%read-all ~]
[%set-dnd dnd=?]
[%seen ~]
==
::
++ stats-index
$% [%graph graph=resource =index:graph-store]
[%group group=resource]
==
::
+$ indexed-notification
[index notification]
::
+$ index-stats
+$ stats
[notifications=@ud =unreads last-seen=@da]
::
+$ unreads
@ -103,6 +122,6 @@
[%added time=@da =index =notification]
[%timebox time=@da archived=? =(list [index notification])]
[%count count=@ud]
[%unreads unreads=(list [index index-stats])]
[%unreads unreads=(list [stats-index stats])]
==
--