]> nmode's Git Repositories - signal-cli/blob - client/src/jsonrpc.rs
Update json-rpc client
[signal-cli] / client / src / jsonrpc.rs
1 use std::path::Path;
2
3 use jsonrpc_client_transports::{transports::ipc, RpcError};
4 use jsonrpc_core::serde::Deserialize;
5 use jsonrpc_derive::rpc;
6 use tokio::net::ToSocketAddrs;
7
8 pub type SignalCliClient = gen_client::Client;
9
10 #[rpc(client, params = "named")]
11 pub trait Rpc {
12 #[rpc(name = "addDevice", params = "named")]
13 fn add_device(&self, account: Option<String>, uri: String) -> Result<Value>;
14
15 #[rpc(name = "block", params = "named")]
16 fn block(
17 &self,
18 account: Option<String>,
19 recipients: Vec<String>,
20 #[allow(non_snake_case)] groupIds: Vec<String>,
21 ) -> Result<Value>;
22
23 #[rpc(name = "deleteLocalAccountData", params = "named")]
24 fn delete_local_account_data(
25 &self,
26 account: Option<String>,
27 #[allow(non_snake_case)] ignoreRegistered: Option<bool>,
28 ) -> Result<Value>;
29
30 #[rpc(name = "getUserStatus", params = "named")]
31 fn get_user_status(&self, account: Option<String>, recipients: Vec<String>) -> Result<Value>;
32
33 #[rpc(name = "joinGroup", params = "named")]
34 fn join_group(&self, account: Option<String>, uri: String) -> Result<Value>;
35
36 #[rpc(name = "finishLink", params = "named")]
37 fn finish_link(
38 &self,
39 #[allow(non_snake_case)] deviceLinkUri: String,
40 #[allow(non_snake_case)] deviceName: String,
41 ) -> Result<Value>;
42
43 #[rpc(name = "listAccounts", params = "named")]
44 fn list_accounts(&self) -> Result<Value>;
45
46 #[rpc(name = "listContacts", params = "named")]
47 fn list_contacts(
48 &self,
49 account: Option<String>,
50 recipients: Vec<String>,
51 #[allow(non_snake_case)] allRecipients: bool,
52 blocked: Option<bool>,
53 name: Option<String>,
54 ) -> Result<Value>;
55
56 #[rpc(name = "listDevices", params = "named")]
57 fn list_devices(&self, account: Option<String>) -> Result<Value>;
58
59 #[rpc(name = "listGroups", params = "named")]
60 fn list_groups(
61 &self,
62 account: Option<String>,
63 #[allow(non_snake_case)] groupIds: Vec<String>,
64 ) -> Result<Value>;
65
66 #[rpc(name = "listIdentities", params = "named")]
67 fn list_identities(&self, account: Option<String>, number: Option<String>) -> Result<Value>;
68
69 #[rpc(name = "listStickerPacks", params = "named")]
70 fn list_sticker_packs(&self, account: Option<String>) -> Result<Value>;
71
72 #[rpc(name = "quitGroup", params = "named")]
73 fn quit_group(
74 &self,
75 account: Option<String>,
76 #[allow(non_snake_case)] groupId: String,
77 delete: bool,
78 admins: Vec<String>,
79 ) -> Result<Value>;
80
81 #[rpc(name = "register", params = "named")]
82 fn register(
83 &self,
84 account: Option<String>,
85 voice: bool,
86 captcha: Option<String>,
87 ) -> Result<Value>;
88
89 #[rpc(name = "removeContact", params = "named")]
90 fn remove_contact(
91 &self,
92 account: Option<String>,
93 recipient: String,
94 forget: bool,
95 ) -> Result<Value>;
96
97 #[rpc(name = "removeDevice", params = "named")]
98 fn remove_device(
99 &self,
100 account: Option<String>,
101 #[allow(non_snake_case)] deviceId: u32,
102 ) -> Result<Value>;
103
104 #[rpc(name = "removePin", params = "named")]
105 fn remove_pin(&self, account: Option<String>) -> Result<Value>;
106
107 #[rpc(name = "remoteDelete", params = "named")]
108 fn remote_delete(
109 &self,
110 account: Option<String>,
111 #[allow(non_snake_case)] targetTimestamp: u64,
112 recipients: Vec<String>,
113 #[allow(non_snake_case)] groupIds: Vec<String>,
114 #[allow(non_snake_case)] noteToSelf: bool,
115 ) -> Result<Value>;
116
117 #[rpc(name = "send", params = "named")]
118 fn send(
119 &self,
120 account: Option<String>,
121 recipients: Vec<String>,
122 #[allow(non_snake_case)] groupIds: Vec<String>,
123 #[allow(non_snake_case)] noteToSelf: bool,
124 #[allow(non_snake_case)] endSession: bool,
125 message: String,
126 attachments: Vec<String>,
127 mentions: Vec<String>,
128 #[allow(non_snake_case)] quoteTimestamp: Option<u64>,
129 #[allow(non_snake_case)] quoteAuthor: Option<String>,
130 #[allow(non_snake_case)] quoteMessage: Option<String>,
131 #[allow(non_snake_case)] quoteMention: Vec<String>,
132 sticker: Option<String>,
133 ) -> Result<Value>;
134
135 #[rpc(name = "sendContacts", params = "named")]
136 fn send_contacts(&self, account: Option<String>) -> Result<Value>;
137
138 #[rpc(name = "sendReaction", params = "named")]
139 fn send_reaction(
140 &self,
141 account: Option<String>,
142 recipients: Vec<String>,
143 #[allow(non_snake_case)] groupIds: Vec<String>,
144 #[allow(non_snake_case)] noteToSelf: bool,
145 emoji: String,
146 #[allow(non_snake_case)] targetAuthor: String,
147 #[allow(non_snake_case)] targetTimestamp: u64,
148 remove: bool,
149 ) -> Result<Value>;
150
151 #[rpc(name = "sendReceipt", params = "named")]
152 fn send_receipt(
153 &self,
154 account: Option<String>,
155 recipient: String,
156 #[allow(non_snake_case)] targetTimestamps: Vec<u64>,
157 r#type: String,
158 ) -> Result<Value>;
159
160 #[rpc(name = "sendSyncRequest", params = "named")]
161 fn send_sync_request(&self, account: Option<String>) -> Result<Value>;
162
163 #[rpc(name = "sendTyping", params = "named")]
164 fn send_typing(
165 &self,
166 account: Option<String>,
167 recipients: Vec<String>,
168 #[allow(non_snake_case)] groupIds: Vec<String>,
169 stop: bool,
170 ) -> Result<Value>;
171
172 #[rpc(name = "setPin", params = "named")]
173 fn set_pin(&self, account: Option<String>, pin: String) -> Result<Value>;
174
175 #[rpc(name = "submitRateLimitChallenge", params = "named")]
176 fn submit_rate_limit_challenge(
177 &self,
178 account: Option<String>,
179 challenge: String,
180 captcha: String,
181 ) -> Result<Value>;
182
183 #[rpc(name = "startLink", params = "named")]
184 fn start_link(&self, account: Option<String>) -> Result<JsonLink>;
185
186 #[rpc(name = "trust", params = "named")]
187 fn trust(
188 &self,
189 account: Option<String>,
190 recipient: String,
191 #[allow(non_snake_case)] trustAllKnownKeys: bool,
192 #[allow(non_snake_case)] verifiedSafetyNumber: Option<String>,
193 ) -> Result<Value>;
194
195 #[rpc(name = "unblock", params = "named")]
196 fn unblock(
197 &self,
198 account: Option<String>,
199 recipients: Vec<String>,
200 #[allow(non_snake_case)] groupIds: Vec<String>,
201 ) -> Result<Value>;
202
203 #[rpc(name = "unregister", params = "named")]
204 fn unregister(
205 &self,
206 account: Option<String>,
207 #[allow(non_snake_case)] deleteAccount: bool,
208 ) -> Result<Value>;
209
210 #[rpc(name = "updateAccount", params = "named")]
211 fn update_account(
212 &self,
213 account: Option<String>,
214 #[allow(non_snake_case)] deviceName: Option<String>,
215 ) -> Result<Value>;
216
217 #[rpc(name = "updateConfiguration", params = "named")]
218 fn update_configuration(
219 &self,
220 account: Option<String>,
221 #[allow(non_snake_case)] readReceiptes: Option<bool>,
222 #[allow(non_snake_case)] unidentifiedDeliveryIndicators: Option<bool>,
223 #[allow(non_snake_case)] typingIndicators: Option<bool>,
224 #[allow(non_snake_case)] linkPreviews: Option<bool>,
225 ) -> Result<Value>;
226
227 #[rpc(name = "updateContact", params = "named")]
228 fn update_contact(
229 &self,
230 account: Option<String>,
231 recipient: String,
232 name: Option<String>,
233 expiration: Option<u32>,
234 ) -> Result<Value>;
235
236 #[rpc(name = "updateGroup", params = "named")]
237 fn update_group(
238 &self,
239 account: Option<String>,
240 #[allow(non_snake_case)] groupId: Option<String>,
241 name: Option<String>,
242 description: Option<String>,
243 avatar: Option<String>,
244 member: Vec<String>,
245 #[allow(non_snake_case)] removeMember: Vec<String>,
246 admin: Vec<String>,
247 #[allow(non_snake_case)] removeAdmin: Vec<String>,
248 ban: Vec<String>,
249 unban: Vec<String>,
250 #[allow(non_snake_case)] resetLink: bool,
251 #[allow(non_snake_case)] link: Option<String>,
252 #[allow(non_snake_case)] setPermissionAddMember: Option<String>,
253 #[allow(non_snake_case)] setPermissionEditDetails: Option<String>,
254 #[allow(non_snake_case)] setPermissionSendMessages: Option<String>,
255 expiration: Option<u32>,
256 ) -> Result<Value>;
257
258 #[rpc(name = "updateProfile", params = "named")]
259 fn update_profile(
260 &self,
261 account: Option<String>,
262 #[allow(non_snake_case)] givenName: Option<String>,
263 #[allow(non_snake_case)] familyName: Option<String>,
264 about: Option<String>,
265 #[allow(non_snake_case)] aboutEmoji: Option<String>,
266 avatar: Option<String>,
267 #[allow(non_snake_case)] removeAvatar: bool,
268 ) -> Result<Value>;
269
270 #[rpc(name = "uploadStickerPack", params = "named")]
271 fn upload_sticker_pack(&self, account: Option<String>, path: String) -> Result<Value>;
272
273 #[rpc(name = "verify", params = "named")]
274 fn verify(
275 &self,
276 account: Option<String>,
277 #[allow(non_snake_case)] verificationCode: String,
278 pin: Option<String>,
279 ) -> Result<Value>;
280
281 #[pubsub(
282 subscription = "receive",
283 subscribe,
284 name = "subscribeReceive",
285 params = "named"
286 )]
287 fn subscribe_receive(&self, _: Self::Metadata, _: Subscriber<Value>, account: Option<String>);
288
289 #[pubsub(subscription = "receive", unsubscribe, name = "unsubscribeReceive")]
290 fn unsubscribe_receive(&self, _: Option<Self::Metadata>, _: SubscriptionId) -> Result<bool>;
291
292 #[rpc(name = "version")]
293 fn version(&self) -> Result<Value>;
294 }
295
296 #[derive(Deserialize)]
297 #[serde(rename_all = "camelCase")]
298 pub struct JsonLink {
299 pub device_link_uri: String,
300 }
301
302 pub async fn connect_tcp(tcp: impl ToSocketAddrs) -> Result<SignalCliClient, RpcError> {
303 super::tcp::connect::<_, SignalCliClient>(tcp).await
304 }
305
306 pub async fn connect_unix(socket_path: impl AsRef<Path>) -> Result<SignalCliClient, RpcError> {
307 ipc::connect::<_, SignalCliClient>(socket_path).await
308 }