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

|_  [=state:sur =bowl:gall]
+$  card  card:agent:gall
++  debug-own-feed
  =/  postlist  (tap:orm:feed feed.state)  
  =/  lol
  |-  ?~  postlist  ~
    ~&  >>  poast=+.i.postlist
    $(postlist t.postlist)
  ~
  
:: state
++  add-to-feed  |=  p=post:post
  =.  feed.state  (put:orm:feed feed.state id.p p)
  state
  
++  handle-post  |=  poke=post-poke:ui:sur
  ^-  (quip card _state)
  =/  profile  (~(get by profiles.state) [%urbit our.bowl])
  =/  pubkey  pub.i.keys.state
  =/  p=post:post
    ?-  -.poke
      %add
        =/  sp     (build-sp:trill our.bowl our.bowl content.poke ~ ~)
        (build-post:trill now.bowl pubkey sp)
      %quote
        =/  sp     (build-sp:trill our.bowl our.bowl content.poke ~ ~)
        =/  quote  [%ref %trill host.poke /(crip (scow:sr %ud id.poke))]
        =.  contents.sp  (snoc contents.sp quote)
        (build-post:trill now.bowl pubkey sp)
      %reply
        =/  sp     (build-sp:trill host.poke our.bowl content.poke `id.poke `thread.poke)
        (build-post:trill now.bowl pubkey sp)
      %rp
        =/  quote  [%ref %trill host.poke /(crip (scow:sr %ud id.poke))]
        =/  sp     (build-sp:trill host.poke our.bowl '' ~ ~)
        =.  contents.sp  ~[quote]
        (build-post:trill now.bowl pubkey sp)
    ==
    =/  pw  [p (some pubkey) ~ ~ profile]
    =/  jfact=fact:ui:sur  [%post %add pw]
    =/  ui-card    (update-ui:cards:lib jfact)
    ::  only update followers when we are updating our own feed
    ?.  .=(our.bowl host.p)  [~[ui-card] state]
    =.  state  (add-to-feed p)
    =/  =fact:comms  [%post %add p]
    =/  fact-card  (update-followers:cards:lib fact)
    :_  state
    :~  ui-card
        fact-card
    ==


++  handle-post-fact  |=  pf=post-fact:comms
  ^-  (quip card _state)
  =/  =user:sur  [%urbit src.bowl]
  =/  fed  (~(get by following.state) user)
  ?~  fed  ~&  "emmm not following ya"  `state
  =/  nf=feed:feed
  ?:  ?=(%del -.pf)
        =<  +  (del:orm:feed u.fed id.pf)
    ::mmm people aren't supposed to update if its not their own feeds
    :: =/  =user:nsur  [%urbit host.p.pdf]
    (put:orm:feed u.fed id.p.pf p.pf)
  =.  following.state  (~(put by following.state) user nf)
   :: TODO update the ui with the changes 
   :_  state  ~
--