use crate::errors::*;
use crate::types::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Message {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
id: i64,
sender_id: MessageSender,
receiver_id: Option<MessageSender>,
chat_id: i64,
sending_state: Option<MessageSendingState>,
scheduling_state: Option<MessageSchedulingState>,
is_outgoing: bool,
is_pinned: bool,
is_from_offline: bool,
can_be_saved: bool,
has_timestamped_media: bool,
is_channel_post: bool,
is_paid_star_suggested_post: bool,
is_paid_gram_suggested_post: bool,
contains_unread_mention: bool,
contains_unread_poll_votes: bool,
date: i64,
edit_date: i64,
forward_info: Option<MessageForwardInfo>,
import_info: Option<MessageImportInfo>,
interaction_info: Option<MessageInteractionInfo>,
unread_reactions: Vec<UnreadReaction>,
fact_check: Option<FactCheck>,
suggested_post_info: Option<SuggestedPostInfo>,
reply_to: Option<MessageReplyTo>,
topic_id: Option<MessageTopic>,
self_destruct_type: Option<MessageSelfDestructType>,
self_destruct_in: f32,
auto_delete_in: f32,
via_bot_user_id: i64,
guest_bot_caller_id: Option<MessageSender>,
sender_business_bot_user_id: i64,
sender_boost_count: i64,
sender_tag: String,
paid_message_star_count: i64,
author_signature: String,
#[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")]
media_album_id: isize,
#[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")]
effect_id: isize,
restriction_info: Option<RestrictionInfo>,
summary_language_code: String,
content: MessageContent,
ephemeral_content: Option<EphemeralMessageContent>,
reply_markup: Option<ReplyMarkup>,
ephemeral_message_id: i64,
#[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")]
chat_instance: isize,
}
impl RObject for Message {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
"message"
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
self.extra.clone()
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl Message {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> RTDMessageBuilder {
let inner = Message {
td_name: "message".to_string(),
extra: Some(Uuid::new_v4().to_string()),
..Default::default()
};
RTDMessageBuilder { inner }
}
pub fn id(&self) -> i64 {
self.id
}
pub fn sender_id(&self) -> &MessageSender {
&self.sender_id
}
pub fn receiver_id(&self) -> &Option<MessageSender> {
&self.receiver_id
}
pub fn chat_id(&self) -> i64 {
self.chat_id
}
pub fn sending_state(&self) -> &Option<MessageSendingState> {
&self.sending_state
}
pub fn scheduling_state(&self) -> &Option<MessageSchedulingState> {
&self.scheduling_state
}
pub fn is_outgoing(&self) -> bool {
self.is_outgoing
}
pub fn is_pinned(&self) -> bool {
self.is_pinned
}
pub fn is_from_offline(&self) -> bool {
self.is_from_offline
}
pub fn can_be_saved(&self) -> bool {
self.can_be_saved
}
pub fn has_timestamped_media(&self) -> bool {
self.has_timestamped_media
}
pub fn is_channel_post(&self) -> bool {
self.is_channel_post
}
pub fn is_paid_star_suggested_post(&self) -> bool {
self.is_paid_star_suggested_post
}
pub fn is_paid_gram_suggested_post(&self) -> bool {
self.is_paid_gram_suggested_post
}
pub fn contains_unread_mention(&self) -> bool {
self.contains_unread_mention
}
pub fn contains_unread_poll_votes(&self) -> bool {
self.contains_unread_poll_votes
}
pub fn date(&self) -> i64 {
self.date
}
pub fn edit_date(&self) -> i64 {
self.edit_date
}
pub fn forward_info(&self) -> &Option<MessageForwardInfo> {
&self.forward_info
}
pub fn import_info(&self) -> &Option<MessageImportInfo> {
&self.import_info
}
pub fn interaction_info(&self) -> &Option<MessageInteractionInfo> {
&self.interaction_info
}
pub fn unread_reactions(&self) -> &Vec<UnreadReaction> {
&self.unread_reactions
}
pub fn fact_check(&self) -> &Option<FactCheck> {
&self.fact_check
}
pub fn suggested_post_info(&self) -> &Option<SuggestedPostInfo> {
&self.suggested_post_info
}
pub fn reply_to(&self) -> &Option<MessageReplyTo> {
&self.reply_to
}
pub fn topic_id(&self) -> &Option<MessageTopic> {
&self.topic_id
}
pub fn self_destruct_type(&self) -> &Option<MessageSelfDestructType> {
&self.self_destruct_type
}
pub fn self_destruct_in(&self) -> f32 {
self.self_destruct_in
}
pub fn auto_delete_in(&self) -> f32 {
self.auto_delete_in
}
pub fn via_bot_user_id(&self) -> i64 {
self.via_bot_user_id
}
pub fn guest_bot_caller_id(&self) -> &Option<MessageSender> {
&self.guest_bot_caller_id
}
pub fn sender_business_bot_user_id(&self) -> i64 {
self.sender_business_bot_user_id
}
pub fn sender_boost_count(&self) -> i64 {
self.sender_boost_count
}
pub fn sender_tag(&self) -> &String {
&self.sender_tag
}
pub fn paid_message_star_count(&self) -> i64 {
self.paid_message_star_count
}
pub fn author_signature(&self) -> &String {
&self.author_signature
}
pub fn media_album_id(&self) -> isize {
self.media_album_id
}
pub fn effect_id(&self) -> isize {
self.effect_id
}
pub fn restriction_info(&self) -> &Option<RestrictionInfo> {
&self.restriction_info
}
pub fn summary_language_code(&self) -> &String {
&self.summary_language_code
}
pub fn content(&self) -> &MessageContent {
&self.content
}
pub fn ephemeral_content(&self) -> &Option<EphemeralMessageContent> {
&self.ephemeral_content
}
pub fn reply_markup(&self) -> &Option<ReplyMarkup> {
&self.reply_markup
}
pub fn ephemeral_message_id(&self) -> i64 {
self.ephemeral_message_id
}
pub fn chat_instance(&self) -> isize {
self.chat_instance
}
}
#[doc(hidden)]
pub struct RTDMessageBuilder {
inner: Message,
}
impl RTDMessageBuilder {
pub fn build(&self) -> Message {
self.inner.clone()
}
pub fn id(&mut self, id: i64) -> &mut Self {
self.inner.id = id;
self
}
pub fn sender_id<T: AsRef<MessageSender>>(&mut self, sender_id: T) -> &mut Self {
self.inner.sender_id = sender_id.as_ref().clone();
self
}
pub fn receiver_id<T: AsRef<MessageSender>>(&mut self, receiver_id: T) -> &mut Self {
self.inner.receiver_id = Some(receiver_id.as_ref().clone());
self
}
pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
self.inner.chat_id = chat_id;
self
}
pub fn sending_state<T: AsRef<MessageSendingState>>(&mut self, sending_state: T) -> &mut Self {
self.inner.sending_state = Some(sending_state.as_ref().clone());
self
}
pub fn scheduling_state<T: AsRef<MessageSchedulingState>>(
&mut self,
scheduling_state: T,
) -> &mut Self {
self.inner.scheduling_state = Some(scheduling_state.as_ref().clone());
self
}
pub fn is_outgoing(&mut self, is_outgoing: bool) -> &mut Self {
self.inner.is_outgoing = is_outgoing;
self
}
pub fn is_pinned(&mut self, is_pinned: bool) -> &mut Self {
self.inner.is_pinned = is_pinned;
self
}
pub fn is_from_offline(&mut self, is_from_offline: bool) -> &mut Self {
self.inner.is_from_offline = is_from_offline;
self
}
pub fn can_be_saved(&mut self, can_be_saved: bool) -> &mut Self {
self.inner.can_be_saved = can_be_saved;
self
}
pub fn has_timestamped_media(&mut self, has_timestamped_media: bool) -> &mut Self {
self.inner.has_timestamped_media = has_timestamped_media;
self
}
pub fn is_channel_post(&mut self, is_channel_post: bool) -> &mut Self {
self.inner.is_channel_post = is_channel_post;
self
}
pub fn is_paid_star_suggested_post(&mut self, is_paid_star_suggested_post: bool) -> &mut Self {
self.inner.is_paid_star_suggested_post = is_paid_star_suggested_post;
self
}
pub fn is_paid_gram_suggested_post(&mut self, is_paid_gram_suggested_post: bool) -> &mut Self {
self.inner.is_paid_gram_suggested_post = is_paid_gram_suggested_post;
self
}
pub fn contains_unread_mention(&mut self, contains_unread_mention: bool) -> &mut Self {
self.inner.contains_unread_mention = contains_unread_mention;
self
}
pub fn contains_unread_poll_votes(&mut self, contains_unread_poll_votes: bool) -> &mut Self {
self.inner.contains_unread_poll_votes = contains_unread_poll_votes;
self
}
pub fn date(&mut self, date: i64) -> &mut Self {
self.inner.date = date;
self
}
pub fn edit_date(&mut self, edit_date: i64) -> &mut Self {
self.inner.edit_date = edit_date;
self
}
pub fn forward_info<T: AsRef<MessageForwardInfo>>(&mut self, forward_info: T) -> &mut Self {
self.inner.forward_info = Some(forward_info.as_ref().clone());
self
}
pub fn import_info<T: AsRef<MessageImportInfo>>(&mut self, import_info: T) -> &mut Self {
self.inner.import_info = Some(import_info.as_ref().clone());
self
}
pub fn interaction_info<T: AsRef<MessageInteractionInfo>>(
&mut self,
interaction_info: T,
) -> &mut Self {
self.inner.interaction_info = Some(interaction_info.as_ref().clone());
self
}
pub fn unread_reactions(&mut self, unread_reactions: Vec<UnreadReaction>) -> &mut Self {
self.inner.unread_reactions = unread_reactions;
self
}
pub fn fact_check<T: AsRef<FactCheck>>(&mut self, fact_check: T) -> &mut Self {
self.inner.fact_check = Some(fact_check.as_ref().clone());
self
}
pub fn suggested_post_info<T: AsRef<SuggestedPostInfo>>(
&mut self,
suggested_post_info: T,
) -> &mut Self {
self.inner.suggested_post_info = Some(suggested_post_info.as_ref().clone());
self
}
pub fn reply_to<T: AsRef<MessageReplyTo>>(&mut self, reply_to: T) -> &mut Self {
self.inner.reply_to = Some(reply_to.as_ref().clone());
self
}
pub fn topic_id<T: AsRef<MessageTopic>>(&mut self, topic_id: T) -> &mut Self {
self.inner.topic_id = Some(topic_id.as_ref().clone());
self
}
pub fn self_destruct_type<T: AsRef<MessageSelfDestructType>>(
&mut self,
self_destruct_type: T,
) -> &mut Self {
self.inner.self_destruct_type = Some(self_destruct_type.as_ref().clone());
self
}
pub fn self_destruct_in(&mut self, self_destruct_in: f32) -> &mut Self {
self.inner.self_destruct_in = self_destruct_in;
self
}
pub fn auto_delete_in(&mut self, auto_delete_in: f32) -> &mut Self {
self.inner.auto_delete_in = auto_delete_in;
self
}
pub fn via_bot_user_id(&mut self, via_bot_user_id: i64) -> &mut Self {
self.inner.via_bot_user_id = via_bot_user_id;
self
}
pub fn guest_bot_caller_id<T: AsRef<MessageSender>>(
&mut self,
guest_bot_caller_id: T,
) -> &mut Self {
self.inner.guest_bot_caller_id = Some(guest_bot_caller_id.as_ref().clone());
self
}
pub fn sender_business_bot_user_id(&mut self, sender_business_bot_user_id: i64) -> &mut Self {
self.inner.sender_business_bot_user_id = sender_business_bot_user_id;
self
}
pub fn sender_boost_count(&mut self, sender_boost_count: i64) -> &mut Self {
self.inner.sender_boost_count = sender_boost_count;
self
}
pub fn sender_tag<T: AsRef<str>>(&mut self, sender_tag: T) -> &mut Self {
self.inner.sender_tag = sender_tag.as_ref().to_string();
self
}
pub fn paid_message_star_count(&mut self, paid_message_star_count: i64) -> &mut Self {
self.inner.paid_message_star_count = paid_message_star_count;
self
}
pub fn author_signature<T: AsRef<str>>(&mut self, author_signature: T) -> &mut Self {
self.inner.author_signature = author_signature.as_ref().to_string();
self
}
pub fn media_album_id(&mut self, media_album_id: isize) -> &mut Self {
self.inner.media_album_id = media_album_id;
self
}
pub fn effect_id(&mut self, effect_id: isize) -> &mut Self {
self.inner.effect_id = effect_id;
self
}
pub fn restriction_info<T: AsRef<RestrictionInfo>>(&mut self, restriction_info: T) -> &mut Self {
self.inner.restriction_info = Some(restriction_info.as_ref().clone());
self
}
pub fn summary_language_code<T: AsRef<str>>(&mut self, summary_language_code: T) -> &mut Self {
self.inner.summary_language_code = summary_language_code.as_ref().to_string();
self
}
pub fn content<T: AsRef<MessageContent>>(&mut self, content: T) -> &mut Self {
self.inner.content = content.as_ref().clone();
self
}
pub fn ephemeral_content<T: AsRef<EphemeralMessageContent>>(
&mut self,
ephemeral_content: T,
) -> &mut Self {
self.inner.ephemeral_content = Some(ephemeral_content.as_ref().clone());
self
}
pub fn reply_markup<T: AsRef<ReplyMarkup>>(&mut self, reply_markup: T) -> &mut Self {
self.inner.reply_markup = Some(reply_markup.as_ref().clone());
self
}
pub fn ephemeral_message_id(&mut self, ephemeral_message_id: i64) -> &mut Self {
self.inner.ephemeral_message_id = ephemeral_message_id;
self
}
pub fn chat_instance(&mut self, chat_instance: isize) -> &mut Self {
self.inner.chat_instance = chat_instance;
self
}
}
impl AsRef<Message> for Message {
fn as_ref(&self) -> &Message {
self
}
}
impl AsRef<Message> for RTDMessageBuilder {
fn as_ref(&self) -> &Message {
&self.inner
}
}