+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 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)]