From ccbfee24b83eba5fd8062a08755c3e0bd34ef6f7 Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 19 Sep 2019 18:24:11 +0300 Subject: [PATCH] +Message::text(&self); message_kind->kind; IncomingMessage->CommonMessage --- src/core/types/message.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/types/message.rs b/src/core/types/message.rs index ebc76355..2252f54f 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -11,13 +11,26 @@ pub struct Message { pub date: i32, pub chat: Chat, #[serde(flatten)] - pub message_kind: MessageKind, + pub kind: MessageKind, +} + +impl Message { + fn text(&self) -> Option<&str> { + if let MessageKind::CommonMessage { + media_kind: MediaKind::Text { + ref text, .. + }, .. } = self.kind { + Some(text) + } else { + None + } + } } #[derive(Debug, Deserialize, PartialEq, Clone)] #[serde(untagged)] pub enum MessageKind { - IncomingMessage { + CommonMessage { #[serde(flatten)] from: Sender, #[serde(flatten)]