BlueGit

ict rusty-teams

Files

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

models.rs

models.rs 6.1 KiB Download Raw
1use chrono::{DateTime, Utc};
2
3#[derive(Debug, Clone, PartialEq, Default)]
4pub struct MemberRecord {
5 pub user_id: Option<String>,
6 pub display_name: String,
7}
8
9#[derive(Debug, Clone, PartialEq, Default)]
10pub struct ChatRecord {
11 pub id: String,
12 pub kind: String,
13 pub title: String,
14 pub member_summary: String,
15 pub last_message_at: Option<DateTime<Utc>>,
16 pub last_read_at: Option<DateTime<Utc>>,
17 pub unread: bool,
18 pub muted: bool,
19 pub members: Vec<MemberRecord>,
20 pub last_message_preview: Option<String>,
21 pub last_message_sender_id: Option<String>,
22 pub last_message_sender_name: Option<String>,
23 pub last_message_deleted: bool,
24 pub last_event_system: bool,
25}
26
27#[derive(Debug, Clone, PartialEq)]
28pub struct AvatarRecord {
29 pub user_id: String,
30 pub bytes: Option<Vec<u8>>,
31 pub content_type: String,
32 pub fetched_at: DateTime<Utc>,
33}
34
35#[derive(Debug, Clone, PartialEq)]
36pub struct FolderRecord {
37 pub id: String,
38 pub name: String,
39 pub kind: String,
40 pub conversation_ids: Vec<String>,
41}
42
43#[derive(Debug, Clone, PartialEq)]
44pub struct TeamRecord {
45 pub id: String,
46 pub name: String,
47}
48
49#[derive(Debug, Clone, PartialEq)]
50pub struct ChannelRecord {
51 pub id: String,
52 pub team_id: String,
53 pub name: String,
54 pub membership_type: Option<String>,
55 pub last_message_at: Option<DateTime<Utc>>,
56 pub unread: bool,
57}
58
59#[derive(Debug, Clone, PartialEq, Default)]
60pub struct MessageRecord {
61 pub conversation_id: String,
62 pub message_id: String,
63 pub reply_to_id: Option<String>,
64 pub sender_id: Option<String>,
65 pub sender_name: Option<String>,
66 pub created_at: DateTime<Utc>,
67 pub edited_at: Option<DateTime<Utc>>,
68 pub deleted: bool,
69 pub body_html: String,
70 pub attachments_json: String,
71 pub reactions_json: String,
72 pub mentions_json: String,
73 pub sender_application_id: Option<String>,
74 pub links_json: String,
75 pub subject: Option<String>,
76}
77
78#[derive(Debug, Clone, PartialEq)]
79pub struct SyncState {
80 pub newest_seen: Option<DateTime<Utc>>,
81 pub oldest_loaded: Option<DateTime<Utc>>,
82 pub has_more: bool,
83 pub older_cursor: Option<String>,
84 pub delta_link: Option<String>,
85}
86
87impl Default for SyncState {
88 fn default() -> Self {
89 SyncState {
90 newest_seen: None,
91 oldest_loaded: None,
92 has_more: true,
93 older_cursor: None,
94 delta_link: None,
95 }
96 }
97}
98
99#[derive(Debug, Clone, PartialEq)]
100pub struct SidebarTeam {
101 pub team: TeamRecord,
102 pub channels: Vec<ChannelRecord>,
103 pub hidden: bool,
104 pub hidden_channel_ids: Vec<String>,
105}
106
107#[derive(Debug, Clone, PartialEq, Eq)]
108pub struct ChannelLayoutRecord {
109 pub channel_id: String,
110 pub general: bool,
111 pub hidden: bool,
112}
113
114#[derive(Debug, Clone, PartialEq, Eq)]
115pub struct TeamLayoutRecord {
116 pub team_id: String,
117 pub hidden: bool,
118 pub channels: Vec<ChannelLayoutRecord>,
119}
120
121/// 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.
122#[derive(Debug, Clone, PartialEq, Default)]
123pub struct Sidebar {
124 pub chats: Vec<ChatRecord>,
125 pub teams: Vec<SidebarTeam>,
126}
127
128#[derive(Debug, Clone, Copy, PartialEq)]
129pub struct ChatPreview<'a> {
130 pub text: Option<&'a str>,
131 pub sender_id: Option<&'a str>,
132 pub sender_name: Option<&'a str>,
133 pub deleted: bool,
134}
135
136#[derive(Debug, Clone, PartialEq)]
137pub struct ImageRecord {
138 pub key: String,
139 pub bytes: Vec<u8>,
140 pub content_type: String,
141 pub fetched_at: DateTime<Utc>,
142}
143
144#[derive(Debug, Clone, PartialEq)]
145pub struct SearchHit {
146 pub conversation_id: String,
147 pub message_id: String,
148 pub sender_name: Option<String>,
149 pub created_at: DateTime<Utc>,
150 pub snippet: String,
151}
152
153#[derive(Debug, Clone, PartialEq, Eq)]
154pub struct ConversationHit {
155 pub conversation_id: String,
156 pub title: String,
157}
158
159#[derive(Debug, Clone, PartialEq)]
160pub struct ActivityRecord {
161 pub id: i64,
162 pub conversation_id: String,
163 pub kind: String,
164 pub message_id: String,
165 pub actors_json: String,
166 pub preview: String,
167 pub glyphs: String,
168 pub count: u32,
169 pub updated_at: DateTime<Utc>,
170 pub read: bool,
171}
172
173#[derive(Debug, Clone, PartialEq, Eq)]
174pub struct AttachmentImage {
175 pub name: String,
176 pub format: String,
177 pub bytes: Vec<u8>,
178 pub width: Option<u32>,
179 pub height: Option<u32>,
180}
181
182#[derive(Debug, Clone, Copy, PartialEq, Eq)]
183pub enum OutboxTarget {
184 Flat,
185 Post,
186 Thread,
187}
188
189impl OutboxTarget {
190 pub(crate) fn as_str(self) -> &'static str {
191 match self {
192 OutboxTarget::Flat => "flat",
193 OutboxTarget::Post => "post",
194 OutboxTarget::Thread => "thread",
195 }
196 }
197
198 pub(crate) fn parse(value: &str) -> Option<Self> {
199 match value {
200 "flat" => Some(OutboxTarget::Flat),
201 "post" => Some(OutboxTarget::Post),
202 "thread" => Some(OutboxTarget::Thread),
203 _ => None,
204 }
205 }
206}
207
208#[derive(Debug, Clone, Copy, PartialEq, Eq)]
209pub enum OutboxState {
210 Sending,
211 Failed,
212}
213
214impl OutboxState {
215 pub(crate) fn as_str(self) -> &'static str {
216 match self {
217 OutboxState::Sending => "sending",
218 OutboxState::Failed => "failed",
219 }
220 }
221
222 pub(crate) fn parse(value: &str) -> Option<Self> {
223 match value {
224 "sending" => Some(OutboxState::Sending),
225 "failed" => Some(OutboxState::Failed),
226 _ => None,
227 }
228 }
229}
230
231#[derive(Debug, Clone, PartialEq, Eq)]
232pub struct OutboxRecord {
233 pub id: String,
234 pub conversation_id: String,
235 pub target: OutboxTarget,
236 pub thread_root_id: Option<String>,
237 pub payload: String,
238 pub images: Vec<AttachmentImage>,
239 pub state: OutboxState,
240 pub last_error: Option<String>,
241 pub created_at: DateTime<Utc>,
242}
243
244#[derive(Debug, Clone, PartialEq, Eq)]
245pub struct DraftRecord {
246 pub conversation_id: String,
247 pub payload: String,
248 pub preview: String,
249 pub images: Vec<AttachmentImage>,
250 pub updated_at: DateTime<Utc>,
251}