-
Notifications
You must be signed in to change notification settings - Fork 9
/
rpcs.ur
252 lines (240 loc) · 9.73 KB
/
rpcs.ur
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
open Session
open Either
fun withUser [r] action (f : string -> transaction r) (l : list bgAction)
: transaction r =
u <- getUser action;
case u of
| Some u =>
t1 <- H.getUrTime;
d <- H.performBgActions u l;
r <- f u;
t2 <- H.getUrTime;
logAction' (action ^ if notNull l then "/bg" else "") d u (diffInMilliseconds t1 t2);
return r
| None => error <xml>Not logged in. Please, log in on the home page first.</xml>
val bgactions = withUser "" (fn u => return ())
fun readAssociatedAccounts u =
us <- H.readUserSettings u;
return (maybe [] (fn s => maybe [] (getF [#AssociatedAccounts]) s.Ex) us)
fun setEmail e : list Datatypes.bgAction -> transaction (either xbody (option string)) =
withUser "setEmail"
(fn userId =>
case H.validateEmail e of
| Some email =>
u <- H.getUserByLogin (LTEmail { Email = email}) None;
(case u of
| Some euid =>
if userId = euid then
return (Right None)
else
return (Left <xml>The email
{emailX email} is busy.
Try another one or log into that account
and change its email or delete it.</xml>)
| None =>
h <- getHost;
ok <- H.sendChangeEmailEmail h userId email;
return (if ok then Right (Some email) else Left (txt
"Too many confirmation emails. Please, check your spam folder.")))
| None =>
return (Left (txt "Please, enter valid email")))
fun setUsername u =
withUser "setUsername"
(fn userId =>
h <- getHost;
ok <- H.setUsername (Some h) userId u;
if ok then
logOutOtherSessions;
aa <- readAssociatedAccounts userId;
return (Some aa)
else
return None)
fun setPassword p =
withUser "setPassword"
(fn userId =>
logOutOtherSessions;
h <- getHost;
H.setPassword (Some h) userId p)
fun removeAssociatedAccount a =
withUser "removeAssociatedAccount"
(fn userId =>
logOutOtherSessions;
h <- getHost;
ok <- H.tryRemoveAssociatedAccount (Some h) userId a;
if ok then
Monad.mp some (readAssociatedAccounts userId)
else
return None)
fun readability key =
withUser "readability"
(fn u =>
h <- getHost;
al <- acceptLanguage;
H.getFullText u False h al key)
fun msg key = withUser "msg" (fn _ => H.readMsg key)
fun subscriptions' n uf bg t h siv fssh = withUser n
(fn userId =>
host <- getHost;
r <- H.subscriptionsAndRenames host bg uf t h siv fssh userId;
p <- H.getPaidTill userId;
ct <- now;
return (r, (p,ct)))
val subscriptions = subscriptions' "subscriptions" UFAll
val subscriptions_ = subscriptions' "subscriptions_" UFNone
val subscriptionsAndSettings = withUser "subscriptionsAndSettings"
(fn userId =>
host <- getHost;
H.subscriptionsAndSettings host True True userId)
val restoreSubscriptions = withUser "restoreSubscriptions"
(fn userId =>
H.restoreSubscriptionsFromBackup userId;
t <- H.getUrTime;
host <- getHost;
H.subscriptionsAndRenames host False UFChanged t "" "" "" userId)
fun markReqReadCounters vm mr mids = withUser "markReqReadCounters"
(fn userId =>
H.markReqReadCounters userId vm mr mids)
fun addSubscription t fssh url l =
if url = "" then error <xml>Empty feed URL</xml>
else withUser "addSubscription"
(fn userId =>
h <- H.userSubscribe userId url None [];
host <- getHost;
r <- H.subscriptionsAndRenames host False UFChanged t "" "" fssh userId;
return (h,r)) l
fun addDiscoverySubscription t fssh url country query l =
if url = "" then error <xml>Empty feed URL</xml>
else withUser "addDiscoverySubscription"
(fn userId =>
h <- H.userDiscoverySubscribe userId url country query None [];
host <- getHost;
r <- H.subscriptionsAndRenames host False UFChanged t "" "" fssh userId;
return (h,r)) l
fun renameSubscription t fssh url to l =
if url = "" then error <xml>Empty feed URL</xml>
else withUser "renameSubscription"
(fn userId =>
H.userRenameSubscription userId url to;
host <- getHost;
H.subscriptionsAndRenames host False UFNone t "" "" fssh userId) l
fun renameFolder t fssh from to l =
if to = "" then error <xml>Empty folder name</xml>
else withUser "renameFolder"
(fn userId =>
h <- H.userRenameFolder userId from to;
host <- getHost;
r <- H.subscriptionsAndRenames host False UFNone t "" "" fssh userId;
return (h,r)) l
fun editSubscriptionFolders t fssh url f add l =
if url = "" || f = "" then error <xml>Empty feed URL or folder</xml>
else withUser "editSubscriptionFolders"
(fn userId =>
H.userEditSubscriptionFolders userId url f add;
host <- getHost;
H.subscriptionsAndRenames host False UFNone t "" "" fssh userId) l
fun retrySubscription url =
withUser "retrySubscription"
(fn userId => H.userRetrySubscription userId url)
fun removeSubscriptions t fssh (urls : list string) =
withUser "removeSubscriptions"
(fn userId =>
H.userUnsubscribe userId urls;
host <- getHost;
H.subscriptionsAndRenames host False UFChanged t "" "" fssh userId)
fun getTree mtvm reqs =
withUser "getTree"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.getTree (AMNormal { HostName = h, AcceptLanguage = al })
userId mtvm reqs)
fun getTreeD url mtvm reqs =
withUser "getTree"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.getTree (AMDiscovery { HostName = h, AcceptLanguage = al,
Url = url })
userId mtvm reqs)
fun editFilters name q f t h siv fssh =
withUser name
(fn userId =>
r <- maybe (return None) H.checkQuerySyntax q;
case r of
| None =>
f userId;
host <- getHost;
s <- H.subscriptionsAndRenames host False UFChanged t h siv fssh userId;
return (Right s)
| Some e =>
return (Left e))
fun addFilter query negate feeds =
editFilters "addFilter" (Some query)
(fn u => H.addFilter u query negate feeds)
fun addSmartStream name query feeds =
editFilters "addSmartStream" (Some query)
(fn u => H.addSmartStream u name query feeds)
fun deleteFilter fid =
editFilters "deleteFilter" None (fn u => H.deleteFilter u fid)
fun deleteSmartStream name =
editFilters "deleteSmartStream" None (fn u => H.deleteSmartStream u name)
fun editFilter fid query negate feeds =
editFilters "editFilter" (Some query)
(fn u => H.editFilter u fid query negate feeds)
fun editSmartStream name query feeds =
editFilters "editSmartStream" (Some query)
(fn u => H.editSmartStream u name query feeds)
fun enablePublicFeed t = withUser "enablePublicFeed" (H.enablePublicFeed t)
fun disablePublicFeed t = withUser "disablePublicFeed" (H.disablePublicFeed t)
fun generateNewPublicFeed t = withUser "generateNewPublicFeed" (H.generateNewPublicFeed t)
fun discover country query =
withUser "discover"
(fn userId =>
host <- getHost;
H.discover host userId country query) []
fun feedDetails url =
withUser "feedDetails"
(fn userId =>
host <- getHost;
H.getFeedDetails host userId url) []
fun tagsForest ts vm =
withUser "tagsForest"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.tagsForest
(AMNormal { HostName = h, AcceptLanguage = al })
userId ts vm)
fun folderForest name feedsOrDiscovery vm =
withUser "folderForest"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.folderForest userId name feedsOrDiscovery [] vm h al)
fun smartStreamForest name feeds vm =
withUser "smartStreamForest"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.smartStreamForest
(AMNormal { HostName = h, AcceptLanguage = al })
userId name feeds vm)
fun filterForest q folder feedsOrDiscovery vm =
withUser "filterForest"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.filterForest userId None q folder feedsOrDiscovery vm h al)
fun filterSmartStreamForest n q feeds vm =
withUser "filterSmartStreamForest"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.filterForest userId (Some n) q None
(FODFeeds { ReadCounters = feeds }) vm h al)
fun filterTagsForest q tags vm =
withUser "filterTagsForest"
(fn userId =>
h <- getHost;
al <- acceptLanguage;
H.filterTagsForest userId q tags vm h al)