Skip to main content

grammers_client/message/
reactions.rs

1// Copyright 2020 - developers of the `grammers` project.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use grammers_tl_types::{self as tl, enums::Reaction};
10
11/// Parameter for reacting to messages with emoji.
12#[derive(Clone, Debug, Default)]
13pub struct InputReactions {
14    pub(crate) reactions: Vec<Reaction>,
15    pub(crate) add_to_recent: bool,
16    pub(crate) big: bool,
17}
18
19impl InputReactions {
20    /// Make reaction animation big.
21    pub fn big(mut self) -> Self {
22        self.big = true;
23        self
24    }
25
26    /// Add this reaction to the recent reactions list.
27    ///
28    /// [Read more about recent reactions](https://core.telegram.org/api/reactions#recent-reactions).
29    pub fn add_to_recent(mut self) -> Self {
30        self.add_to_recent = true;
31        self
32    }
33
34    /// Create new InputReactions with one emoticon reaction
35    pub fn emoticon<S: Into<String>>(emoticon: S) -> Self {
36        Self {
37            reactions: vec![Reaction::Emoji(tl::types::ReactionEmoji {
38                emoticon: emoticon.into(),
39            })],
40            ..Self::default()
41        }
42    }
43
44    /// Create new InputReactions with one custom emoji reaction
45    pub fn custom_emoji(document_id: i64) -> Self {
46        Self {
47            reactions: vec![Reaction::CustomEmoji(tl::types::ReactionCustomEmoji {
48                document_id,
49            })],
50            ..Self::default()
51        }
52    }
53
54    /// Create an empty InputReactions which will remove reactions
55    pub fn remove() -> Self {
56        Self::default()
57    }
58}
59
60impl From<String> for InputReactions {
61    fn from(val: String) -> Self {
62        InputReactions::emoticon(val)
63    }
64}
65
66impl From<&str> for InputReactions {
67    fn from(val: &str) -> Self {
68        InputReactions::emoticon(val)
69    }
70}
71
72impl From<Vec<Reaction>> for InputReactions {
73    fn from(reactions: Vec<Reaction>) -> Self {
74        Self {
75            reactions,
76            ..Self::default()
77        }
78    }
79}
80
81impl From<InputReactions> for Vec<Reaction> {
82    fn from(val: InputReactions) -> Self {
83        val.reactions
84    }
85}