BlueGit

ict rusty-teams

Files

rusty-teams / crates / store / src / models.rs

models.rs

models.rs 8.4 KiB Download Raw
1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4
5#[derive(Debug, Clone, PartialEq, Default)]
6pub struct MemberRecord {
7 pub user_id: Option<String>,
8 pub display_name: String,
9}
10
11#[derive(Debug, Clone, PartialEq, Default)]
12pub struct ChatRecord {
13 pub id: String,
14 pub kind: String,
15 pub title: String,
16 pub member_summary: String,
17 pub last_message_at: Option<DateTime<Utc>>,
18 pub last_read_at: Option<DateTime<Utc>>,
19 pub unread: bool,
20 pub muted: bool,
21 pub members: Vec<MemberRecord>,
22 pub last_message_preview: Option<String>,
23 pub last_message_sender_id: Option<String>,
24 pub last_message_sender_name: Option<String>,
25 pub last_message_deleted: bool,
26 pub last_event_system: bool,
27}
28
29impl ChatRecord {
30 pub fn display_title(&self) -> String {
31 if !self.title.trim().is_empty() {
32 self.title.clone()
33 } else if !self.member_summary.trim().is_empty() {
34 self.member_summary.clone()
35 } else {
36 "Chat".to_owned()
37 }
38 }
39}
40
41#[derive(Debug, Clone, PartialEq)]
42pub struct AvatarRecord {
43 pub user_id: String,
44 pub bytes: Option<Vec<u8>>,
45 pub content_type: String,
46 pub fetched_at: DateTime<Utc>,
47}
48
49#[derive(Debug, Clone, PartialEq)]
50pub struct FolderRecord {
51 pub id: String,
52 pub name: String,
53 pub kind: String,
54 pub expanded: bool,
55 pub conversation_ids: Vec<String>,
56}
57
58#[derive(Debug, Clone, PartialEq)]
59pub struct TeamRecord {
60 pub id: String,
61 pub name: String,
62}
63
64#[derive(Debug, Clone, PartialEq)]
65pub struct ChannelRecord {
66 pub id: String,
67 pub team_id: String,
68 pub name: String,
69 pub membership_type: Option<String>,
70 pub last_message_at: Option<DateTime<Utc>>,
71 pub unread: bool,
72}
73
74#[derive(Debug, Clone, PartialEq, Default)]
75pub struct MessageRecord {
76 pub conversation_id: String,
77 pub message_id: String,
78 pub reply_to_id: Option<String>,
79 pub sender_id: Option<String>,
80 pub sender_name: Option<String>,
81 pub created_at: DateTime<Utc>,
82 pub edited_at: Option<DateTime<Utc>>,
83 pub deleted: bool,
84 pub body_html: String,
85 pub attachments_json: String,
86 pub reactions_json: String,
87 pub mentions_json: String,
88 pub sender_application_id: Option<String>,
89 pub links_json: String,
90 pub subject: Option<String>,
91}
92
93#[derive(Debug, Clone, PartialEq)]
94pub struct SyncState {
95 pub newest_seen: Option<DateTime<Utc>>,
96 pub oldest_loaded: Option<DateTime<Utc>>,
97 pub has_more: bool,
98 pub older_cursor: Option<String>,
99 pub delta_link: Option<String>,
100}
101
102impl Default for SyncState {
103 fn default() -> Self {
104 SyncState {
105 newest_seen: None,
106 oldest_loaded: None,
107 has_more: true,
108 older_cursor: None,
109 delta_link: None,
110 }
111 }
112}
113
114#[derive(Debug, Clone, PartialEq)]
115pub struct SidebarTeam {
116 pub team: TeamRecord,
117 pub channels: Vec<ChannelRecord>,
118 pub hidden: bool,
119 pub hidden_channel_ids: Vec<String>,
120 pub notifications: HashMap<String, ChannelNotifications>,
121}
122
123impl SidebarTeam {
124 pub fn channel_notifications(&self, channel_id: &str) -> ChannelNotifications {
125 self.notifications
126 .get(channel_id)
127 .copied()
128 .unwrap_or_default()
129 }
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
133pub enum ChannelNotificationLevel {
134 BannerAndFeed,
135 #[default]
136 Feed,
137 Off,
138}
139
140impl ChannelNotificationLevel {
141 pub fn key(self) -> &'static str {
142 match self {
143 ChannelNotificationLevel::BannerAndFeed => "banner",
144 ChannelNotificationLevel::Feed => "feed",
145 ChannelNotificationLevel::Off => "off",
146 }
147 }
148
149 pub fn from_key(key: &str) -> Self {
150 match key {
151 "banner" => ChannelNotificationLevel::BannerAndFeed,
152 "off" => ChannelNotificationLevel::Off,
153 _ => ChannelNotificationLevel::Feed,
154 }
155 }
156}
157
158#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
159pub struct ChannelNotifications {
160 pub level: ChannelNotificationLevel,
161 pub include_replies: bool,
162}
163
164#[derive(Debug, Clone, PartialEq, Eq)]
165pub struct ChannelTabRecord {
166 pub tab_id: String,
167 pub name: String,
168 pub definition_id: String,
169 pub open_url: Option<String>,
170}
171
172const WEBSITE_DEFINITION_ID: &str = "com.microsoft.teamspace.tab.web";
173
174impl ChannelTabRecord {
175 pub fn is_website(&self) -> bool {
176 self.definition_id == WEBSITE_DEFINITION_ID && self.open_url.is_some()
177 }
178}
179
180#[derive(Debug, Clone, PartialEq, Eq)]
181pub struct ChannelLayoutRecord {
182 pub channel_id: String,
183 pub general: bool,
184 pub hidden: bool,
185 pub tabs: Vec<ChannelTabRecord>,
186 pub notifications: ChannelNotifications,
187}
188
189#[derive(Debug, Clone, PartialEq, Eq)]
190pub struct TeamLayoutRecord {
191 pub team_id: String,
192 pub hidden: bool,
193 pub channels: Vec<ChannelLayoutRecord>,
194}
195
196/// Everything the sidebar renders: chats by last message (newest first), teams in the user's Teams order (alphabetical without one), General first, then channels by name.
197#[derive(Debug, Clone, PartialEq, Default)]
198pub struct Sidebar {
199 pub chats: Vec<ChatRecord>,
200 pub teams: Vec<SidebarTeam>,
201}
202
203#[derive(Debug, Clone, Copy, PartialEq)]
204pub struct ChatPreview<'a> {
205 pub text: Option<&'a str>,
206 pub sender_id: Option<&'a str>,
207 pub sender_name: Option<&'a str>,
208 pub deleted: bool,
209}
210
211#[derive(Debug, Clone, PartialEq)]
212pub struct ImageRecord {
213 pub key: String,
214 pub bytes: Vec<u8>,
215 pub content_type: String,
216 pub fetched_at: DateTime<Utc>,
217}
218
219#[derive(Debug, Clone, PartialEq)]
220pub struct SearchHit {
221 pub conversation_id: String,
222 pub message_id: String,
223 pub sender_name: Option<String>,
224 pub created_at: DateTime<Utc>,
225 pub snippet: String,
226}
227
228#[derive(Debug, Clone, PartialEq, Eq)]
229pub struct ConversationHit {
230 pub conversation_id: String,
231 pub title: String,
232}
233
234#[derive(Debug, Clone, PartialEq)]
235pub struct ActivityRecord {
236 pub id: i64,
237 pub conversation_id: String,
238 pub kind: String,
239 pub message_id: String,
240 pub actors_json: String,
241 pub preview: String,
242 pub glyphs: String,
243 pub count: u32,
244 pub updated_at: DateTime<Utc>,
245 pub read: bool,
246}
247
248#[derive(Debug, Clone, PartialEq, Eq)]
249pub struct AttachmentImage {
250 pub name: String,
251 pub format: String,
252 pub bytes: Vec<u8>,
253 pub width: Option<u32>,
254 pub height: Option<u32>,
255}
256
257#[derive(Debug, Clone, Copy, PartialEq, Eq)]
258pub enum OutboxTarget {
259 Flat,
260 Post,
261 Thread,
262}
263
264impl OutboxTarget {
265 pub(crate) fn as_str(self) -> &'static str {
266 match self {
267 OutboxTarget::Flat => "flat",
268 OutboxTarget::Post => "post",
269 OutboxTarget::Thread => "thread",
270 }
271 }
272
273 pub(crate) fn parse(value: &str) -> Option<Self> {
274 match value {
275 "flat" => Some(OutboxTarget::Flat),
276 "post" => Some(OutboxTarget::Post),
277 "thread" => Some(OutboxTarget::Thread),
278 _ => None,
279 }
280 }
281}
282
283#[derive(Debug, Clone, Copy, PartialEq, Eq)]
284pub enum OutboxState {
285 Sending,
286 Failed,
287}
288
289impl OutboxState {
290 pub(crate) fn as_str(self) -> &'static str {
291 match self {
292 OutboxState::Sending => "sending",
293 OutboxState::Failed => "failed",
294 }
295 }
296
297 pub(crate) fn parse(value: &str) -> Option<Self> {
298 match value {
299 "sending" => Some(OutboxState::Sending),
300 "failed" => Some(OutboxState::Failed),
301 _ => None,
302 }
303 }
304}
305
306#[derive(Debug, Clone, PartialEq, Eq)]
307pub struct OutboxRecord {
308 pub id: String,
309 pub conversation_id: String,
310 pub target: OutboxTarget,
311 pub thread_root_id: Option<String>,
312 pub payload: String,
313 pub images: Vec<AttachmentImage>,
314 pub state: OutboxState,
315 pub last_error: Option<String>,
316 pub created_at: DateTime<Utc>,
317}
318
319#[derive(Debug, Clone, PartialEq, Eq)]
320pub struct DraftRecord {
321 pub conversation_id: String,
322 pub payload: String,
323 pub preview: String,
324 pub images: Vec<AttachmentImage>,
325 pub updated_at: DateTime<Utc>,
326}
327
328#[derive(Debug, Clone, PartialEq, Eq)]
329pub struct AgentProposalRecord {
330 pub id: String,
331 pub conversation_id: String,
332 pub reply_to_message_id: Option<String>,
333 pub text: String,
334 pub agent: Option<String>,
335 pub session_id: Option<String>,
336 pub created_at: DateTime<Utc>,
337 pub state: String,
338 pub resolved_at: Option<DateTime<Utc>>,
339}