1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Endpoints for third party lookups

pub mod get_location_for_protocol;
pub mod get_location_for_room_alias;
pub mod get_protocol;
pub mod get_protocols;
pub mod get_user_for_protocol;
pub mod get_user_for_user_id;

use std::collections::HashMap;

use ruma_identifiers::{RoomAliasId, UserId};

use serde::{Deserialize, Serialize};

/// Metadata about a third party protocol.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Protocol {
    /// Fields which may be used to identify a third party user.
    pub user_fields: Vec<String>,
    /// Fields which may be used to identify a third party location.
    pub location_fields: Vec<String>,
    /// A content URI representing an icon for the third party protocol.
    pub icon: String,
    /// The type definitions for the fields defined in `user_fields` and `location_fields`.
    pub field_types: HashMap<String, FieldType>,
    /// A list of objects representing independent instances of configuration.
    pub instances: Vec<ProtocolInstance>,
}

/// Metadata about an instance of a third party protocol.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ProtocolInstance {
    /// A human-readable description for the protocol, such as the name.
    pub desc: String,
    /// An optional content URI representing the protocol.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    /// Preset values for `fields` the client may use to search by.
    pub fields: HashMap<String, String>,
    /// A unique identifier across all instances.
    pub network_id: String,
}

/// A type definition for a field used to identify third party users or locations.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FieldType {
    /// A regular expression for validation of a field's value.
    pub regexp: String,
    /// A placeholder serving as a valid example of the field value.
    pub placeholder: String,
}

/// A third party network location.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Location {
    /// An alias for a matrix room.
    pub alias: RoomAliasId,
    /// The protocol ID that the third party location is a part of.
    pub protocol: String,
    /// Information used to identify this third party location.
    pub fields: HashMap<String, String>,
}

/// A third party network user.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User {
    /// A matrix user ID representing a third party user.
    pub userid: UserId,
    /// The protocol ID that the third party user is a part of.
    pub protocol: String,
    /// Information used to identify this third party user.
    pub fields: HashMap<String, String>,
}

/// The medium of a third party identifier.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Medium {
    /// Email address identifier
    Email,
    /// Phone number identifier
    MSISDN,
}