blob: 31fcd64a69c3ea1b46bc8ec6b4189dfe4af7f870 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/- feed=trill-feed, post=trill-post, sur=nostrill
/+ sr=sortug, constants
|%
++ latest-page
=/ count feed-page-size:constants
|= f=feed:feed ^- fc:feed
=/ nodelist (tap:orm:feed f)
=/ subset (scag count nodelist)
?~ subset [f ~ ~]
=/ start `-.i.subset
=/ rev (flop subset)
?~ rev [f ~ ~]
=/ end `-.i.rev
=/ nf (gas:orm:feed *feed:feed subset)
[nf start end]
::
++ latest-page-nostr |= f=nostr-feed:sur ^- nfc:sur
=/ nodelist (tap:norm:sur f)
=/ subset (scag feed-page-size:constants nodelist)
?~ subset [f ~ ~]
=/ start (some `@da`-.i.subset)
=/ rev (flop subset)
?~ rev [f ~ ~]
=/ end (some `@da`-.i.rev)
=/ nf (gas:norm:sur *nostr-feed:sur subset)
[nf start end]
::
:: NOTE START IS OLD, END IS NEW
++ subset
=/ count feed-page-size:constants
|= [=fc:feed replies=? now=@da] ^- fc:feed
?: ?&(?=(%~ start.fc) ?=(%~ end.fc)) (latest-page feed.fc)
=/ start ?~ start.fc 0 u.start.fc
=/ end ?~ end.fc now u.end.fc
=/ nodelist (tap:orm:feed feed.fc)
=/ threads %+ skim nodelist
|= [=id:post =post:post] ^- ?
?. replies
?&
?= %~ parent.post
(lte id start) (gte id end)
==
?& (lte id start) (gte id end) ==
=/ thread-count (lent threads)
:: TODO I remember something was weird about this
:: =/ result=(list [id:post post:post]) ?: newest (scag count threads) (flop (scag count (flop threads)))
=/ result=(list [id:post post:post]) (scag count threads)
=/ cursors=[(unit @da) (unit @da)] ?~ result [~ ~] ?~ threads [~ ~] :-
?: .=((head result) (head threads)) ~ `id:(head result)
?: .=((rear result) (rear threads)) ~ `id:(rear result)
[(gas:orm:feed *feed:feed result) -.cursors +.cursors]
:: posts
++ node-to-full
|= [p=post:post f=feed:feed] ^- full-node:post
p(children (convert-children children.p f))
++ convert-children
|= [children=(set id:post) f=feed:feed]
^- internal-graph:post
=/ g=full-graph:post %- ~(rep in children)
|= [=id:post acc=full-graph:post]
=/ n (get:orm:feed f id)
?~ n acc
=/ full-node (node-to-full u.n f)
(put:form:post acc id full-node)
?~ children [%empty ~]
:- %full g
::
++ add-new-feed
|= [global=feed:feed new=feed:feed] ^- feed:feed
=/ poasts (tap:orm:feed new)
|- ?~ poasts global
=/ poast +.i.poasts
=. global (insert-to-global global poast)
$(poasts t.poasts)
++ consolidate-feeds
|= feeds=(list [* feed:feed]) ^- feed:feed
=| nf=feed:feed
|- ?~ feeds nf
=/ poasts (tap:orm:feed +.i.feeds)
=. nf |- ?~ poasts nf
=/ poast +.i.poasts
=. nf (insert-to-global nf poast)
$(poasts t.poasts)
$(feeds t.feeds)
++ find-available-id
=| tries=@ud
|= [f=feed:feed id=@da] ^- @da
?: (gte tries 20) ~|('find-available-id stack overflow' !!)
?. (has:orm:feed f id) id
$(id +(id), tries +(tries))
++ insert-to-global
|= [f=feed:feed p=post:post] ^- feed:feed
=/ nid (find-available-id f id.p)
(put:orm:feed f nid p)
--
|