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