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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/- sur=nostrill, nsur=nostr, comms=nostrill-comms, feed=trill-feed, post=trill-post
/+ js=json-nostr, sr=sortug,constants, gatelib=trill-gate, feedlib=trill-feed, jsonlib=json-nostrill, lib=nostrill
|_ [=state:sur =bowl:gall]
++ cast-poke
|= raw=* ^- poke:comms
;; poke:comms raw
:: Req
++ handle-req |= =req:comms
?- -.req
%feed handle-feed
%thread (handle-thread +.req)
==
++ handle-feed
=/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl)
?. can
:: TODO keep track of the requests at the feed-perms struct
=/ crd (res-poke [%ng 'not allowed'])
:_ state :~(crd)
::
=/ lp latest-page:feedlib
=/ lp2 lp(count backlog.feed-perms.state)
=/ =fc:feed (lp2 feed.state)
=/ prof (~(get by profiles.state) [%urbit our.bowl])
=/ crd (res-poke [%ok %feed fc prof])
:_ state :~(crd)
++ give-feed
|= pat=path
~& give-feed=src.bowl
=/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl)
?. can
:: TODO keep track of the requests at the feed-perms struct
(res-fact [%ng 'not allowed'] pat)
::
=/ lp latest-page:feedlib
=/ lp2 lp(count backlog.feed-perms.state)
=/ =fc:feed (lp2 feed.state)
=/ prof (~(get by profiles.state) [%urbit our.bowl])
(res-fact [%ok %feed fc prof] pat)
++ give-ted |= [id=@ pat=path]
=/ ted (get:orm:feed feed.state id)
?~ ted
(res-fact [%ng 'no such thread'] pat)
=/ can (can-access:gatelib src.bowl read.u.ted bowl)
?. can
(res-fact [%ng 'not allowed'] pat)
::
=/ fn (node-to-full:feedlib u.ted feed.state)
(res-fact [%ok %thread fn] pat)
::
++ handle-thread |= id=@da
=/ ted (get:orm:feed feed.state id)
?~ ted
=/ crd (res-poke [%ng 'no such thread'])
:_ state :~(crd)
=/ can (can-access:gatelib src.bowl read.u.ted bowl)
?. can
=/ crd (res-poke [%ng 'not allowed'])
:_ state :~(crd)
::
=/ fn (node-to-full:feedlib u.ted feed.state)
=/ crd (res-poke [%ok %thread fn])
:_ state :~(crd)
:: res
++ handle-res |= =res:comms
`state
::
++ res-poke |= =res:comms ^- card:agent:gall
=/ =poke:comms [%res res]
=/ cage [%noun !>(poke)]
[%pass /poke %agent [src.bowl dap.bowl] %poke cage]
++ res-fact |= [=res:comms pat=path] ^- (list card:agent:gall)
=/ beg ?=([%beg *] pat)
=/ paths ~[pat]
~& > giving-res-fact=pat
?: beg :: for the thread that goes directly to the frontend
=/ jon (beg-res:en:jsonlib res)
=/ cage [%json !>(jon)]
=/ c1 [%give %fact paths cage]
=/ c2 [%give %kick paths ~]
:~(c1 c2)
:: for the follow flow
=/ cage [%noun !>([%init res])]
=/ c1 [%give %fact paths cage]
:~(c1)
:: engagement pokes, heads up when replying etc. to a post on your feed
++ handle-eng
|= e=engagement:comms
?- -.e
%reply
=/ poast (get:orm:feed feed.state parent.e)
?~ poast `state
=. children.u.poast (~(put in children.u.poast) id.child.e)
=. feed.state (put:orm:feed feed.state parent.e u.poast)
=. feed.state (put:orm:feed feed.state id.child.e child.e)
=/ f=fact:comms [%post %add child.e]
=/ f2=fact:comms [%post %changes u.poast]
:_ state
:~ (update-followers:cards:lib f)
(update-followers:cards:lib f2)
==
%del-reply
=. feed.state =< + (del:orm:feed feed.state child.e)
=/ poast (get:orm:feed feed.state parent.e)
?~ poast `state
=. children.u.poast (~(del in children.u.poast) child.e)
=. feed.state (put:orm:feed feed.state parent.e u.poast)
:_ state
:~ (update-followers:cards:lib [%post %changes u.poast])
(update-followers:cards:lib [%post %del child.e])
==
:: TODO ideally we want the full quote to display it within the post engagement. So do we change quoted.engagement.post? What if the quoter edits the quote down the line, etc.
%quote
=/ poast (get:orm:feed feed.state src.e)
?~ poast `state
=/ spid [*signature:post src.bowl id.post.e]
=. quoted.engagement.u.poast (~(put in quoted.engagement.u.poast) spid)
=. feed.state (put:orm:feed feed.state src.e u.poast)
=/ f=fact:comms [%post %changes u.poast]
:_ state
:~ (update-followers:cards:lib f)
==
%rp
=/ poast (get:orm:feed feed.state src.e)
?~ poast `state
=/ spid [*signature:post src.bowl rt.e]
=. shared.engagement.u.poast (~(put in shared.engagement.u.poast) spid)
=. feed.state (put:orm:feed feed.state src.e u.poast)
=/ f=fact:comms [%post %changes u.poast]
:_ state
:~ (update-followers:cards:lib f)
==
%reaction
=/ poast (get:orm:feed feed.state post.e)
?~ poast `state
:: TODO signatures et al.
=. reacts.engagement.u.poast (~(put by reacts.engagement.u.poast) src.bowl [reaction.e *signature:post])
=. feed.state (put:orm:feed feed.state post.e u.poast)
=/ f=fact:comms [%post %changes u.poast]
:_ state
:~ (update-followers:cards:lib f)
==
==
--
|