BlueGit

ict rusty-teams

Files

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

models.rs

models.rs 8.9 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 pub last_event_call: bool,
28}
29
30impl ChatRecord {
31 pub fn display_title(&self) -> String {
32 if !self.title.trim().is_empty() {
33 self.title.clone()
34 } else if !self.member_summary.trim().is_empty() {
35 self.member_summary.clone()
36 } else {
37 "Chat".to_owned()
38 }
39 }
40}
41
42#[derive(Debug, Clone, PartialEq)]
43pub struct AvatarRecord {
44 pub user_id: String,
45 pub bytes: Option<Vec<u8>>,
46 pub content_type: String,
47 pub fetched_at: DateTime<Utc>,
48}
49
50#[derive(Debug, Clone, PartialEq)]
51pub struct FolderRecord {
52 pub id: String,
53 pub name: String,
54 pub kind: String,
55 pub expanded: bool,
56 pub conversation_ids: Vec<String>,
57}
58
59#[derive(Debug, Clone, PartialEq)]
60pub struct TeamRecord {
61 pub id: String,
62 pub name: String,
63}
64
65#[derive(Debug, Clone, PartialEq)]
66pub struct ChannelRecord {
67 pub id: String,
68 pub team_id: String,
69 pub name: String,
70 pub membership_type: Option<String>,
71 pub last_message_at: Option<DateTime<Utc>>,
72 pub unread: bool,
73}
74
75#[derive(Debug, Clone, PartialEq, Default)]
76pub struct MessageRecord {
77 pub conversation_id: String,
78 pub message_id: String,
79 pub reply_to_id: Option<String>,
80 pub sender_id: Option<String>,
81 pub sender_name: Option<String>,
82 pub created_at: DateTime<Utc>,
83 pub edited_at: Option<DateTime<Utc>>,
84 pub deleted: bool,
85 pub body_html: String,
86 pub attachments_json: String,
87 pub reactions_json: String,
88 pub mentions_json: String,
89 pub sender_application_id: Option<String>,
90 pub links_json: String,
91 pub subject: Option<String>,
92 pub call_event_json: Option<String>,
93}
94
95#[derive(Debug, Clone, PartialEq)]
96pub struct RecentScope {
97 pub conversation_id: String,
98 pub after: DateTime<Utc>,
99}
100
101#[derive(Debug, Clone, PartialEq)]
102pub struct SyncState {
103 pub newest_seen: Option<DateTime<Utc>>,
104 pub oldest_loaded: Option<DateTime<Utc>>,
105 pub has_more: bool,
106 pub older_cursor: Option<String>,
107 pub delta_link: Option<String>,
108}
109
110impl Default for SyncState {
111 fn default() -> Self {
112 SyncState {
113 newest_seen: None,
114 oldest_loaded: None,
115 has_more: true,
116 older_cursor: None,
117 delta_link: None,
118 }
119 }
120}
121
122#[derive(Debug, Clone, PartialEq)]
123pub struct SidebarTeam {
124 pub team: TeamRecord,
125 pub channels: Vec<ChannelRecord>,
126 pub hidden: bool,
127 pub hidden_channel_ids: Vec<String>,
128 pub notifications: HashMap<String, ChannelNotifications>,
129}
130
131impl SidebarTeam {
132 pub fn channel_notifications(&self, channel_id: &str) -> ChannelNotifications {
133 self.notifications
134 .get(channel_id)
135 .copied()
136 .unwrap_or_default()
137 }
138}
139
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
141pub enum ChannelNotificationLevel {
142 BannerAndFeed,
143 #[default]
144 Feed,
145 Off,
146}
147
148impl ChannelNotificationLevel {
149 pub fn key(self) -> &'static str {
150 match self {
151 ChannelNotificationLevel::BannerAndFeed => "banner",
152 ChannelNotificationLevel::Feed => "feed",
153 ChannelNotificationLevel::Off => "off",
154 }
155 }
156
157 pub fn from_key(key: &str) -> Self {
158 match key {
159 "banner" => ChannelNotificationLevel::BannerAndFeed,
160 "off" => ChannelNotificationLevel::Off,
161 _ => ChannelNotificationLevel::Feed,
162 }
163 }
164}
165
166#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
167pub struct ChannelNotifications {
168 pub level: ChannelNotificationLevel,
169 pub include_replies: bool,
170}
171
172#[derive(Debug, Clone, PartialEq, Eq)]
173pub struct ChannelTabRecord {
174 pub tab_id: String,
175 pub name: String,
176 pub definition_id: String,
177 pub open_url: Option<String>,
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 AgentProposalMention {
330 pub user_id: String,
331 pub name: String,
332}
333
334#[derive(Debug, Clone, PartialEq, Eq)]
335pub struct AgentProposalRecord {
336 pub id: String,
337 pub conversation_id: String,
338 pub reply_to_message_id: Option<String>,
339 pub text: String,
340 pub mentions: Vec<AgentProposalMention>,
341 pub images: Vec<AttachmentImage>,
342 pub agent: Option<String>,
343 pub session_id: Option<String>,
344 pub created_at: DateTime<Utc>,
345 pub state: String,
346 pub resolved_at: Option<DateTime<Utc>>,
347}
348
349#[derive(Debug, Clone, PartialEq, Eq)]
350pub struct AgentReactionRecord {
351 pub id: String,
352 pub conversation_id: String,
353 pub message_id: String,
354 pub emoji: String,
355 pub agent: Option<String>,
356 pub session_id: Option<String>,
357 pub created_at: DateTime<Utc>,
358 pub state: String,
359 pub resolved_at: Option<DateTime<Utc>>,
360}