Skip to main content

tilo_actions/
reaction.rs

1//! Reactions as a reader sees them: who answered something with which emoji.
2//! The record a thing keeps its reactions in is the resource model's; what a
3//! reaction strip shows is plain data any view can draw.
4
5use tilo_action_policy::MemberId;
6
7/// One person (or outside account) among those who reacted with an emoji.
8#[derive(Clone, Debug, PartialEq, Eq)]
9pub struct Reactor {
10    /// The member who invoked the reaction.
11    pub by: MemberId,
12    /// The outside account a bot reacted for.
13    pub persona: Option<String>,
14    /// The name that account shows.
15    pub name: Option<String>,
16}
17
18/// Everyone who reacted with one emoji, first reaction first.
19#[derive(Clone, Debug, PartialEq, Eq)]
20pub struct ReactionGroup {
21    pub emoji: String,
22    pub reactors: Vec<Reactor>,
23    /// When the first of them reacted.
24    pub first_at: i64,
25}
26
27impl ReactionGroup {
28    #[must_use]
29    pub fn count(&self) -> usize {
30        self.reactors.len()
31    }
32
33    /// Whether `member` is among them themselves.
34    #[must_use]
35    pub fn includes(&self, member: &MemberId) -> bool {
36        self.reactors
37            .iter()
38            .any(|reactor| reactor.persona.is_none() && reactor.by == *member)
39    }
40}