twapi_v2/responses/
dm_events.rs1use crate::responses::{attachments::Attachments, referenced_tweets::ReferencedTweets};
2use chrono::prelude::*;
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
6pub struct DmEvents {
7 #[serde(skip_serializing_if = "Option::is_none")]
8 pub id: Option<String>,
9 #[serde(skip_serializing_if = "Option::is_none")]
10 pub text: Option<String>,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub event_type: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub created_at: Option<DateTime<Utc>>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub sender_id: Option<String>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub dm_conversation_id: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub attachments: Option<Attachments>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub referenced_tweets: Option<Vec<ReferencedTweets>>,
23 #[serde(flatten)]
24 pub extra: std::collections::HashMap<String, serde_json::Value>,
25}
26
27impl DmEvents {
28 pub fn is_empty_extra(&self) -> bool {
29 let res = self.extra.is_empty()
30 && self
31 .attachments
32 .as_ref()
33 .map(|it| it.is_empty_extra())
34 .unwrap_or(true)
35 && self
36 .referenced_tweets
37 .as_ref()
38 .map(|it| it.iter().all(|item| item.is_empty_extra()))
39 .unwrap_or(true);
40 if !res {
41 println!("DmEvents {:?}", self.extra);
42 }
43 res
44 }
45}