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