+Message::text(&self); message_kind->kind; IncomingMessage->CommonMessage

This commit is contained in:
Mr-Andersen 2019-09-19 18:24:11 +03:00
parent ced6bd8e69
commit ccbfee24b8

View file

@ -11,13 +11,26 @@ pub struct Message {
pub date: i32, pub date: i32,
pub chat: Chat, pub chat: Chat,
#[serde(flatten)] #[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)] #[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(untagged)] #[serde(untagged)]
pub enum MessageKind { pub enum MessageKind {
IncomingMessage { CommonMessage {
#[serde(flatten)] #[serde(flatten)]
from: Sender, from: Sender,
#[serde(flatten)] #[serde(flatten)]