]> nmode's Git Repositories - signal-cli/blob - client/src/jsonrpc.rs
Update libsignal-service-java
[signal-cli] / client / src / jsonrpc.rs
1 use std::path::Path;
2
3 use jsonrpsee::async_client::ClientBuilder;
4 use jsonrpsee::core::client::{Error, SubscriptionClientT};
5 use jsonrpsee::http_client::HttpClientBuilder;
6 use jsonrpsee::proc_macros::rpc;
7 use serde::Deserialize;
8 use serde_json::Value;
9 use tokio::net::ToSocketAddrs;
10
11 #[rpc(client)]
12 pub trait Rpc {
13 #[method(name = "addDevice", param_kind = map)]
14 async fn add_device(
15 &self,
16 account: Option<String>,
17 uri: String,
18 ) -> Result<Value, ErrorObjectOwned>;
19
20 #[method(name = "addStickerPack", param_kind = map)]
21 async fn add_sticker_pack(
22 &self,
23 account: Option<String>,
24 uri: String,
25 ) -> Result<Value, ErrorObjectOwned>;
26
27 #[method(name = "block", param_kind = map)]
28 fn block(
29 &self,
30 account: Option<String>,
31 recipients: Vec<String>,
32 #[allow(non_snake_case)] groupIds: Vec<String>,
33 ) -> Result<Value, ErrorObjectOwned>;
34
35 #[method(name = "deleteLocalAccountData", param_kind = map)]
36 fn delete_local_account_data(
37 &self,
38 account: Option<String>,
39 #[allow(non_snake_case)] ignoreRegistered: Option<bool>,
40 ) -> Result<Value, ErrorObjectOwned>;
41
42 #[method(name = "getAttachment", param_kind = map)]
43 fn get_attachment(
44 &self,
45 account: Option<String>,
46 id: String,
47 recipient: Option<String>,
48 #[allow(non_snake_case)] groupId: Option<String>,
49 ) -> Result<Value, ErrorObjectOwned>;
50
51 #[method(name = "getAvatar", param_kind = map)]
52 fn get_avatar(
53 &self,
54 account: Option<String>,
55 contact: Option<String>,
56 profile: Option<String>,
57 #[allow(non_snake_case)] groupId: Option<String>,
58 ) -> Result<Value, ErrorObjectOwned>;
59
60 #[method(name = "getSticker", param_kind = map)]
61 fn get_sticker(
62 &self,
63 account: Option<String>,
64 #[allow(non_snake_case)] packId: String,
65 #[allow(non_snake_case)] stickerId: u32,
66 ) -> Result<Value, ErrorObjectOwned>;
67
68 #[method(name = "getUserStatus", param_kind = map)]
69 fn get_user_status(
70 &self,
71 account: Option<String>,
72 recipients: Vec<String>,
73 usernames: Vec<String>,
74 ) -> Result<Value, ErrorObjectOwned>;
75
76 #[method(name = "joinGroup", param_kind = map)]
77 fn join_group(&self, account: Option<String>, uri: String) -> Result<Value, ErrorObjectOwned>;
78
79 #[allow(non_snake_case)]
80 #[method(name = "finishChangeNumber", param_kind = map)]
81 fn finish_change_number(
82 &self,
83 account: Option<String>,
84 number: String,
85 verificationCode: String,
86 pin: Option<String>,
87 ) -> Result<Value, ErrorObjectOwned>;
88
89 #[method(name = "finishLink", param_kind = map)]
90 fn finish_link(
91 &self,
92 #[allow(non_snake_case)] deviceLinkUri: String,
93 #[allow(non_snake_case)] deviceName: String,
94 ) -> Result<Value, ErrorObjectOwned>;
95
96 #[method(name = "listAccounts", param_kind = map)]
97 fn list_accounts(&self) -> Result<Value, ErrorObjectOwned>;
98
99 #[method(name = "listContacts", param_kind = map)]
100 fn list_contacts(
101 &self,
102 account: Option<String>,
103 recipients: Vec<String>,
104 #[allow(non_snake_case)] allRecipients: bool,
105 blocked: Option<bool>,
106 name: Option<String>,
107 ) -> Result<Value, ErrorObjectOwned>;
108
109 #[method(name = "listDevices", param_kind = map)]
110 fn list_devices(&self, account: Option<String>) -> Result<Value, ErrorObjectOwned>;
111
112 #[method(name = "listGroups", param_kind = map)]
113 fn list_groups(
114 &self,
115 account: Option<String>,
116 #[allow(non_snake_case)] groupIds: Vec<String>,
117 ) -> Result<Value, ErrorObjectOwned>;
118
119 #[method(name = "listIdentities", param_kind = map)]
120 fn list_identities(
121 &self,
122 account: Option<String>,
123 number: Option<String>,
124 ) -> Result<Value, ErrorObjectOwned>;
125
126 #[method(name = "listStickerPacks", param_kind = map)]
127 fn list_sticker_packs(&self, account: Option<String>) -> Result<Value, ErrorObjectOwned>;
128
129 #[method(name = "quitGroup", param_kind = map)]
130 fn quit_group(
131 &self,
132 account: Option<String>,
133 #[allow(non_snake_case)] groupId: String,
134 delete: bool,
135 admins: Vec<String>,
136 ) -> Result<Value, ErrorObjectOwned>;
137
138 #[method(name = "register", param_kind = map)]
139 fn register(
140 &self,
141 account: Option<String>,
142 voice: bool,
143 captcha: Option<String>,
144 ) -> Result<Value, ErrorObjectOwned>;
145
146 #[method(name = "removeContact", param_kind = map)]
147 fn remove_contact(
148 &self,
149 account: Option<String>,
150 recipient: String,
151 forget: bool,
152 hide: bool,
153 ) -> Result<Value, ErrorObjectOwned>;
154
155 #[method(name = "removeDevice", param_kind = map)]
156 fn remove_device(
157 &self,
158 account: Option<String>,
159 #[allow(non_snake_case)] deviceId: u32,
160 ) -> Result<Value, ErrorObjectOwned>;
161
162 #[method(name = "removePin", param_kind = map)]
163 fn remove_pin(&self, account: Option<String>) -> Result<Value, ErrorObjectOwned>;
164
165 #[method(name = "remoteDelete", param_kind = map)]
166 fn remote_delete(
167 &self,
168 account: Option<String>,
169 #[allow(non_snake_case)] targetTimestamp: u64,
170 recipients: Vec<String>,
171 #[allow(non_snake_case)] groupIds: Vec<String>,
172 #[allow(non_snake_case)] noteToSelf: bool,
173 ) -> Result<Value, ErrorObjectOwned>;
174
175 #[allow(non_snake_case)]
176 #[method(name = "send", param_kind = map)]
177 fn send(
178 &self,
179 account: Option<String>,
180 recipients: Vec<String>,
181 groupIds: Vec<String>,
182 noteToSelf: bool,
183 endSession: bool,
184 message: String,
185 attachments: Vec<String>,
186 mentions: Vec<String>,
187 textStyle: Vec<String>,
188 quoteTimestamp: Option<u64>,
189 quoteAuthor: Option<String>,
190 quoteMessage: Option<String>,
191 quoteMention: Vec<String>,
192 quoteTextStyle: Vec<String>,
193 quoteAttachment: Vec<String>,
194 preview_url: Option<String>,
195 preview_title: Option<String>,
196 preview_description: Option<String>,
197 preview_image: Option<String>,
198 sticker: Option<String>,
199 storyTimestamp: Option<u64>,
200 storyAuthor: Option<String>,
201 editTimestamp: Option<u64>,
202 ) -> Result<Value, ErrorObjectOwned>;
203
204 #[method(name = "sendContacts", param_kind = map)]
205 fn send_contacts(&self, account: Option<String>) -> Result<Value, ErrorObjectOwned>;
206
207 #[method(name = "sendPaymentNotification", param_kind = map)]
208 fn send_payment_notification(
209 &self,
210 account: Option<String>,
211 recipient: String,
212 receipt: String,
213 note: String,
214 ) -> Result<Value, ErrorObjectOwned>;
215
216 #[method(name = "sendReaction", param_kind = map)]
217 fn send_reaction(
218 &self,
219 account: Option<String>,
220 recipients: Vec<String>,
221 #[allow(non_snake_case)] groupIds: Vec<String>,
222 #[allow(non_snake_case)] noteToSelf: bool,
223 emoji: String,
224 #[allow(non_snake_case)] targetAuthor: String,
225 #[allow(non_snake_case)] targetTimestamp: u64,
226 remove: bool,
227 story: bool,
228 ) -> Result<Value, ErrorObjectOwned>;
229
230 #[method(name = "sendReceipt", param_kind = map)]
231 fn send_receipt(
232 &self,
233 account: Option<String>,
234 recipient: String,
235 #[allow(non_snake_case)] targetTimestamps: Vec<u64>,
236 r#type: String,
237 ) -> Result<Value, ErrorObjectOwned>;
238
239 #[method(name = "sendSyncRequest", param_kind = map)]
240 fn send_sync_request(&self, account: Option<String>) -> Result<Value, ErrorObjectOwned>;
241
242 #[method(name = "sendTyping", param_kind = map)]
243 fn send_typing(
244 &self,
245 account: Option<String>,
246 recipients: Vec<String>,
247 #[allow(non_snake_case)] groupIds: Vec<String>,
248 stop: bool,
249 ) -> Result<Value, ErrorObjectOwned>;
250
251 #[method(name = "sendMessageRequestResponse", param_kind = map)]
252 fn send_message_request_response(
253 &self,
254 account: Option<String>,
255 recipients: Vec<String>,
256 #[allow(non_snake_case)] groupIds: Vec<String>,
257 r#type: String,
258 ) -> Result<Value, ErrorObjectOwned>;
259
260 #[method(name = "setPin", param_kind = map)]
261 fn set_pin(&self, account: Option<String>, pin: String) -> Result<Value, ErrorObjectOwned>;
262
263 #[method(name = "submitRateLimitChallenge", param_kind = map)]
264 fn submit_rate_limit_challenge(
265 &self,
266 account: Option<String>,
267 challenge: String,
268 captcha: String,
269 ) -> Result<Value, ErrorObjectOwned>;
270
271 #[method(name = "startChangeNumber", param_kind = map)]
272 fn start_change_number(
273 &self,
274 account: Option<String>,
275 number: String,
276 voice: bool,
277 captcha: Option<String>,
278 ) -> Result<Value, ErrorObjectOwned>;
279
280 #[method(name = "startLink", param_kind = map)]
281 fn start_link(&self, account: Option<String>) -> Result<JsonLink, ErrorObjectOwned>;
282
283 #[method(name = "trust", param_kind = map)]
284 fn trust(
285 &self,
286 account: Option<String>,
287 recipient: String,
288 #[allow(non_snake_case)] trustAllKnownKeys: bool,
289 #[allow(non_snake_case)] verifiedSafetyNumber: Option<String>,
290 ) -> Result<Value, ErrorObjectOwned>;
291
292 #[method(name = "unblock", param_kind = map)]
293 fn unblock(
294 &self,
295 account: Option<String>,
296 recipients: Vec<String>,
297 #[allow(non_snake_case)] groupIds: Vec<String>,
298 ) -> Result<Value, ErrorObjectOwned>;
299
300 #[method(name = "unregister", param_kind = map)]
301 fn unregister(
302 &self,
303 account: Option<String>,
304 #[allow(non_snake_case)] deleteAccount: bool,
305 ) -> Result<Value, ErrorObjectOwned>;
306
307 #[allow(non_snake_case)]
308 #[method(name = "updateAccount", param_kind = map)]
309 fn update_account(
310 &self,
311 account: Option<String>,
312 deviceName: Option<String>,
313 unrestrictedUnidentifiedSender: Option<bool>,
314 discoverableByNumber: Option<bool>,
315 numberSharing: Option<bool>,
316 ) -> Result<Value, ErrorObjectOwned>;
317
318 #[method(name = "updateConfiguration", param_kind = map)]
319 fn update_configuration(
320 &self,
321 account: Option<String>,
322 #[allow(non_snake_case)] readReceipts: Option<bool>,
323 #[allow(non_snake_case)] unidentifiedDeliveryIndicators: Option<bool>,
324 #[allow(non_snake_case)] typingIndicators: Option<bool>,
325 #[allow(non_snake_case)] linkPreviews: Option<bool>,
326 ) -> Result<Value, ErrorObjectOwned>;
327
328 #[method(name = "updateContact", param_kind = map)]
329 fn update_contact(
330 &self,
331 account: Option<String>,
332 recipient: String,
333 name: Option<String>,
334 expiration: Option<u32>,
335 ) -> Result<Value, ErrorObjectOwned>;
336
337 #[method(name = "updateGroup", param_kind = map)]
338 fn update_group(
339 &self,
340 account: Option<String>,
341 #[allow(non_snake_case)] groupId: Option<String>,
342 name: Option<String>,
343 description: Option<String>,
344 avatar: Option<String>,
345 member: Vec<String>,
346 #[allow(non_snake_case)] removeMember: Vec<String>,
347 admin: Vec<String>,
348 #[allow(non_snake_case)] removeAdmin: Vec<String>,
349 ban: Vec<String>,
350 unban: Vec<String>,
351 #[allow(non_snake_case)] resetLink: bool,
352 #[allow(non_snake_case)] link: Option<String>,
353 #[allow(non_snake_case)] setPermissionAddMember: Option<String>,
354 #[allow(non_snake_case)] setPermissionEditDetails: Option<String>,
355 #[allow(non_snake_case)] setPermissionSendMessages: Option<String>,
356 expiration: Option<u32>,
357 ) -> Result<Value, ErrorObjectOwned>;
358
359 #[method(name = "updateProfile", param_kind = map)]
360 fn update_profile(
361 &self,
362 account: Option<String>,
363 #[allow(non_snake_case)] givenName: Option<String>,
364 #[allow(non_snake_case)] familyName: Option<String>,
365 about: Option<String>,
366 #[allow(non_snake_case)] aboutEmoji: Option<String>,
367 #[allow(non_snake_case)] mobileCoinAddress: Option<String>,
368 avatar: Option<String>,
369 #[allow(non_snake_case)] removeAvatar: bool,
370 ) -> Result<Value, ErrorObjectOwned>;
371
372 #[method(name = "uploadStickerPack", param_kind = map)]
373 fn upload_sticker_pack(
374 &self,
375 account: Option<String>,
376 path: String,
377 ) -> Result<Value, ErrorObjectOwned>;
378
379 #[method(name = "verify", param_kind = map)]
380 fn verify(
381 &self,
382 account: Option<String>,
383 #[allow(non_snake_case)] verificationCode: String,
384 pin: Option<String>,
385 ) -> Result<Value, ErrorObjectOwned>;
386
387 #[subscription(
388 name = "subscribeReceive" => "receive",
389 unsubscribe = "unsubscribeReceive",
390 item = Value,
391 param_kind = map
392 )]
393 async fn subscribe_receive(&self, account: Option<String>) -> SubscriptionResult;
394
395 #[method(name = "version")]
396 fn version(&self) -> Result<Value, ErrorObjectOwned>;
397 }
398
399 #[derive(Deserialize)]
400 #[serde(rename_all = "camelCase")]
401 pub struct JsonLink {
402 pub device_link_uri: String,
403 }
404
405 pub async fn connect_tcp(
406 tcp: impl ToSocketAddrs,
407 ) -> Result<impl SubscriptionClientT, std::io::Error> {
408 let (sender, receiver) = super::transports::tcp::connect(tcp).await?;
409
410 Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
411 }
412
413 #[cfg(unix)]
414 pub async fn connect_unix(
415 socket_path: impl AsRef<Path>,
416 ) -> Result<impl SubscriptionClientT, std::io::Error> {
417 let (sender, receiver) = super::transports::ipc::connect(socket_path).await?;
418
419 Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
420 }
421
422 pub async fn connect_http(uri: &str) -> Result<impl SubscriptionClientT + use<>, Error> {
423 HttpClientBuilder::default().build(uri)
424 }