| 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 | #[derive(Debug, Clone, PartialEq)] |
| 30 | pub struct AvatarRecord { |
| 31 | pub user_id: String, |
| 32 | pub bytes: Option<Vec<u8>>, |
| 33 | pub content_type: String, |
| 34 | pub fetched_at: DateTime<Utc>, |
| 35 | } |
| 36 | |
| 37 | #[derive(Debug, Clone, PartialEq)] |
| 38 | pub struct FolderRecord { |
| 39 | pub id: String, |
| 40 | pub name: String, |
| 41 | pub kind: String, |
| 42 | pub expanded: bool, |
| 43 | pub conversation_ids: Vec<String>, |
| 44 | } |
| 45 | |
| 46 | #[derive(Debug, Clone, PartialEq)] |
| 47 | pub struct TeamRecord { |
| 48 | pub id: String, |
| 49 | pub name: String, |
| 50 | } |
| 51 | |
| 52 | #[derive(Debug, Clone, PartialEq)] |
| 53 | pub struct ChannelRecord { |
| 54 | pub id: String, |
| 55 | pub team_id: String, |
| 56 | pub name: String, |
| 57 | pub membership_type: Option<String>, |
| 58 | pub last_message_at: Option<DateTime<Utc>>, |
| 59 | pub unread: bool, |
| 60 | } |
| 61 | |
| 62 | #[derive(Debug, Clone, PartialEq, Default)] |
| 63 | pub struct MessageRecord { |
| 64 | pub conversation_id: String, |
| 65 | pub message_id: String, |
| 66 | pub reply_to_id: Option<String>, |
| 67 | pub sender_id: Option<String>, |
| 68 | pub sender_name: Option<String>, |
| 69 | pub created_at: DateTime<Utc>, |
| 70 | pub edited_at: Option<DateTime<Utc>>, |
| 71 | pub deleted: bool, |
| 72 | pub body_html: String, |
| 73 | pub attachments_json: String, |
| 74 | pub reactions_json: String, |
| 75 | pub mentions_json: String, |
| 76 | pub sender_application_id: Option<String>, |
| 77 | pub links_json: String, |
| 78 | pub subject: Option<String>, |
| 79 | } |
| 80 | |
| 81 | #[derive(Debug, Clone, PartialEq)] |
| 82 | pub struct SyncState { |
| 83 | pub newest_seen: Option<DateTime<Utc>>, |
| 84 | pub oldest_loaded: Option<DateTime<Utc>>, |
| 85 | pub has_more: bool, |
| 86 | pub older_cursor: Option<String>, |
| 87 | pub delta_link: Option<String>, |
| 88 | } |
| 89 | |
| 90 | impl Default for SyncState { |
| 91 | fn default() -> Self { |
| 92 | SyncState { |
| 93 | newest_seen: None, |
| 94 | oldest_loaded: None, |
| 95 | has_more: true, |
| 96 | older_cursor: None, |
| 97 | delta_link: None, |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | #[derive(Debug, Clone, PartialEq)] |
| 103 | pub struct SidebarTeam { |
| 104 | pub team: TeamRecord, |
| 105 | pub channels: Vec<ChannelRecord>, |
| 106 | pub hidden: bool, |
| 107 | pub hidden_channel_ids: Vec<String>, |
| 108 | pub notifications: HashMap<String, ChannelNotifications>, |
| 109 | } |
| 110 | |
| 111 | impl SidebarTeam { |
| 112 | pub fn channel_notifications(&self, channel_id: &str) -> ChannelNotifications { |
| 113 | self.notifications |
| 114 | .get(channel_id) |
| 115 | .copied() |
| 116 | .unwrap_or_default() |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 121 | pub enum ChannelNotificationLevel { |
| 122 | BannerAndFeed, |
| 123 | #[default] |
| 124 | Feed, |
| 125 | Off, |
| 126 | } |
| 127 | |
| 128 | impl ChannelNotificationLevel { |
| 129 | pub fn key(self) -> &'static str { |
| 130 | match self { |
| 131 | ChannelNotificationLevel::BannerAndFeed => "banner", |
| 132 | ChannelNotificationLevel::Feed => "feed", |
| 133 | ChannelNotificationLevel::Off => "off", |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | pub fn from_key(key: &str) -> Self { |
| 138 | match key { |
| 139 | "banner" => ChannelNotificationLevel::BannerAndFeed, |
| 140 | "off" => ChannelNotificationLevel::Off, |
| 141 | _ => ChannelNotificationLevel::Feed, |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 147 | pub struct ChannelNotifications { |
| 148 | pub level: ChannelNotificationLevel, |
| 149 | pub include_replies: bool, |
| 150 | } |
| 151 | |
| 152 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 153 | pub struct ChannelTabRecord { |
| 154 | pub tab_id: String, |
| 155 | pub name: String, |
| 156 | pub definition_id: String, |
| 157 | pub open_url: Option<String>, |
| 158 | } |
| 159 | |
| 160 | const WEBSITE_DEFINITION_ID: &str = "com.microsoft.teamspace.tab.web"; |
| 161 | |
| 162 | impl ChannelTabRecord { |
| 163 | pub fn is_website(&self) -> bool { |
| 164 | self.definition_id == WEBSITE_DEFINITION_ID && self.open_url.is_some() |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 169 | pub struct ChannelLayoutRecord { |
| 170 | pub channel_id: String, |
| 171 | pub general: bool, |
| 172 | pub hidden: bool, |
| 173 | pub tabs: Vec<ChannelTabRecord>, |
| 174 | pub notifications: ChannelNotifications, |
| 175 | } |
| 176 | |
| 177 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 178 | pub struct TeamLayoutRecord { |
| 179 | pub team_id: String, |
| 180 | pub hidden: bool, |
| 181 | pub channels: Vec<ChannelLayoutRecord>, |
| 182 | } |
| 183 | |
| 184 | /// 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. |
| 185 | #[derive(Debug, Clone, PartialEq, Default)] |
| 186 | pub struct Sidebar { |
| 187 | pub chats: Vec<ChatRecord>, |
| 188 | pub teams: Vec<SidebarTeam>, |
| 189 | } |
| 190 | |
| 191 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 192 | pub struct ChatPreview<'a> { |
| 193 | pub text: Option<&'a str>, |
| 194 | pub sender_id: Option<&'a str>, |
| 195 | pub sender_name: Option<&'a str>, |
| 196 | pub deleted: bool, |
| 197 | } |
| 198 | |
| 199 | #[derive(Debug, Clone, PartialEq)] |
| 200 | pub struct ImageRecord { |
| 201 | pub key: String, |
| 202 | pub bytes: Vec<u8>, |
| 203 | pub content_type: String, |
| 204 | pub fetched_at: DateTime<Utc>, |
| 205 | } |
| 206 | |
| 207 | #[derive(Debug, Clone, PartialEq)] |
| 208 | pub struct SearchHit { |
| 209 | pub conversation_id: String, |
| 210 | pub message_id: String, |
| 211 | pub sender_name: Option<String>, |
| 212 | pub created_at: DateTime<Utc>, |
| 213 | pub snippet: String, |
| 214 | } |
| 215 | |
| 216 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 217 | pub struct ConversationHit { |
| 218 | pub conversation_id: String, |
| 219 | pub title: String, |
| 220 | } |
| 221 | |
| 222 | #[derive(Debug, Clone, PartialEq)] |
| 223 | pub struct ActivityRecord { |
| 224 | pub id: i64, |
| 225 | pub conversation_id: String, |
| 226 | pub kind: String, |
| 227 | pub message_id: String, |
| 228 | pub actors_json: String, |
| 229 | pub preview: String, |
| 230 | pub glyphs: String, |
| 231 | pub count: u32, |
| 232 | pub updated_at: DateTime<Utc>, |
| 233 | pub read: bool, |
| 234 | } |
| 235 | |
| 236 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 237 | pub struct AttachmentImage { |
| 238 | pub name: String, |
| 239 | pub format: String, |
| 240 | pub bytes: Vec<u8>, |
| 241 | pub width: Option<u32>, |
| 242 | pub height: Option<u32>, |
| 243 | } |
| 244 | |
| 245 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 246 | pub enum OutboxTarget { |
| 247 | Flat, |
| 248 | Post, |
| 249 | Thread, |
| 250 | } |
| 251 | |
| 252 | impl OutboxTarget { |
| 253 | pub(crate) fn as_str(self) -> &'static str { |
| 254 | match self { |
| 255 | OutboxTarget::Flat => "flat", |
| 256 | OutboxTarget::Post => "post", |
| 257 | OutboxTarget::Thread => "thread", |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | pub(crate) fn parse(value: &str) -> Option<Self> { |
| 262 | match value { |
| 263 | "flat" => Some(OutboxTarget::Flat), |
| 264 | "post" => Some(OutboxTarget::Post), |
| 265 | "thread" => Some(OutboxTarget::Thread), |
| 266 | _ => None, |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 272 | pub enum OutboxState { |
| 273 | Sending, |
| 274 | Failed, |
| 275 | } |
| 276 | |
| 277 | impl OutboxState { |
| 278 | pub(crate) fn as_str(self) -> &'static str { |
| 279 | match self { |
| 280 | OutboxState::Sending => "sending", |
| 281 | OutboxState::Failed => "failed", |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | pub(crate) fn parse(value: &str) -> Option<Self> { |
| 286 | match value { |
| 287 | "sending" => Some(OutboxState::Sending), |
| 288 | "failed" => Some(OutboxState::Failed), |
| 289 | _ => None, |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 295 | pub struct OutboxRecord { |
| 296 | pub id: String, |
| 297 | pub conversation_id: String, |
| 298 | pub target: OutboxTarget, |
| 299 | pub thread_root_id: Option<String>, |
| 300 | pub payload: String, |
| 301 | pub images: Vec<AttachmentImage>, |
| 302 | pub state: OutboxState, |
| 303 | pub last_error: Option<String>, |
| 304 | pub created_at: DateTime<Utc>, |
| 305 | } |
| 306 | |
| 307 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 308 | pub struct DraftRecord { |
| 309 | pub conversation_id: String, |
| 310 | pub payload: String, |
| 311 | pub preview: String, |
| 312 | pub images: Vec<AttachmentImage>, |
| 313 | pub updated_at: DateTime<Utc>, |
| 314 | } |