xmtp_api_d14n/protocol/traits/
xmtp_query.rs1use xmtp_common::{MaybeSend, MaybeSync};
3use xmtp_proto::types::Cursor;
4
5use super::*;
6
7#[xmtp_common::async_trait]
10pub trait XmtpQuery: MaybeSend + MaybeSync {
11 type Error: RetryableError + 'static;
12 async fn query_at(
14 &self,
15 topic: Topic,
16 at: Option<GlobalCursor>,
17 ) -> Result<XmtpEnvelope, Self::Error>;
18}
19
20pub struct XmtpEnvelope {
23 inner: Box<dyn EnvelopeCollection<'static>>,
24}
25
26impl XmtpEnvelope {
27 pub fn new(envelope: impl EnvelopeCollection<'static> + 'static) -> Self {
28 Self {
29 inner: Box::new(envelope) as Box<_>,
30 }
31 }
32
33 pub fn len(&self) -> usize {
34 self.inner.len()
35 }
36
37 pub fn cursors(&self) -> Result<Vec<Cursor>, EnvelopeError> {
38 self.inner.cursors()
39 }
40
41 pub fn is_empty(&self) -> bool {
42 self.inner.is_empty()
43 }
44
45 pub fn group_messages(&self) -> Result<Vec<GroupMessage>, EnvelopeError> {
46 Ok(self.inner.group_messages()?.into_iter().flatten().collect())
47 }
48
49 pub fn welcome_messages(&self) -> Result<Vec<WelcomeMessage>, EnvelopeError> {
50 Ok(self
51 .inner
52 .welcome_messages()?
53 .into_iter()
54 .flatten()
55 .collect())
56 }
57
58 pub fn client_envelopes(&self) -> Result<Vec<ClientEnvelope>, EnvelopeError> {
59 self.inner.client_envelopes()
60 }
61}