summaryrefslogtreecommitdiff
path: root/desk/lib/scri.hoon
blob: e76d79a50217c3382f66dac26dd25a567bfaad4f (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
/-  sur=nostrill, nsur=nostr, comms=nostrill-comms,
    post=trill-post, gate=trill-gate, feed=trill-feed
    
/+  appjs=json-nostrill,
    lib=nostrill,
    njs=json-nostr,
    feedlib=trill-feed,
    postlib=trill-post,
    shim,
    constants,
    sr=sortug

|_  [=state:sur =bowl:gall]
+$  card  card:agent:gall

++  get-poast  |=  [host=@p id=@]  ^-  (unit post:post)
  =/  poast  ?:  .=(host our.bowl)
    (get:orm:feed feed.state id)
    ~
  poast



++  thread  |=  [hs=@t ids=@t]
  ^-  (unit (unit cage))  :-  ~  :-  ~  :-  %json  !>
  %-  beg-res:en:appjs
  ^-  res:comms
  =/  host  (slaw %p hs)
  ?~  host  [%ng 'Host is not a @p']
  :: TODO what about non urbit stuff
  =/  =user:sur  [%urbit u.host]
  =/  fed=(unit feed:feed)  ?:  .=(u.host our.bowl)  `feed.state  (~(get by following.state) user)
  ?~  fed  [%ng 'Feed not found']
  =/  id  (slaw:sr %ud ids)  ?~  id  [%ng 'Post ID malformed']
  =/  node  (get:orm:feed u.fed u.id)
  ?~  node  [%ng 'Post not found in feed']
  =/  fn  (node-to-full:feedlib u.node u.fed)
  [%ok %thread fn]

++  sfeed  |=  [hs=@t s=@t e=@t c=@ n=@ r=@]
  ^-  (unit (unit cage))  :-  ~  :-  ~  :-  %json  !>
  %-  beg-res:en:appjs
  ^-  res:comms
  =/  host  (slaw %p hs)
  ?~  host  [%ng 'Host is not a @p']
  =/  =user:sur  [%urbit u.host]
  =/  fed=(unit feed:feed)  ?:  .=(u.host our.bowl)  `feed.state  (~(get by following.state) user)
  ?~  fed  [%ng 'Feed not found']
  =/  start=(unit @da)  (timestamp:sr s)  
  =/  end               (timestamp:sr e) 
  =/  cont  (slaw:sr %ud c)
  =/  count  ?~  cont  feed-page-size:constants  u.cont
  =/  newest  !=('0' n)
  :: =/  nodelist  (tap:orm:feed u.fed)
  :: =/  replies=?  !=('0' r)
  :: =/  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)
  :: =/  result=(list [id:post post:post])  ?:  newest  (scag count threads)  (flop (scag count (flop threads)))
  :: =/  cursors=[(unit @da) (unit @da)]  ?~  result  [~ ~]  ?~  threads  [~ ~]  :-
  :: ?:  .=((head result) (head threads))  ~  `id:(head result)
  :: ?:  .=((rear result) (rear threads))  ~  `id:(rear result)
  :: =/  =fc:feed  [(gas:orm:feed *feed:feed result) -.cursors +.cursors]
  :: TODO counts and order
  =/  nf  (lot:orm:feed u.fed start end)
  =/  hed  (pry:orm:feed nf)
  =/  tal  (ram:orm:feed nf)
  =/  ns=(unit @da)  ?~  hed  ~  (some key.u.hed)
  =/  ne=(unit @da)  ?~  tal  ~  (some key.u.tal)
  =/  =fc:feed  [nf ns ne]
  =/  profile  (~(get by profiles.state) user)
  [%ok %feed fc profile]
--