urbit/pkg/arvo/lib/hark/store.hoon

285 lines
6.1 KiB
Plaintext
Raw Normal View History

2020-10-27 08:04:39 +03:00
/- sur=hark-store, post
2020-11-05 08:33:52 +03:00
/+ resource, graph-store, group-store, chat-store
2020-10-27 08:04:39 +03:00
^?
=< [. sur]
=, sur
|%
++ dejs
=, dejs:format
|%
++ index
%- of
:~ graph+graph-index
group+group-index
chat+chat-index
==
::
++ chat-index
%- ot
:~ chat+pa
mention+bo
2020-10-27 08:04:39 +03:00
==
::
++ group-index
%- ot
:~ group+dejs-path:resource
description+so
==
::
++ graph-index
%- ot
:~ group+dejs-path:resource
graph+dejs-path:resource
module+so
description+so
index+(su ;~(pfix fas (more fas dem)))
2020-10-27 08:04:39 +03:00
==
:: parse date as @ud
:: TODO: move to zuse
++ sd
|= jon=json
^- @da
?> ?=(%s -.jon)
`@da`(rash p.jon dem:ag)
::
++ notif-ref
^- $-(json [@da ^index])
%- ot
:~ time+sd
index+index
==
::
++ add
|= jon=json
[*^index *notification]
::
++ read-graph-index
%- ot
:~ index+index
target+(su ;~(pfix fas (more fas dem)))
==
::
2020-10-27 08:04:39 +03:00
++ action
^- $-(json ^action)
%- of
:~ seen+ul
archive+notif-ref
unread-note+notif-ref
read-note+notif-ref
add-note+add
2020-10-27 08:04:39 +03:00
set-dnd+bo
2020-12-01 08:46:28 +03:00
read-count+index
read-each+read-graph-index
2020-10-27 08:04:39 +03:00
==
--
::
++ enjs
=, enjs:format
|%
++ update
|= upd=^update
^- json
|^
%+ frond -.upd
?+ -.upd a+~
2020-10-28 08:52:59 +03:00
%added (added +.upd)
2020-10-27 08:04:39 +03:00
%timebox (timebox +.upd)
%set-dnd b+dnd.upd
%count (numb count.upd)
%more (more +.upd)
2020-12-01 08:46:28 +03:00
%read-each (read-each +.upd)
%read-count (index +.upd)
%unread-each (unread-each +.upd)
2020-12-01 08:46:28 +03:00
%unread-count (unread-count +.upd)
%unreads (unreads +.upd)
2020-11-10 06:32:48 +03:00
::
?(%archive %read-note %unread-note)
2020-10-27 08:04:39 +03:00
(notif-ref +.upd)
==
::
2020-11-16 05:22:42 +03:00
++ unreads
|= l=(list [^index ^index-stats])
2020-11-12 04:31:33 +03:00
^- json
2020-11-16 05:22:42 +03:00
:- %a
^- (list json)
%+ turn l
|= [idx=^index stats=^index-stats]
2020-11-12 04:31:33 +03:00
%- pairs
2020-12-01 08:46:28 +03:00
:~ stats+(index-stats stats)
2020-11-16 05:22:42 +03:00
index+(index idx)
==
2020-11-12 04:31:33 +03:00
::
++ unread
|= =^unreads
%+ frond
-.unreads
?- -.unreads
%each a+(turn ~(tap by indices.unreads) index:enjs:graph-store)
2020-12-01 08:46:28 +03:00
::
%count
(numb num.unreads)
==
::
++ index-stats
|= stats=^index-stats
^- json
%- pairs
:~ unreads+(unread unreads.stats)
notifications+(numb notifications.stats)
last+(time last-seen.stats)
==
2020-10-28 08:52:59 +03:00
++ added
|= [tim=@da idx=^index not=^notification]
^- json
%- pairs
:~ time+s+(scot %ud tim)
index+(index idx)
notification+(notification not)
==
::
2020-10-27 08:04:39 +03:00
++ notif-ref
|= [tim=@da idx=^index]
^- json
%- pairs
:~ time+s+(scot %ud tim)
index+(index idx)
==
::
++ more
|= upds=(list ^update)
^- json
a+(turn upds update)
::
++ index
|= =^index
%+ frond -.index
|^
?- -.index
%graph (graph-index +.index)
%group (group-index +.index)
%chat (chat-index +.index)
2020-10-27 08:04:39 +03:00
==
::
++ chat-index
|= [chat=^path mention=?]
^- json
%- pairs
:~ chat+(path chat)
mention+b+mention
==
2020-10-27 08:04:39 +03:00
::
++ graph-index
|= $: group=resource
graph=resource
module=@t
description=@t
idx=index:graph-store
==
2020-10-27 08:04:39 +03:00
^- json
%- pairs
:~ group+s+(enjs-path:resource group)
graph+s+(enjs-path:resource graph)
module+s+module
description+s+description
index+(index:enjs:graph-store idx)
2020-10-27 08:04:39 +03:00
==
::
++ group-index
|= [group=resource description=@t]
^- json
%- pairs
:~ group+s+(enjs-path:resource group)
description+s+description
==
--
::
++ notification
|= ^notification
^- json
%- pairs
:~ time+(time date)
read+b+read
contents+(^contents contents)
==
::
++ contents
|= =^contents
^- json
%+ frond -.contents
|^
?- -.contents
%graph (graph-contents +.contents)
%group (group-contents +.contents)
2020-11-05 08:33:52 +03:00
%chat (chat-contents +.contents)
2020-10-27 08:04:39 +03:00
==
::
2020-11-05 08:33:52 +03:00
++ chat-contents
|= =(list envelope:chat-store)
^- json
:- %a
(turn list envelope:enjs:chat-store)
::
2020-10-27 08:04:39 +03:00
++ graph-contents
|= =(list post:post)
^- json
:- %a
(turn list post:enjs:graph-store)
::
++ group-contents
|= =(list ^group-contents)
^- json
:- %a
%+ murn list
|= =^group-contents
?. ?=(?(%add-members %remove-members) -.group-contents)
~
`(update:enjs:group-store group-contents)
--
::
++ indexed-notification
|= [=^index =^notification]
%- pairs
:~ index+(^index index)
notification+(^notification notification)
==
::
++ timebox
|= [tim=@da arch=? l=(list [^index ^notification])]
^- json
%- pairs
:~ time+s+(scot %ud tim)
archive+b+arch
:- %notifications
^- json
:- %a
%+ turn l
|= [=^index =^notification]
^- json
(indexed-notification index notification)
==
::
2020-12-01 08:46:28 +03:00
++ read-each
|= [=^index target=index:graph-store]
%- pairs
:~ index+(^index index)
target+(index:enjs:graph-store target)
==
::
++ unread-each
|= [=^index target=index:graph-store tim=@da]
%- pairs
:~ index+(^index index)
target+(index:enjs:graph-store target)
last+(time tim)
==
::
2020-12-01 08:46:28 +03:00
++ unread-count
|= [=^index tim=@da]
%- pairs
:~ index+(^index index)
last+(time tim)
==
2020-10-27 08:04:39 +03:00
--
--
--