Skip to main content

xmtp_proto/api_client/
impls.rs

1use super::*;
2
3#[xmtp_common::async_trait]
4impl<T: XmtpBackendClient + ?Sized> XmtpBackendClient for Box<T> {
5    type Error = T::Error;
6    fn register_client_event_writer(&self, writer: &Arc<dyn xmtp_events::EventWriter<()>>) {
7        (**self).register_client_event_writer(writer);
8    }
9    fn unregister_client_event_writer(&self, writer: &Arc<dyn xmtp_events::EventWriter<()>>) {
10        (**self).unregister_client_event_writer(writer);
11    }
12    async fn publish(&self, request: PublishRequest) -> Result<PublishResponse, Self::Error> {
13        (**self).publish(request).await
14    }
15    async fn create_upload(
16        &self,
17        request: CreateUploadRequest,
18    ) -> Result<CreateUploadResponse, Self::Error> {
19        (**self).create_upload(request).await
20    }
21    async fn query(&self, request: QueryRequest) -> Result<QueryResponse, Self::Error> {
22        (**self).query(request).await
23    }
24    async fn query_raw_envelopes(
25        &self,
26        request: QueryRequest,
27    ) -> Result<ReceivedQueryResponse, Self::Error> {
28        (**self).query_raw_envelopes(request).await
29    }
30    async fn query_newest(
31        &self,
32        request: QueryNewestRequest,
33    ) -> Result<QueryNewestResponse, Self::Error> {
34        (**self).query_newest(request).await
35    }
36    async fn get_inbox_ids(
37        &self,
38        request: GetInboxIdsRequest,
39    ) -> Result<GetInboxIdsResponse, Self::Error> {
40        (**self).get_inbox_ids(request).await
41    }
42    async fn get_configuration(
43        &self,
44        request: GetConfigurationRequest,
45    ) -> Result<GetConfigurationResponse, Self::Error> {
46        (**self).get_configuration(request).await
47    }
48    fn backend_url(&self) -> Option<&str> {
49        (**self).backend_url()
50    }
51
52    fn has_credential_source(&self) -> bool {
53        (**self).has_credential_source()
54    }
55
56    fn set_limits(&self, limits: std::sync::Arc<xmtp_configuration::LimitsConfiguration>) {
57        (**self).set_limits(limits)
58    }
59    async fn verify_smart_contract_wallet_signatures(
60        &self,
61        request: VerifySmartContractWalletSignaturesRequest,
62    ) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
63        (**self)
64            .verify_smart_contract_wallet_signatures(request)
65            .await
66    }
67    async fn register(&self, request: RegisterRequest) -> Result<RecipientState, Self::Error> {
68        (**self).register(request).await
69    }
70    async fn unregister(
71        &self,
72        request: UnregisterRequest,
73    ) -> Result<UnregisterResponse, Self::Error> {
74        (**self).unregister(request).await
75    }
76    async fn update_subscriptions(
77        &self,
78        request: UpdateSubscriptionsRequest,
79    ) -> Result<RecipientState, Self::Error> {
80        (**self).update_subscriptions(request).await
81    }
82}
83
84#[xmtp_common::async_trait]
85impl<T: XmtpMlsStreams + ?Sized> XmtpMlsStreams for Box<T> {
86    type Error = T::Error;
87    type GroupMessageStream = T::GroupMessageStream;
88    type WelcomeMessageStream = T::WelcomeMessageStream;
89    async fn subscribe_envelopes_with_cursors(
90        &self,
91        cursors: &TopicCursor,
92        limits: IncomingBatchLimits,
93    ) -> Result<IncomingSubscription<Self::Error>, Self::Error> {
94        (**self)
95            .subscribe_envelopes_with_cursors(cursors, limits)
96            .await
97    }
98    async fn subscribe_group_messages(
99        &self,
100        group_ids: &[&GroupId],
101    ) -> Result<Self::GroupMessageStream, Self::Error> {
102        (**self).subscribe_group_messages(group_ids).await
103    }
104    async fn subscribe_group_messages_with_cursors(
105        &self,
106        cursors: &TopicCursor,
107    ) -> Result<Self::GroupMessageStream, Self::Error> {
108        (**self)
109            .subscribe_group_messages_with_cursors(cursors)
110            .await
111    }
112    async fn subscribe_welcome_messages(
113        &self,
114        installations: &[&InstallationId],
115    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
116        (**self).subscribe_welcome_messages(installations).await
117    }
118    async fn subscribe_welcome_messages_with_cursors(
119        &self,
120        cursors: &TopicCursor,
121    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
122        (**self)
123            .subscribe_welcome_messages_with_cursors(cursors)
124            .await
125    }
126}
127
128#[xmtp_common::async_trait]
129impl<T: XmtpBackendClient + ?Sized> XmtpBackendClient for Arc<T> {
130    type Error = T::Error;
131    fn register_client_event_writer(&self, writer: &Arc<dyn xmtp_events::EventWriter<()>>) {
132        (**self).register_client_event_writer(writer);
133    }
134    fn unregister_client_event_writer(&self, writer: &Arc<dyn xmtp_events::EventWriter<()>>) {
135        (**self).unregister_client_event_writer(writer);
136    }
137    async fn publish(&self, request: PublishRequest) -> Result<PublishResponse, Self::Error> {
138        (**self).publish(request).await
139    }
140    async fn create_upload(
141        &self,
142        request: CreateUploadRequest,
143    ) -> Result<CreateUploadResponse, Self::Error> {
144        (**self).create_upload(request).await
145    }
146    async fn query(&self, request: QueryRequest) -> Result<QueryResponse, Self::Error> {
147        (**self).query(request).await
148    }
149    async fn query_raw_envelopes(
150        &self,
151        request: QueryRequest,
152    ) -> Result<ReceivedQueryResponse, Self::Error> {
153        (**self).query_raw_envelopes(request).await
154    }
155    async fn query_newest(
156        &self,
157        request: QueryNewestRequest,
158    ) -> Result<QueryNewestResponse, Self::Error> {
159        (**self).query_newest(request).await
160    }
161    async fn get_inbox_ids(
162        &self,
163        request: GetInboxIdsRequest,
164    ) -> Result<GetInboxIdsResponse, Self::Error> {
165        (**self).get_inbox_ids(request).await
166    }
167    async fn get_configuration(
168        &self,
169        request: GetConfigurationRequest,
170    ) -> Result<GetConfigurationResponse, Self::Error> {
171        (**self).get_configuration(request).await
172    }
173    fn backend_url(&self) -> Option<&str> {
174        (**self).backend_url()
175    }
176
177    fn has_credential_source(&self) -> bool {
178        (**self).has_credential_source()
179    }
180
181    fn set_limits(&self, limits: std::sync::Arc<xmtp_configuration::LimitsConfiguration>) {
182        (**self).set_limits(limits)
183    }
184    async fn verify_smart_contract_wallet_signatures(
185        &self,
186        request: VerifySmartContractWalletSignaturesRequest,
187    ) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
188        (**self)
189            .verify_smart_contract_wallet_signatures(request)
190            .await
191    }
192    async fn register(&self, request: RegisterRequest) -> Result<RecipientState, Self::Error> {
193        (**self).register(request).await
194    }
195    async fn unregister(
196        &self,
197        request: UnregisterRequest,
198    ) -> Result<UnregisterResponse, Self::Error> {
199        (**self).unregister(request).await
200    }
201    async fn update_subscriptions(
202        &self,
203        request: UpdateSubscriptionsRequest,
204    ) -> Result<RecipientState, Self::Error> {
205        (**self).update_subscriptions(request).await
206    }
207}
208
209#[xmtp_common::async_trait]
210impl<T: XmtpMlsStreams + ?Sized> XmtpMlsStreams for Arc<T> {
211    type Error = T::Error;
212    type GroupMessageStream = T::GroupMessageStream;
213    type WelcomeMessageStream = T::WelcomeMessageStream;
214    async fn subscribe_envelopes_with_cursors(
215        &self,
216        cursors: &TopicCursor,
217        limits: IncomingBatchLimits,
218    ) -> Result<IncomingSubscription<Self::Error>, Self::Error> {
219        (**self)
220            .subscribe_envelopes_with_cursors(cursors, limits)
221            .await
222    }
223    async fn subscribe_group_messages(
224        &self,
225        group_ids: &[&GroupId],
226    ) -> Result<Self::GroupMessageStream, Self::Error> {
227        (**self).subscribe_group_messages(group_ids).await
228    }
229    async fn subscribe_group_messages_with_cursors(
230        &self,
231        cursors: &TopicCursor,
232    ) -> Result<Self::GroupMessageStream, Self::Error> {
233        (**self)
234            .subscribe_group_messages_with_cursors(cursors)
235            .await
236    }
237    async fn subscribe_welcome_messages(
238        &self,
239        installations: &[&InstallationId],
240    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
241        (**self).subscribe_welcome_messages(installations).await
242    }
243    async fn subscribe_welcome_messages_with_cursors(
244        &self,
245        cursors: &TopicCursor,
246    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
247        (**self)
248            .subscribe_welcome_messages_with_cursors(cursors)
249            .await
250    }
251}
252
253#[xmtp_common::async_trait]
254impl<T: XmtpBackendClient + ?Sized> XmtpBackendClient for &T {
255    type Error = T::Error;
256    fn register_client_event_writer(&self, writer: &Arc<dyn xmtp_events::EventWriter<()>>) {
257        (**self).register_client_event_writer(writer);
258    }
259    fn unregister_client_event_writer(&self, writer: &Arc<dyn xmtp_events::EventWriter<()>>) {
260        (**self).unregister_client_event_writer(writer);
261    }
262    async fn publish(&self, request: PublishRequest) -> Result<PublishResponse, Self::Error> {
263        (**self).publish(request).await
264    }
265    async fn create_upload(
266        &self,
267        request: CreateUploadRequest,
268    ) -> Result<CreateUploadResponse, Self::Error> {
269        (**self).create_upload(request).await
270    }
271    async fn query(&self, request: QueryRequest) -> Result<QueryResponse, Self::Error> {
272        (**self).query(request).await
273    }
274    async fn query_raw_envelopes(
275        &self,
276        request: QueryRequest,
277    ) -> Result<ReceivedQueryResponse, Self::Error> {
278        (**self).query_raw_envelopes(request).await
279    }
280    async fn query_newest(
281        &self,
282        request: QueryNewestRequest,
283    ) -> Result<QueryNewestResponse, Self::Error> {
284        (**self).query_newest(request).await
285    }
286    async fn get_inbox_ids(
287        &self,
288        request: GetInboxIdsRequest,
289    ) -> Result<GetInboxIdsResponse, Self::Error> {
290        (**self).get_inbox_ids(request).await
291    }
292    async fn get_configuration(
293        &self,
294        request: GetConfigurationRequest,
295    ) -> Result<GetConfigurationResponse, Self::Error> {
296        (**self).get_configuration(request).await
297    }
298    fn backend_url(&self) -> Option<&str> {
299        (**self).backend_url()
300    }
301
302    fn has_credential_source(&self) -> bool {
303        (**self).has_credential_source()
304    }
305
306    fn set_limits(&self, limits: std::sync::Arc<xmtp_configuration::LimitsConfiguration>) {
307        (**self).set_limits(limits)
308    }
309    async fn verify_smart_contract_wallet_signatures(
310        &self,
311        request: VerifySmartContractWalletSignaturesRequest,
312    ) -> Result<VerifySmartContractWalletSignaturesResponse, Self::Error> {
313        (**self)
314            .verify_smart_contract_wallet_signatures(request)
315            .await
316    }
317    async fn register(&self, request: RegisterRequest) -> Result<RecipientState, Self::Error> {
318        (**self).register(request).await
319    }
320    async fn unregister(
321        &self,
322        request: UnregisterRequest,
323    ) -> Result<UnregisterResponse, Self::Error> {
324        (**self).unregister(request).await
325    }
326    async fn update_subscriptions(
327        &self,
328        request: UpdateSubscriptionsRequest,
329    ) -> Result<RecipientState, Self::Error> {
330        (**self).update_subscriptions(request).await
331    }
332}
333
334#[xmtp_common::async_trait]
335impl<T: XmtpMlsStreams + ?Sized> XmtpMlsStreams for &T {
336    type Error = T::Error;
337    type GroupMessageStream = T::GroupMessageStream;
338    type WelcomeMessageStream = T::WelcomeMessageStream;
339    async fn subscribe_envelopes_with_cursors(
340        &self,
341        cursors: &TopicCursor,
342        limits: IncomingBatchLimits,
343    ) -> Result<IncomingSubscription<Self::Error>, Self::Error> {
344        (**self)
345            .subscribe_envelopes_with_cursors(cursors, limits)
346            .await
347    }
348    async fn subscribe_group_messages(
349        &self,
350        group_ids: &[&GroupId],
351    ) -> Result<Self::GroupMessageStream, Self::Error> {
352        (**self).subscribe_group_messages(group_ids).await
353    }
354    async fn subscribe_group_messages_with_cursors(
355        &self,
356        cursors: &TopicCursor,
357    ) -> Result<Self::GroupMessageStream, Self::Error> {
358        (**self)
359            .subscribe_group_messages_with_cursors(cursors)
360            .await
361    }
362    async fn subscribe_welcome_messages(
363        &self,
364        installations: &[&InstallationId],
365    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
366        (**self).subscribe_welcome_messages(installations).await
367    }
368    async fn subscribe_welcome_messages_with_cursors(
369        &self,
370        cursors: &TopicCursor,
371    ) -> Result<Self::WelcomeMessageStream, Self::Error> {
372        (**self)
373            .subscribe_welcome_messages_with_cursors(cursors)
374            .await
375    }
376}
377
378xmtp_common::if_native! {
379    // `XmtpMlsBidiStreams` is native-only (see `api_client.rs`), so its boxed /
380    // arced forwarders are gated the same way. Without these, erasing a client
381    // into `Box<dyn XmtpMlsBidiStreams>` / `Arc<dyn XmtpMlsBidiStreams>` would
382    // fail to compile on `subscribe_bidi`, unlike every other client trait here.
383    #[xmtp_common::async_trait]
384    impl<T> XmtpMlsBidiStreams for Box<T>
385    where
386        T: XmtpMlsBidiStreams + Sync + ?Sized,
387    {
388        type Error = <T as XmtpMlsBidiStreams>::Error;
389        type SubscribeStream = <T as XmtpMlsBidiStreams>::SubscribeStream;
390
391        fn host(&self) -> &str {
392            (**self).host()
393        }
394
395        fn bidi_limits(&self) -> std::sync::Arc<xmtp_configuration::LimitsConfiguration> {
396            (**self).bidi_limits()
397        }
398
399        async fn subscribe_bidi(
400            &self,
401            requests: futures::stream::BoxStream<'static, crate::backend_v1::SubscribeRequest>,
402        ) -> Result<Self::SubscribeStream, Self::Error> {
403            (**self).subscribe_bidi(requests).await
404        }
405    }
406
407    #[xmtp_common::async_trait]
408    impl<T> XmtpMlsBidiStreams for Arc<T>
409    where
410        T: XmtpMlsBidiStreams + ?Sized,
411    {
412        type Error = <T as XmtpMlsBidiStreams>::Error;
413        type SubscribeStream = <T as XmtpMlsBidiStreams>::SubscribeStream;
414
415        fn host(&self) -> &str {
416            (**self).host()
417        }
418
419        fn bidi_limits(&self) -> std::sync::Arc<xmtp_configuration::LimitsConfiguration> {
420            (**self).bidi_limits()
421        }
422
423        async fn subscribe_bidi(
424            &self,
425            requests: futures::stream::BoxStream<'static, crate::backend_v1::SubscribeRequest>,
426        ) -> Result<Self::SubscribeStream, Self::Error> {
427            (**self).subscribe_bidi(requests).await
428        }
429    }
430}