1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
//
// ferogram: async Telegram MTProto client in Rust
// https://github.com/ankit-chaubey/ferogram
//
// Licensed under either the MIT License or the Apache License 2.0.
// See the LICENSE-MIT or LICENSE-APACHE file in this repository:
// https://github.com/ankit-chaubey/ferogram
//
// Feel free to use, modify, and share this code.
// Please keep this notice when redistributing.
use ferogram_tl_types::{self as tl, enums::Reaction};
/// A set of reactions to apply to a message.
///
/// Construct with [`InputReactions::emoticon`], [`InputReactions::custom_emoji`],
/// [`InputReactions::remove`], or `From<Vec<Reaction>>`.
#[derive(Clone, Debug, Default)]
pub struct InputReactions {
pub(crate) reactions: Vec<Reaction>,
pub(crate) add_to_recent: bool,
pub(crate) big: bool,
}
impl InputReactions {
// Constructors
/// React with a standard Unicode emoji (e.g. `"👍"`).
pub fn emoticon<S: Into<String>>(emoticon: S) -> Self {
Self {
reactions: vec![Reaction::Emoji(tl::types::ReactionEmoji {
emoticon: emoticon.into(),
})],
..Self::default()
}
}
/// React with a custom (premium) emoji identified by its `document_id`.
pub fn custom_emoji(document_id: i64) -> Self {
Self {
reactions: vec![Reaction::CustomEmoji(tl::types::ReactionCustomEmoji {
document_id,
})],
..Self::default()
}
}
/// Remove all reactions from the message.
pub fn remove() -> Self {
Self::default()
}
// Modifiers
/// Play the reaction with a large animated effect.
pub fn big(mut self) -> Self {
self.big = true;
self
}
/// Add this reaction to the user's recent reactions list.
pub fn add_to_recent(mut self) -> Self {
self.add_to_recent = true;
self
}
}
// From impls
impl From<&str> for InputReactions {
fn from(s: &str) -> Self {
InputReactions::emoticon(s)
}
}
impl From<String> for InputReactions {
fn from(s: String) -> Self {
InputReactions::emoticon(s)
}
}
impl From<Vec<Reaction>> for InputReactions {
fn from(reactions: Vec<Reaction>) -> Self {
Self {
reactions,
..Self::default()
}
}
}
impl From<InputReactions> for Vec<Reaction> {
fn from(r: InputReactions) -> Self {
r.reactions
}
}