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