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}
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 pub call_event_json: Option<String>,
92}
93
94#[derive(Debug, Clone, PartialEq)]
95pub struct RecentScope {
96 pub conversation_id: String,
97 pub after: DateTime<Utc>,
98}
99
100#[derive(Debug, Clone, PartialEq)]
101pub struct SyncState {
102 pub newest_seen: Option<DateTime<Utc>>,
103 pub oldest_loaded: Option<DateTime<Utc>>,
104 pub has_more: bool,
105 pub older_cursor: Option<String>,
106 pub delta_link: Option<String>,
107}
108
109impl Default for SyncState {
110 fn default() -> Self {
111 SyncState {
112 newest_seen: None,
113 oldest_loaded: None,
114 has_more: true,
115 older_cursor: None,
116 delta_link: None,
117 }
118 }
119}
120
121#[derive(Debug, Clone, PartialEq)]
122pub struct SidebarTeam {
123 pub team: TeamRecord,
124 pub channels: Vec<ChannelRecord>,
125 pub hidden: bool,
126 pub hidden_channel_ids: Vec<String>,
127 pub notifications: HashMap<String, ChannelNotifications>,
128}
129
130impl SidebarTeam {
131 pub fn channel_notifications(&self, channel_id: &str) -> ChannelNotifications {
132 self.notifications
133 .get(channel_id)
134 .copied()
135 .unwrap_or_default()
136 }
137}
138
139#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
140pub enum ChannelNotificationLevel {
141 BannerAndFeed,
142 #[default]
143 Feed,
144 Off,
145}
146
147impl ChannelNotificationLevel {
148 pub fn key(self) -> &'static str {
149 match self {
150 ChannelNotificationLevel::BannerAndFeed => "banner",
151 ChannelNotificationLevel::Feed => "feed",
152 ChannelNotificationLevel::Off => "off",
153 }
154 }
155
156 pub fn from_key(key: &str) -> Self {
157 match key {
158 "banner" => ChannelNotificationLevel::BannerAndFeed,
159 "off" => ChannelNotificationLevel::Off,
160 _ => ChannelNotificationLevel::Feed,
161 }
162 }
163}
164
165#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
166pub struct ChannelNotifications {
167 pub level: ChannelNotificationLevel,
168 pub include_replies: bool,
169}
170
171#[derive(Debug, Clone, PartialEq, Eq)]
172pub struct ChannelTabRecord {
173 pub tab_id: String,
174 pub name: String,
175 pub definition_id: String,
176 pub open_url: Option<String>,
177}
178
179#[derive(Debug, Clone, PartialEq, Eq)]
180pub struct ChannelLayoutRecord {
181 pub channel_id: String,
182 pub general: bool,
183 pub hidden: bool,
184 pub tabs: Vec<ChannelTabRecord>,
185 pub notifications: ChannelNotifications,
186}
187
188#[derive(Debug, Clone, PartialEq, Eq)]
189pub struct TeamLayoutRecord {
190 pub team_id: String,
191 pub hidden: bool,
192 pub channels: Vec<ChannelLayoutRecord>,
193}
194
195/// 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.
196#[derive(Debug, Clone, PartialEq, Default)]
197pub struct Sidebar {
198 pub chats: Vec<ChatRecord>,
199 pub teams: Vec<SidebarTeam>,
200}
201
202#[derive(Debug, Clone, Copy, PartialEq)]
203pub struct ChatPreview<'a> {
204 pub text: Option<&'a str>,
205 pub sender_id: Option<&'a str>,
206 pub sender_name: Option<&'a str>,
207 pub deleted: bool,
208}
209
210#[derive(Debug, Clone, PartialEq)]
211pub struct ImageRecord {
212 pub key: String,
213 pub bytes: Vec<u8>,
214 pub content_type: String,
215 pub fetched_at: DateTime<Utc>,
216}
217
218#[derive(Debug, Clone, PartialEq)]
219pub struct SearchHit {
220 pub conversation_id: String,
221 pub message_id: String,
222 pub sender_name: Option<String>,
223 pub created_at: DateTime<Utc>,
224 pub snippet: String,
225}
226
227#[derive(Debug, Clone, PartialEq, Eq)]
228pub struct ConversationHit {
229 pub conversation_id: String,
230 pub title: String,
231}
232
233#[derive(Debug, Clone, PartialEq)]
234pub struct ActivityRecord {
235 pub id: i64,
236 pub conversation_id: String,
237 pub kind: String,
238 pub message_id: String,
239 pub actors_json: String,
240 pub preview: String,
241 pub glyphs: String,
242 pub count: u32,
243 pub updated_at: DateTime<Utc>,
244 pub read: bool,
245}
246
247#[derive(Debug, Clone, PartialEq, Eq)]
248pub struct AttachmentImage {
249 pub name: String,
250 pub format: String,
251 pub bytes: Vec<u8>,
252 pub width: Option<u32>,
253 pub height: Option<u32>,
254}
255
256#[derive(Debug, Clone, Copy, PartialEq, Eq)]
257pub enum OutboxTarget {
258 Flat,
259 Post,
260 Thread,
261}
262
263impl OutboxTarget {
264 pub(crate) fn as_str(self) -> &'static str {
265 match self {
266 OutboxTarget::Flat => "flat",
267 OutboxTarget::Post => "post",
268 OutboxTarget::Thread => "thread",
269 }
270 }
271
272 pub(crate) fn parse(value: &str) -> Option<Self> {
273 match value {
274 "flat" => Some(OutboxTarget::Flat),
275 "post" => Some(OutboxTarget::Post),
276 "thread" => Some(OutboxTarget::Thread),
277 _ => None,
278 }
279 }
280}
281
282#[derive(Debug, Clone, Copy, PartialEq, Eq)]
283pub enum OutboxState {
284 Sending,
285 Failed,
286}
287
288impl OutboxState {
289 pub(crate) fn as_str(self) -> &'static str {
290 match self {
291 OutboxState::Sending => "sending",
292 OutboxState::Failed => "failed",
293 }
294 }
295
296 pub(crate) fn parse(value: &str) -> Option<Self> {
297 match value {
298 "sending" => Some(OutboxState::Sending),
299 "failed" => Some(OutboxState::Failed),
300 _ => None,
301 }
302 }
303}
304
305#[derive(Debug, Clone, PartialEq, Eq)]
306pub struct OutboxRecord {
307 pub id: String,
308 pub conversation_id: String,
309 pub target: OutboxTarget,
310 pub thread_root_id: Option<String>,
311 pub payload: String,
312 pub images: Vec<AttachmentImage>,
313 pub state: OutboxState,
314 pub last_error: Option<String>,
315 pub created_at: DateTime<Utc>,
316}
317
318#[derive(Debug, Clone, PartialEq, Eq)]
319pub struct DraftRecord {
320 pub conversation_id: String,
321 pub payload: String,
322 pub preview: String,
323 pub images: Vec<AttachmentImage>,
324 pub updated_at: DateTime<Utc>,
325}
326
327#[derive(Debug, Clone, PartialEq, Eq)]
328pub struct AgentProposalMention {
329 pub user_id: String,
330 pub name: String,
331}
332
333#[derive(Debug, Clone, PartialEq, Eq)]
334pub struct AgentProposalRecord {
335 pub id: String,
336 pub conversation_id: String,
337 pub reply_to_message_id: Option<String>,
338 pub text: String,
339 pub mentions: Vec<AgentProposalMention>,
340 pub images: Vec<AttachmentImage>,
341 pub agent: Option<String>,
342 pub session_id: Option<String>,
343 pub created_at: DateTime<Utc>,
344 pub state: String,
345 pub resolved_at: Option<DateTime<Utc>>,
346}
347
348#[derive(Debug, Clone, PartialEq, Eq)]
349pub struct AgentReactionRecord {
350 pub id: String,
351 pub conversation_id: String,
352 pub message_id: String,
353 pub emoji: String,
354 pub agent: Option<String>,
355 pub session_id: Option<String>,
356 pub created_at: DateTime<Utc>,
357 pub state: String,
358 pub resolved_at: Option<DateTime<Utc>>,
359}