BlueGit

ict rusty-teams

Files

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

models.rs

models.rs 8.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}
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
172#[derive(Debug, Clone, PartialEq, Eq)]
173pub struct ChannelLayoutRecord {
174 pub channel_id: String,
175 pub general: bool,
176 pub hidden: bool,
177 pub tabs: Vec<ChannelTabRecord>,
178 pub notifications: ChannelNotifications,
179}
180
181#[derive(Debug, Clone, PartialEq, Eq)]
182pub struct TeamLayoutRecord {
183 pub team_id: String,
184 pub hidden: bool,
185 pub channels: Vec<ChannelLayoutRecord>,
186}
187
188/// 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.
189#[derive(Debug, Clone, PartialEq, Default)]
190pub struct Sidebar {
191 pub chats: Vec<ChatRecord>,
192 pub teams: Vec<SidebarTeam>,
193}
194
195#[derive(Debug, Clone, Copy, PartialEq)]
196pub struct ChatPreview<'a> {
197 pub text: Option<&'a str>,
198 pub sender_id: Option<&'a str>,
199 pub sender_name: Option<&'a str>,
200 pub deleted: bool,
201}
202
203#[derive(Debug, Clone, PartialEq)]
204pub struct ImageRecord {
205 pub key: String,
206 pub bytes: Vec<u8>,
207 pub content_type: String,
208 pub fetched_at: DateTime<Utc>,
209}
210
211#[derive(Debug, Clone, PartialEq)]
212pub struct SearchHit {
213 pub conversation_id: String,
214 pub message_id: String,
215 pub sender_name: Option<String>,
216 pub created_at: DateTime<Utc>,
217 pub snippet: String,
218}
219
220#[derive(Debug, Clone, PartialEq, Eq)]
221pub struct ConversationHit {
222 pub conversation_id: String,
223 pub title: String,
224}
225
226#[derive(Debug, Clone, PartialEq)]
227pub struct ActivityRecord {
228 pub id: i64,
229 pub conversation_id: String,
230 pub kind: String,
231 pub message_id: String,
232 pub actors_json: String,
233 pub preview: String,
234 pub glyphs: String,
235 pub count: u32,
236 pub updated_at: DateTime<Utc>,
237 pub read: bool,
238}
239
240#[derive(Debug, Clone, PartialEq, Eq)]
241pub struct AttachmentImage {
242 pub name: String,
243 pub format: String,
244 pub bytes: Vec<u8>,
245 pub width: Option<u32>,
246 pub height: Option<u32>,
247}
248
249#[derive(Debug, Clone, Copy, PartialEq, Eq)]
250pub enum OutboxTarget {
251 Flat,
252 Post,
253 Thread,
254}
255
256impl OutboxTarget {
257 pub(crate) fn as_str(self) -> &'static str {
258 match self {
259 OutboxTarget::Flat => "flat",
260 OutboxTarget::Post => "post",
261 OutboxTarget::Thread => "thread",
262 }
263 }
264
265 pub(crate) fn parse(value: &str) -> Option<Self> {
266 match value {
267 "flat" => Some(OutboxTarget::Flat),
268 "post" => Some(OutboxTarget::Post),
269 "thread" => Some(OutboxTarget::Thread),
270 _ => None,
271 }
272 }
273}
274
275#[derive(Debug, Clone, Copy, PartialEq, Eq)]
276pub enum OutboxState {
277 Sending,
278 Failed,
279}
280
281impl OutboxState {
282 pub(crate) fn as_str(self) -> &'static str {
283 match self {
284 OutboxState::Sending => "sending",
285 OutboxState::Failed => "failed",
286 }
287 }
288
289 pub(crate) fn parse(value: &str) -> Option<Self> {
290 match value {
291 "sending" => Some(OutboxState::Sending),
292 "failed" => Some(OutboxState::Failed),
293 _ => None,
294 }
295 }
296}
297
298#[derive(Debug, Clone, PartialEq, Eq)]
299pub struct OutboxRecord {
300 pub id: String,
301 pub conversation_id: String,
302 pub target: OutboxTarget,
303 pub thread_root_id: Option<String>,
304 pub payload: String,
305 pub images: Vec<AttachmentImage>,
306 pub state: OutboxState,
307 pub last_error: Option<String>,
308 pub created_at: DateTime<Utc>,
309}
310
311#[derive(Debug, Clone, PartialEq, Eq)]
312pub struct DraftRecord {
313 pub conversation_id: String,
314 pub payload: String,
315 pub preview: String,
316 pub images: Vec<AttachmentImage>,
317 pub updated_at: DateTime<Utc>,
318}
319
320#[derive(Debug, Clone, PartialEq, Eq)]
321pub struct AgentProposalRecord {
322 pub id: String,
323 pub conversation_id: String,
324 pub reply_to_message_id: Option<String>,
325 pub text: String,
326 pub agent: Option<String>,
327 pub session_id: Option<String>,
328 pub created_at: DateTime<Utc>,
329 pub state: String,
330 pub resolved_at: Option<DateTime<Utc>>,
331}