matrix_ui_serializable/models/
events.rs1use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomId};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
6pub enum ListenEvent {
7 VerificationResult,
8 MatrixUpdateCurrentActiveRoom,
9 MatrixLogin,
10 CancelVerification,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct MatrixVerificationResponse {
16 pub confirmed: bool,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct MatrixUpdateCurrentActiveRoom {
22 pub room_id: OwnedRoomId,
23 pub thread_root_event_id: Option<OwnedEventId>,
24 pub room_name: String,
25}
26
27#[derive(Debug, Clone, Deserialize, Serialize)]
29#[serde(rename_all = "camelCase")]
30pub struct MatrixLoginPayload {
31 pub username: String,
32 pub password: String,
33 pub homeserver_url: String,
34 pub client_name: String,
35}
36
37#[derive(Debug, Clone)]
40pub enum EmitEvent {
41 VerificationStart(MatrixVerificationEmojis),
42 ToastNotification(ToastNotificationRequest),
43 OsNotification(OsNotificationRequest),
44 OAuthUrl(String),
45 ResetCrossSigngingUrl(String),
46 NewlyCreatedRoomId(OwnedRoomId),
47}
48
49#[derive(Debug, Clone, Serialize)]
50#[serde(rename_all = "camelCase")]
51pub struct MatrixVerificationEmojis {
52 emojis: String,
53}
54
55impl MatrixVerificationEmojis {
56 pub fn new(emojis: String) -> Self {
57 Self { emojis }
58 }
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(rename_all = "camelCase")]
63pub struct MatrixRoomStoreCreateRequest {
64 id: String,
65}
66
67impl MatrixRoomStoreCreateRequest {
68 pub fn new(id: String) -> Self {
69 Self { id }
70 }
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(rename_all = "camelCase")]
75pub struct ToastNotificationRequest {
76 message: String,
77 description: Option<String>,
78 variant: ToastNotificationVariant,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(rename_all = "camelCase", rename_all_fields = "camelCase")]
83pub enum ToastNotificationVariant {
84 Default,
85 Description,
86 Success,
87 Info,
88 Warning,
89 Error,
90}
91
92impl ToastNotificationRequest {
93 pub fn new(
94 message: String,
95 description: Option<String>,
96 variant: ToastNotificationVariant,
97 ) -> Self {
98 if description.is_some() {
99 Self {
101 message,
102 description,
103 variant: ToastNotificationVariant::Description,
104 }
105 } else {
106 Self {
107 message,
108 description: None,
109 variant,
110 }
111 }
112 }
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(rename_all = "camelCase")]
117pub struct OsNotificationRequest {
118 pub summary: String,
119 pub body: Option<String>,
120}
121
122impl OsNotificationRequest {
123 pub fn new(summary: String, body: Option<String>) -> Self {
124 Self { summary, body }
125 }
126}
127
128#[derive(Clone, Serialize)]
131#[serde(
132 rename_all = "camelCase",
133 rename_all_fields = "camelCase",
134 tag = "event",
135 content = "data"
136)]
137pub enum MediaStreamEvent {
138 Started,
139 Chunk {
140 data: Vec<u8>,
141 chunk_size: usize,
142 bytes_received: usize,
143 },
144 Finished {
145 total_bytes: usize,
146 },
147 Error {
148 message: String,
149 },
150}
151
152#[derive(Clone, Serialize)]
153#[serde(
154 rename_all = "camelCase",
155 rename_all_fields = "camelCase",
156 tag = "event",
157 content = "data"
158)]
159pub enum VerifyDeviceEvent {
160 Requested,
161 Done,
162 Cancelled { reason: String },
163}
164
165#[derive(Debug, Clone, Serialize)]
167#[serde(rename_all = "camelCase")]
168pub struct FrontendDevice {
169 pub device_id: OwnedDeviceId,
170 pub is_verified: bool,
171 pub is_verified_with_cross_signing: bool,
172 pub display_name: Option<String>,
173 pub last_seen_ts: Option<MilliSecondsSinceUnixEpoch>,
174 pub guessed_type: DeviceGuessedType,
175 pub is_current_device: bool,
176}
177
178#[derive(Debug, Clone, Serialize)]
179#[serde(rename_all = "camelCase", rename_all_fields = "camelCase")]
180pub enum DeviceGuessedType {
181 Android,
182 Ios,
183 Web,
184 Desktop,
185 Unknown,
186}