ruma_identity_service_api/lookup/
lookup_3pid.rs

1//! `POST /_matrix/identity/*/lookup`
2//!
3//! Looks up the set of Matrix User IDs which have bound the 3PIDs given, if bindings are available.
4
5pub mod v2 {
6    //! `/v2/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2lookup
9
10    use std::collections::BTreeMap;
11
12    use ruma_common::{
13        OwnedUserId,
14        api::{auth_scheme::AccessToken, request, response},
15        metadata,
16    };
17
18    use crate::lookup::IdentifierHashingAlgorithm;
19
20    metadata! {
21        method: POST,
22        rate_limited: false,
23        authentication: AccessToken,
24        history: {
25            1.0 => "/_matrix/identity/v2/lookup",
26        }
27    }
28
29    /// Request type for the `lookup_3pid` endpoint.
30    #[request]
31    pub struct Request {
32        /// The algorithm the client is using to encode the `addresses`. This should be one of the
33        /// available options from `/hash_details`.
34        pub algorithm: IdentifierHashingAlgorithm,
35
36        /// The pepper from `/hash_details`. This is required even when the `algorithm` does not
37        /// make use of it.
38        pub pepper: String,
39
40        /// The addresses to look up.
41        ///
42        /// The format of the entries here depend on the `algorithm` used. Note that queries which
43        /// have been incorrectly hashed or formatted will lead to no matches.
44        pub addresses: Vec<String>,
45    }
46
47    /// Response type for the `lookup_3pid` endpoint.
48    #[response]
49    pub struct Response {
50        /// Any applicable mappings of `addresses` to Matrix User IDs.
51        ///
52        /// Addresses which do not have associations will not be included, which can make this
53        /// property be an empty object.
54        pub mappings: BTreeMap<String, OwnedUserId>,
55    }
56
57    impl Request {
58        /// Create a `Request` with algorithm, pepper and addresses to loop up.
59        pub fn new(
60            algorithm: IdentifierHashingAlgorithm,
61            pepper: String,
62            addresses: Vec<String>,
63        ) -> Self {
64            Self { algorithm, pepper, addresses }
65        }
66    }
67
68    impl Response {
69        /// Create a `Response` with the BTreeMap which map addresses from the request which were
70        /// found to their corresponding User IDs.
71        pub fn new(mappings: BTreeMap<String, OwnedUserId>) -> Self {
72            Self { mappings }
73        }
74    }
75}