2020-10-21 08:54:59 +03:00
|
|
|
:: hark-store: notifications [landscape]
|
|
|
|
::
|
|
|
|
/- store=hark-store, post, group-store, metadata-store
|
|
|
|
/+ resource, metadata, default-agent, dbug, graph-store
|
|
|
|
::
|
|
|
|
~% %hark-store-top ..is ~
|
|
|
|
|%
|
|
|
|
+$ card card:agent:gall
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-0
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ state-0
|
|
|
|
$: %0
|
|
|
|
=notifications:store
|
|
|
|
archive=notifications:store
|
|
|
|
last-seen=@da
|
2020-11-12 03:34:51 +03:00
|
|
|
dnd=_|
|
2020-10-21 08:54:59 +03:00
|
|
|
==
|
2020-10-27 08:07:13 +03:00
|
|
|
+$ inflated-state
|
|
|
|
$: state-0
|
|
|
|
cache
|
|
|
|
==
|
|
|
|
:: $cache: useful to have precalculated, but can be derived from state
|
|
|
|
:: albeit expensively
|
|
|
|
+$ cache
|
|
|
|
$: unread-count=@ud
|
2020-11-16 05:22:42 +03:00
|
|
|
by-index=(jug index:store @da)
|
2020-10-27 08:07:13 +03:00
|
|
|
~
|
|
|
|
==
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
2020-11-16 06:52:45 +03:00
|
|
|
++ orm ((ordered-map @da timebox:store) gth)
|
2020-10-21 08:54:59 +03:00
|
|
|
--
|
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
=| inflated-state
|
2020-10-21 08:54:59 +03:00
|
|
|
=* state -
|
|
|
|
::
|
|
|
|
=<
|
|
|
|
%- agent:dbug
|
|
|
|
^- agent:gall
|
|
|
|
~% %hark-store-agent ..card ~
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
ha ~(. +> bowl)
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
met ~(. metadata bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
:_ this
|
|
|
|
~[autoseen-timer]
|
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
++ on-save !>(-.state)
|
2020-10-21 08:54:59 +03:00
|
|
|
++ on-load
|
2020-10-27 08:07:13 +03:00
|
|
|
|= =old=vase
|
2020-10-21 08:54:59 +03:00
|
|
|
^- (quip card _this)
|
2020-10-27 08:07:13 +03:00
|
|
|
=/ old
|
|
|
|
!<(state-0 old-vase)
|
2020-11-16 06:52:45 +03:00
|
|
|
=. notifications.old
|
|
|
|
(gas:orm *notifications:store (tap:orm notifications.old))
|
|
|
|
=. archive.old
|
|
|
|
(gas:orm *notifications:store (tap:orm archive.old))
|
2020-10-27 08:07:13 +03:00
|
|
|
`this(-.state old, +.state (inflate-cache old))
|
|
|
|
::
|
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
|^
|
|
|
|
?+ path (on-watch:def path)
|
|
|
|
::
|
|
|
|
[%updates ~]
|
|
|
|
:_ this
|
|
|
|
[%give %fact ~ hark-update+!>(initial-updates)]~
|
|
|
|
==
|
2020-11-10 06:32:48 +03:00
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
++ initial-updates
|
|
|
|
^- update:store
|
|
|
|
:- %more
|
|
|
|
^- (list update:store)
|
2020-11-16 05:22:42 +03:00
|
|
|
:- unreads
|
2020-10-27 08:07:13 +03:00
|
|
|
:+ [%set-dnd dnd]
|
|
|
|
[%count unread-count]
|
|
|
|
%+ weld
|
|
|
|
%+ turn
|
2020-11-16 06:52:45 +03:00
|
|
|
%+ scag 3
|
2020-11-12 03:26:24 +03:00
|
|
|
(tap-nonempty:ha archive)
|
2020-10-27 08:07:13 +03:00
|
|
|
(timebox-update &)
|
|
|
|
%+ turn
|
2020-11-16 06:52:45 +03:00
|
|
|
%+ scag 3
|
2020-11-12 03:26:24 +03:00
|
|
|
(tap-nonempty:ha notifications)
|
2020-10-27 08:07:13 +03:00
|
|
|
(timebox-update |)
|
|
|
|
::
|
2020-11-16 05:22:42 +03:00
|
|
|
++ unreads
|
|
|
|
^- update:store
|
|
|
|
:- %unreads
|
|
|
|
^- (list [index:store @ud])
|
|
|
|
%+ turn
|
|
|
|
~(tap by by-index)
|
|
|
|
|=([=index:store =(set @da)] [index ~(wyt in set)])
|
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
++ timebox-update
|
|
|
|
|= archived=?
|
|
|
|
|= [time=@da =timebox:store]
|
|
|
|
^- update:store
|
|
|
|
[%timebox time archived ~(tap by timebox)]
|
|
|
|
--
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
++ on-peek
|
|
|
|
|= =path
|
|
|
|
^- (unit (unit cage))
|
|
|
|
?+ path (on-peek:def path)
|
|
|
|
::
|
2020-11-16 06:53:18 +03:00
|
|
|
[%x %recent ?(%archive %inbox) @ @ ~]
|
|
|
|
=/ is-archive
|
|
|
|
=(%archive i.t.t.path)
|
2020-10-27 08:07:13 +03:00
|
|
|
=/ offset=@ud
|
|
|
|
(slav %ud i.t.t.t.path)
|
2020-11-16 06:53:18 +03:00
|
|
|
=/ length=@ud
|
|
|
|
(slav %ud i.t.t.t.t.path)
|
2020-11-12 03:26:24 +03:00
|
|
|
:^ ~ ~ %hark-update
|
2020-11-03 03:36:00 +03:00
|
|
|
!> ^- update:store
|
|
|
|
:- %more
|
|
|
|
%+ turn
|
2020-11-12 03:26:24 +03:00
|
|
|
%+ scag length
|
|
|
|
%+ slag offset
|
2020-11-16 06:53:18 +03:00
|
|
|
%- tap-nonempty:ha
|
|
|
|
?:(is-archive archive notifications)
|
2020-11-03 03:36:00 +03:00
|
|
|
|= [time=@da =timebox:store]
|
|
|
|
^- update:store
|
2020-11-16 06:53:18 +03:00
|
|
|
:^ %timebox time is-archive
|
2020-11-03 03:36:00 +03:00
|
|
|
~(tap by timebox)
|
2020-10-27 08:07:13 +03:00
|
|
|
==
|
2020-11-10 06:32:48 +03:00
|
|
|
::
|
2020-10-21 08:54:59 +03:00
|
|
|
++ on-poke
|
|
|
|
~/ %hark-store-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
|^
|
|
|
|
?> (team:title our.bowl src.bowl)
|
|
|
|
=^ cards state
|
|
|
|
?+ mark (on-poke:def mark vase)
|
|
|
|
%hark-action (hark-action !<(action:store vase))
|
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
++ hark-action
|
|
|
|
|= =action:store
|
|
|
|
^- (quip card _state)
|
|
|
|
|^
|
|
|
|
?- -.action
|
|
|
|
%add (add +.action)
|
|
|
|
%archive (do-archive +.action)
|
|
|
|
%seen seen
|
|
|
|
%read (read +.action)
|
2020-11-16 05:22:42 +03:00
|
|
|
%read-index (read-index +.action)
|
2020-10-21 08:54:59 +03:00
|
|
|
%unread (unread +.action)
|
2020-10-27 08:07:13 +03:00
|
|
|
%set-dnd (set-dnd +.action)
|
2020-10-21 08:54:59 +03:00
|
|
|
==
|
|
|
|
++ add
|
|
|
|
|= [=index:store =notification:store]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ =timebox:store
|
|
|
|
(gut-orm:ha notifications last-seen)
|
|
|
|
=/ existing-notif
|
|
|
|
(~(get by timebox) index)
|
|
|
|
=/ new=notification:store
|
|
|
|
?~ existing-notif
|
|
|
|
notification
|
|
|
|
(merge-notification:ha u.existing-notif notification)
|
2020-11-25 03:51:05 +03:00
|
|
|
=/ new-read=?
|
|
|
|
?~ existing-notif
|
|
|
|
%.y
|
|
|
|
read.u.existing-notif
|
|
|
|
=. read.new %.n
|
2020-10-22 04:30:37 +03:00
|
|
|
=/ new-timebox=timebox:store
|
2020-10-21 08:54:59 +03:00
|
|
|
(~(put by timebox) index new)
|
2020-10-28 08:52:59 +03:00
|
|
|
:- (give:ha [/updates]~ %added last-seen index new)
|
|
|
|
%_ state
|
2020-11-25 03:51:05 +03:00
|
|
|
+ ?.(new-read +.state (upd-unreads:ha index last-seen %.n))
|
2020-10-28 08:52:59 +03:00
|
|
|
notifications (put:orm notifications last-seen new-timebox)
|
|
|
|
==
|
2020-11-16 05:22:42 +03:00
|
|
|
++ read-index
|
|
|
|
|= =index:store
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ times=(list @da)
|
|
|
|
~(tap in (~(gut by by-index) index ~))
|
|
|
|
=| cards=(list card)
|
|
|
|
|-
|
|
|
|
?~ times
|
|
|
|
[cards state]
|
|
|
|
=* time i.times
|
|
|
|
=^ crds state
|
|
|
|
(read time index)
|
|
|
|
$(cards (weld cards crds), times t.times)
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
|
|
|
++ do-archive
|
|
|
|
|= [time=@da =index:store]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ =timebox:store
|
|
|
|
(gut-orm:ha notifications time)
|
|
|
|
=/ =notification:store
|
|
|
|
(~(got by timebox) index)
|
2020-10-22 04:30:37 +03:00
|
|
|
=/ new-timebox=timebox:store
|
2020-10-21 08:54:59 +03:00
|
|
|
(~(del by timebox) index)
|
|
|
|
:- (give:ha [/updates]~ %archive time index)
|
|
|
|
%_ state
|
2020-11-16 05:22:42 +03:00
|
|
|
+ ?.(read.notification (upd-unreads:ha index time %.y) +.state)
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
|
|
|
notifications
|
2020-10-22 04:30:37 +03:00
|
|
|
(put:orm notifications time new-timebox)
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
|
|
|
archive
|
|
|
|
%^ jub-orm:ha archive time
|
2020-10-22 04:30:37 +03:00
|
|
|
|= archive-box=timebox:store
|
2020-10-21 08:54:59 +03:00
|
|
|
^- timebox:store
|
2020-10-27 08:07:13 +03:00
|
|
|
(~(put by archive-box) index notification(read %.y))
|
2020-10-21 08:54:59 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ read
|
|
|
|
|= [time=@da =index:store]
|
|
|
|
^- (quip card _state)
|
|
|
|
:- (give:ha [/updates]~ %read time index)
|
2020-10-28 08:52:59 +03:00
|
|
|
%_ state
|
2020-11-16 05:22:42 +03:00
|
|
|
+ (upd-unreads:ha index time %.y)
|
2020-10-28 08:52:59 +03:00
|
|
|
unread-count (dec unread-count)
|
|
|
|
notifications (change-read-status:ha time index %.y)
|
|
|
|
==
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
|
|
|
++ unread
|
|
|
|
|= [time=@da =index:store]
|
|
|
|
^- (quip card _state)
|
|
|
|
:- (give:ha [/updates]~ %unread time index)
|
2020-10-28 08:52:59 +03:00
|
|
|
%_ state
|
2020-11-16 05:22:42 +03:00
|
|
|
+ (upd-unreads:ha index time %.n)
|
2020-10-28 08:52:59 +03:00
|
|
|
unread-count +(unread-count)
|
|
|
|
notifications (change-read-status:ha time index %.n)
|
|
|
|
==
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
|
|
|
++ seen
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ state(last-seen now.bowl)
|
|
|
|
:~ cancel-autoseen:ha
|
|
|
|
autoseen-timer:ha
|
|
|
|
==
|
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
++ set-dnd
|
|
|
|
|= d=?
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ state(dnd d)
|
|
|
|
(give:ha [/updates]~ %set-dnd d)
|
2020-10-21 08:54:59 +03:00
|
|
|
--
|
|
|
|
--
|
|
|
|
::
|
|
|
|
++ on-agent on-agent:def
|
|
|
|
::
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-arvo
|
|
|
|
|= [=wire =sign-arvo]
|
|
|
|
^- (quip card _this)
|
|
|
|
?. ?=([%autoseen ~] wire)
|
|
|
|
(on-arvo:def wire sign-arvo)
|
|
|
|
?> ?=([%b %wake *] sign-arvo)
|
|
|
|
:_ this(last-seen now.bowl)
|
|
|
|
~[autoseen-timer:ha]
|
|
|
|
::
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* met ~(. metadata bowl)
|
|
|
|
::
|
2020-11-12 03:26:24 +03:00
|
|
|
++ tap-nonempty
|
|
|
|
|= =notifications:store
|
|
|
|
^- (list [@da timebox:store])
|
|
|
|
%+ skip (tap:orm notifications)
|
|
|
|
|=([@da =timebox:store] =(0 ~(wyt by timebox)))
|
|
|
|
::
|
2020-10-21 08:54:59 +03:00
|
|
|
++ merge-notification
|
|
|
|
|= [existing=notification:store new=notification:store]
|
|
|
|
^- notification:store
|
|
|
|
?- -.contents.existing
|
2020-11-05 05:50:56 +03:00
|
|
|
::
|
|
|
|
%chat
|
|
|
|
?> ?=(%chat -.contents.new)
|
|
|
|
existing(list.contents (weld list.contents.existing list.contents.new))
|
2020-10-21 08:54:59 +03:00
|
|
|
::
|
|
|
|
%graph
|
|
|
|
?> ?=(%graph -.contents.new)
|
|
|
|
existing(list.contents (weld list.contents.existing list.contents.new))
|
|
|
|
::
|
|
|
|
%group
|
|
|
|
?> ?=(%group -.contents.new)
|
|
|
|
existing(list.contents (weld list.contents.existing list.contents.new))
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ change-read-status
|
|
|
|
|= [time=@da =index:store read=?]
|
|
|
|
^+ notifications
|
|
|
|
%^ jub-orm notifications time
|
|
|
|
|= =timebox:store
|
|
|
|
%+ ~(jab by timebox) index
|
|
|
|
|= =notification:store
|
2020-10-27 08:07:13 +03:00
|
|
|
?> !=(read read.notification)
|
2020-10-21 08:54:59 +03:00
|
|
|
notification(read read)
|
2020-10-27 08:07:13 +03:00
|
|
|
:: +key-orm: +key:by for ordered maps
|
|
|
|
++ key-orm
|
|
|
|
|= =notifications:store
|
|
|
|
^- (list @da)
|
|
|
|
(turn (tap:orm notifications) |=([key=@da =timebox:store] key))
|
2020-10-21 08:54:59 +03:00
|
|
|
:: +jub-orm: combo +jab/+gut for ordered maps
|
2020-10-22 04:30:37 +03:00
|
|
|
:: TODO: move to zuse.hoon
|
2020-10-21 08:54:59 +03:00
|
|
|
++ jub-orm
|
|
|
|
|= [=notifications:store time=@da fun=$-(timebox:store timebox:store)]
|
|
|
|
^- notifications:store
|
|
|
|
=/ =timebox:store
|
|
|
|
(fun (gut-orm notifications time))
|
|
|
|
(put:orm notifications time timebox)
|
2020-10-22 04:30:37 +03:00
|
|
|
:: +gut-orm: +gut:by for ordered maps
|
|
|
|
:: TODO: move to zuse.hoon
|
2020-10-21 08:54:59 +03:00
|
|
|
++ gut-orm
|
|
|
|
|= [=notifications:store time=@da]
|
|
|
|
^- timebox:store
|
|
|
|
(fall (get:orm notifications time) ~)
|
|
|
|
::
|
|
|
|
++ autoseen-interval ~h3
|
|
|
|
++ cancel-autoseen
|
|
|
|
^- card
|
|
|
|
[%pass /autoseen %arvo %b %rest (add last-seen autoseen-interval)]
|
|
|
|
::
|
|
|
|
++ autoseen-timer
|
|
|
|
^- card
|
|
|
|
[%pass /autoseen %arvo %b %wait (add now.bowl autoseen-interval)]
|
|
|
|
::
|
|
|
|
++ give
|
|
|
|
|= [paths=(list path) update=update:store]
|
|
|
|
^- (list card)
|
2020-10-27 08:07:13 +03:00
|
|
|
[%give %fact paths [%hark-update !>(update)]]~
|
|
|
|
::
|
2020-11-12 04:31:33 +03:00
|
|
|
++ upd-unreads
|
2020-11-16 05:22:42 +03:00
|
|
|
|= [=index:store time=@da read=?]
|
2020-11-12 04:31:33 +03:00
|
|
|
^+ +.state
|
2020-11-16 05:22:42 +03:00
|
|
|
%_ +.state
|
|
|
|
::
|
|
|
|
by-index
|
|
|
|
%. [index time]
|
2020-11-12 04:31:33 +03:00
|
|
|
?: read
|
2020-11-16 05:22:42 +03:00
|
|
|
~(del ju by-index)
|
|
|
|
~(put ju by-index)
|
|
|
|
==
|
2020-11-12 04:31:33 +03:00
|
|
|
::
|
2020-10-27 08:07:13 +03:00
|
|
|
++ inflate-cache
|
|
|
|
|= state-0
|
2020-11-12 04:31:33 +03:00
|
|
|
^+ +.state
|
|
|
|
=/ nots=(list [p=@da =timebox:store])
|
2020-10-27 08:07:13 +03:00
|
|
|
(tap:orm notifications)
|
2020-11-12 04:31:33 +03:00
|
|
|
|- =* outer $
|
|
|
|
?~ nots
|
|
|
|
+.state
|
|
|
|
=/ unreads ~(tap by timebox.i.nots)
|
|
|
|
|- =* inner $
|
|
|
|
?~ unreads
|
|
|
|
outer(nots t.nots)
|
2020-10-27 08:07:13 +03:00
|
|
|
=* notification q.i.unreads
|
2020-11-12 04:31:33 +03:00
|
|
|
=* index p.i.unreads
|
2020-10-27 08:07:13 +03:00
|
|
|
?: read.notification
|
2020-11-12 04:31:33 +03:00
|
|
|
inner(unreads t.unreads)
|
|
|
|
=. +.state
|
2020-11-16 05:22:42 +03:00
|
|
|
(upd-unreads index p.i.nots %.n)
|
2020-11-12 04:31:33 +03:00
|
|
|
inner(unreads t.unreads)
|
2020-10-21 08:54:59 +03:00
|
|
|
--
|