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