use super::*;
pub(in crate::discord) fn touch_recent<T: PartialEq>(order: &mut VecDeque<T>, key: T) {
order.retain(|existing| *existing != key);
order.push_back(key);
}
pub(in crate::discord) fn drain_over_limit<T>(order: &mut VecDeque<T>, limit: usize) -> Vec<T> {
let excess = order.len().saturating_sub(limit);
order.drain(..excess).collect()
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct NavigationIndex {
pub(in crate::discord) guilds: BTreeMap<Id<GuildMarker>, GuildState>,
pub(in crate::discord) channels: BTreeMap<Id<ChannelMarker>, ChannelState>,
pub(in crate::discord) thread_creators: BTreeMap<Id<ChannelMarker>, ThreadCreatorState>,
pub(in crate::discord) custom_emojis: BTreeMap<Id<GuildMarker>, Vec<CustomEmojiInfo>>,
pub(in crate::discord) guild_folders: Vec<GuildFolder>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ThreadCreatorState {
pub guild_id: Option<Id<GuildMarker>>,
pub user_id: Id<UserMarker>,
}
#[derive(Clone, Debug)]
pub(in crate::discord) struct MessageCache {
pub(in crate::discord) timelines: BTreeMap<Id<ChannelMarker>, ChannelMessageTimeline>,
pub(in crate::discord) cold_message_channels: BTreeSet<Id<ChannelMarker>>,
pub(in crate::discord) warm_message_channels: VecDeque<Id<ChannelMarker>>,
pub(in crate::discord) pinned_messages: BTreeMap<Id<ChannelMarker>, VecDeque<MessageState>>,
pub(in crate::discord) message_author_role_ids: MessageAuthorRoleIds,
pub(in crate::discord) max_messages_per_channel: usize,
pub(in crate::discord) max_warm_message_channels: usize,
}
impl MessageCache {
pub(super) fn new(max_messages_per_channel: usize) -> Self {
Self {
timelines: BTreeMap::new(),
cold_message_channels: BTreeSet::new(),
warm_message_channels: VecDeque::new(),
pinned_messages: BTreeMap::new(),
message_author_role_ids: BTreeMap::new(),
max_messages_per_channel,
max_warm_message_channels: DEFAULT_MAX_WARM_MESSAGE_CHANNELS,
}
}
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct ChannelMessageTimeline {
pub(in crate::discord) messages: VecDeque<MessageState>,
pub(in crate::discord) segments: VecDeque<MessageSegment>,
pub(in crate::discord) historical_mode: bool,
pub(in crate::discord) active_focus: MessageTimelineFocus,
}
#[derive(Clone, Debug)]
pub(in crate::discord) struct MessageSegment {
pub(in crate::discord) message_ids: VecDeque<Id<MessageMarker>>,
pub(in crate::discord) active: bool,
pub(in crate::discord) reaches_live_edge: bool,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub(in crate::discord) enum MessageTimelineFocus {
#[default]
Newest,
Oldest,
Around(Id<MessageMarker>),
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct GuildDetailCache {
pub(in crate::discord) members:
BTreeMap<Id<GuildMarker>, BTreeMap<Id<UserMarker>, GuildMemberState>>,
pub(in crate::discord) member_cache_guild_order: VecDeque<Id<GuildMarker>>,
pub(in crate::discord) roles: BTreeMap<Id<GuildMarker>, BTreeMap<Id<RoleMarker>, RoleState>>,
pub(in crate::discord) current_user_role_ids: BTreeMap<Id<GuildMarker>, Vec<Id<RoleMarker>>>,
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct ProfileCache {
pub(in crate::discord) profile_role_ids: ProfileRoleIds,
pub(in crate::discord) user_profiles: BTreeMap<UserProfileCacheKey, UserProfileInfo>,
pub(in crate::discord) profile_cache_order: VecDeque<UserProfileCacheKey>,
pub(in crate::discord) fetched_notes: BTreeMap<Id<UserMarker>, Option<String>>,
pub(in crate::discord) fetched_note_order: VecDeque<Id<UserMarker>>,
pub(in crate::discord) relationships: BTreeMap<Id<UserMarker>, RelationshipInfo>,
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct PresenceCache {
pub(in crate::discord) guild_user_presences:
BTreeMap<(Id<GuildMarker>, Id<UserMarker>), PresenceStatus>,
pub(in crate::discord) guild_user_activities:
BTreeMap<(Id<GuildMarker>, Id<UserMarker>), Vec<ActivityInfo>>,
pub(in crate::discord) user_presences: BTreeMap<Id<UserMarker>, PresenceStatus>,
pub(in crate::discord) user_activities: BTreeMap<Id<UserMarker>, Vec<ActivityInfo>>,
pub(in crate::discord) typing:
BTreeMap<Id<ChannelMarker>, BTreeMap<Id<UserMarker>, TypingIndicator>>,
}
#[derive(Clone, Debug)]
pub(in crate::discord) struct TypingIndicator {
pub(in crate::discord) started: Instant,
pub(in crate::discord) display_name: Option<String>,
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct VoiceStateCache {
pub(in crate::discord) states:
BTreeMap<(VoiceScope, Id<UserMarker>), crate::discord::voice::VoiceState>,
pub(in crate::discord) streams: BTreeMap<String, crate::discord::voice::StreamState>,
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct SessionState {
pub(in crate::discord) current_user_id: Option<Id<UserMarker>>,
pub(in crate::discord) current_user: Option<String>,
pub(in crate::discord) current_user_premium_tier: Option<PremiumTier>,
pub(in crate::discord) current_user_email_verified: Option<bool>,
pub(in crate::discord) current_user_phone_verified: Option<bool>,
pub(in crate::discord) current_user_mfa_enabled: Option<bool>,
pub(in crate::discord) selected_message_channel_known: bool,
pub(in crate::discord) selected_message_channel_id: Option<Id<ChannelMarker>>,
pub(in crate::discord) ready_users:
BTreeMap<Id<UserMarker>, crate::discord::ChannelRecipientInfo>,
}
#[derive(Clone, Debug, Default)]
pub(in crate::discord) struct NotificationCache {
pub(in crate::discord) read_states: BTreeMap<Id<ChannelMarker>, ChannelReadState>,
pub(in crate::discord) non_channel_read_states: BTreeMap<(u8, u64), NonChannelReadState>,
pub(in crate::discord) user_notification_flags: u64,
pub(in crate::discord) notification_settings:
BTreeMap<Id<GuildMarker>, GuildNotificationSettingsState>,
pub(in crate::discord) private_notification_settings: Option<GuildNotificationSettingsState>,
}