BlueGit

ict rusty-teams

Files

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

models.rs

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