sparkle-cache 0.14.1

A backend-agnostic Discord cache implementation for the Twilight ecosystem.
Documentation
use twilight_model::{
    channel::message::ReactionType,
    gateway::GatewayReaction,
    id::{
        marker::{ChannelMarker, GuildMarker, MessageMarker, UserMarker},
        Id,
    },
};

/// A cached reaction
///
/// It's the same as [`twilight_model::channel::Reaction`] except:
///
/// - `member` field is removed, as members are cached separately
///
/// - `emoji` field is changed to a string that is either the ID or the name of
///   the emoji
#[derive(Clone, Debug)]
#[cfg_attr(feature = "tests", derive(PartialEq, Eq))]
pub struct CachedReaction {
    pub channel_id: Id<ChannelMarker>,
    pub emoji: String,
    pub guild_id: Option<Id<GuildMarker>>,
    pub message_id: Id<MessageMarker>,
    pub user_id: Id<UserMarker>,
}

impl From<&GatewayReaction> for CachedReaction {
    fn from(reaction: &GatewayReaction) -> Self {
        Self {
            channel_id: reaction.channel_id,
            emoji: match &reaction.emoji {
                ReactionType::Custom { id, .. } => id.to_string(),
                ReactionType::Unicode { name } => name.clone(),
            },
            guild_id: reaction.guild_id,
            message_id: reaction.message_id,
            user_id: reaction.user_id,
        }
    }
}