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
macro_rules! media_message {
    (
        struct $name:ident {
            #[doc = $media_doc:literal] $media:ident: $media_type:ty,
            $(#[doc = $field_doc:literal] $field:ident: $type:ty,)*
        } -> EventLoop::$handler:ident

        fn new(
            $($param:ident: $param_type:ty,)*
        ) -> Self {
            Self {
                $($new_field:ident: $value:expr,)*
            }
        }
    ) => {
        message_base! {
            struct $name {
                /// The replied message.
                reply_to: Option<crate::types::Message>,
                /// The author's signature, if enabled for the channel.
                author_signature: Option<String>,
                /// The origin of the message if it's a forward.
                forward: Option<crate::types::message::Forward>,
                /// The inline keyboard attached to the message.
                reply_markup: Option<crate::types::message::inline_markup::Keyboard>,
                #[doc = $media_doc]
                $media: $media_type,
                $(#[doc = $field_doc] $field: $type,)*
            } -> EventLoop::$handler

            fn new(
                $media: $media_type,
                $($param: $param_type,)*
            ) -> Self {
                infer reply_to;
                infer author_signature;
                infer forward;
                infer reply_markup;

                Self {
                    $media: $media,
                    $($new_field: $value,)*
                }
            }
        }

        impl<'a, C: 'static> super::traits::Forwardable<'a, C> for $name<C> {}
        impl<'a, C: 'static> super::traits::Pinnable<'a, C> for $name<C> {}

        impl<C> crate::contexts::fields::MediaMessage<C> for $name<C> {
            #[must_use]
            fn reply_to(&self) -> Option<&crate::types::Message> {
                self.reply_to.as_ref()
            }

            #[must_use]
            fn author_signature(&self) -> Option<&str> {
                self.author_signature.as_ref().map(String::as_str)
            }

            #[must_use]
            fn reply_markup(
                &self
            ) -> Option<&crate::types::message::inline_markup::Keyboard> {
                self.reply_markup.as_ref()
            }
        }

        impl<C> crate::contexts::fields::Forward<C> for $name<C> {
            #[must_use]
            fn forward(&self) -> Option<&crate::types::message::Forward> {
                self.forward.as_ref()
            }
        }
    };
}