use std::collections::HashMap; use chrono::{DateTime, Utc}; pub const BOT_MRI_PREFIX: &str = "28:"; pub fn is_bot_id(user_id: &str) -> bool { user_id.starts_with(BOT_MRI_PREFIX) } #[derive(Debug, Clone, PartialEq, Default)] pub struct MemberRecord { pub user_id: Option, pub display_name: String, } impl MemberRecord { pub fn is_bot(&self) -> bool { self.user_id.as_deref().is_some_and(is_bot_id) } } #[derive(Debug, Clone, PartialEq, Default)] pub struct ChatRecord { pub id: String, pub kind: String, pub title: String, pub member_summary: String, pub last_message_at: Option>, pub last_read_at: Option>, pub unread: bool, pub muted: bool, pub members: Vec, pub last_message_preview: Option, pub last_message_sender_id: Option, pub last_message_sender_name: Option, pub last_message_deleted: bool, pub last_event_system: bool, pub last_event_call: bool, } impl ChatRecord { pub fn display_title(&self) -> String { if !self.title.trim().is_empty() { self.title.clone() } else if !self.member_summary.trim().is_empty() { self.member_summary.clone() } else { "Chat".to_owned() } } } #[derive(Debug, Clone, PartialEq)] pub struct AvatarRecord { pub user_id: String, pub bytes: Option>, pub content_type: String, pub fetched_at: DateTime, } #[derive(Debug, Clone, PartialEq)] pub struct FolderRecord { pub id: String, pub name: String, pub kind: String, pub expanded: bool, pub conversation_ids: Vec, } #[derive(Debug, Clone, PartialEq)] pub struct TeamRecord { pub id: String, pub name: String, } #[derive(Debug, Clone, PartialEq)] pub struct ChannelRecord { pub id: String, pub team_id: String, pub name: String, pub membership_type: Option, pub last_message_at: Option>, pub unread: bool, } #[derive(Debug, Clone, PartialEq, Default)] pub struct MessageRecord { pub conversation_id: String, pub message_id: String, pub reply_to_id: Option, pub sender_id: Option, pub sender_name: Option, pub created_at: DateTime, pub edited_at: Option>, pub deleted: bool, pub body_html: String, pub attachments_json: String, pub reactions_json: String, pub mentions_json: String, pub sender_application_id: Option, pub links_json: String, pub subject: Option, pub call_event_json: Option, } #[derive(Debug, Clone, PartialEq)] pub struct RecentScope { pub conversation_id: String, pub after: DateTime, } #[derive(Debug, Clone, PartialEq)] pub struct SyncState { pub newest_seen: Option>, pub oldest_loaded: Option>, pub has_more: bool, pub older_cursor: Option, pub delta_link: Option, } impl Default for SyncState { fn default() -> Self { SyncState { newest_seen: None, oldest_loaded: None, has_more: true, older_cursor: None, delta_link: None, } } } #[derive(Debug, Clone, PartialEq)] pub struct SidebarTeam { pub team: TeamRecord, pub channels: Vec, pub hidden: bool, pub hidden_channel_ids: Vec, pub notifications: HashMap, } impl SidebarTeam { pub fn channel_notifications(&self, channel_id: &str) -> ChannelNotifications { self.notifications .get(channel_id) .copied() .unwrap_or_default() } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum ChannelNotificationLevel { BannerAndFeed, #[default] Feed, Off, } impl ChannelNotificationLevel { pub fn key(self) -> &'static str { match self { ChannelNotificationLevel::BannerAndFeed => "banner", ChannelNotificationLevel::Feed => "feed", ChannelNotificationLevel::Off => "off", } } pub fn from_key(key: &str) -> Self { match key { "banner" => ChannelNotificationLevel::BannerAndFeed, "off" => ChannelNotificationLevel::Off, _ => ChannelNotificationLevel::Feed, } } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct ChannelNotifications { pub level: ChannelNotificationLevel, pub include_replies: bool, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct ChannelTabRecord { pub tab_id: String, pub name: String, pub definition_id: String, pub open_url: Option, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct ChannelLayoutRecord { pub channel_id: String, pub general: bool, pub hidden: bool, pub tabs: Vec, pub notifications: ChannelNotifications, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct TeamLayoutRecord { pub team_id: String, pub hidden: bool, pub channels: Vec, } /// 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. #[derive(Debug, Clone, PartialEq, Default)] pub struct Sidebar { pub chats: Vec, pub teams: Vec, } #[derive(Debug, Clone, Copy, PartialEq)] pub struct ChatPreview<'a> { pub text: Option<&'a str>, pub sender_id: Option<&'a str>, pub sender_name: Option<&'a str>, pub deleted: bool, } #[derive(Debug, Clone, PartialEq)] pub struct ImageRecord { pub key: String, pub bytes: Vec, pub content_type: String, pub fetched_at: DateTime, } #[derive(Debug, Clone, PartialEq)] pub struct SearchHit { pub conversation_id: String, pub message_id: String, pub sender_name: Option, pub created_at: DateTime, pub snippet: String, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConversationHit { pub conversation_id: String, pub title: String, } #[derive(Debug, Clone, PartialEq)] pub struct ActivityRecord { pub id: i64, pub conversation_id: String, pub kind: String, pub message_id: String, pub actors_json: String, pub preview: String, pub glyphs: String, pub count: u32, pub updated_at: DateTime, pub read: bool, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct AttachmentImage { pub name: String, pub format: String, pub bytes: Vec, pub width: Option, pub height: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum OutboxTarget { Flat, Post, Thread, } impl OutboxTarget { pub(crate) fn as_str(self) -> &'static str { match self { OutboxTarget::Flat => "flat", OutboxTarget::Post => "post", OutboxTarget::Thread => "thread", } } pub(crate) fn parse(value: &str) -> Option { match value { "flat" => Some(OutboxTarget::Flat), "post" => Some(OutboxTarget::Post), "thread" => Some(OutboxTarget::Thread), _ => None, } } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum OutboxState { Sending, Failed, } impl OutboxState { pub(crate) fn as_str(self) -> &'static str { match self { OutboxState::Sending => "sending", OutboxState::Failed => "failed", } } pub(crate) fn parse(value: &str) -> Option { match value { "sending" => Some(OutboxState::Sending), "failed" => Some(OutboxState::Failed), _ => None, } } } #[derive(Debug, Clone, PartialEq, Eq)] pub struct OutboxRecord { pub id: String, pub conversation_id: String, pub target: OutboxTarget, pub thread_root_id: Option, pub payload: String, pub images: Vec, pub state: OutboxState, pub last_error: Option, pub created_at: DateTime, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct DraftRecord { pub conversation_id: String, pub payload: String, pub preview: String, pub images: Vec, pub updated_at: DateTime, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct AgentProposalMention { pub user_id: String, pub name: String, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct AgentProposalRecord { pub id: String, pub conversation_id: String, pub reply_to_message_id: Option, pub text: String, pub mentions: Vec, pub images: Vec, pub agent: Option, pub session_id: Option, pub created_at: DateTime, pub state: String, pub resolved_at: Option>, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct AgentReactionRecord { pub id: String, pub conversation_id: String, pub message_id: String, pub emoji: String, pub agent: Option, pub session_id: Option, pub created_at: DateTime, pub state: String, pub resolved_at: Option>, }