Skip to content

Commit

Permalink
[Twitter] Fix quoted_status_result may be empty object
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Jan 30, 2025
1 parent b9b5002 commit cc58fed
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/source/platform/twitter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ mod data {
pub struct Result<T> {
pub result: T,
}

#[derive(Clone, Debug, PartialEq, Deserialize)]
#[serde(untagged, deny_unknown_fields)]
pub enum MaybeEmpty<T> {
Empty {},
Value(T),
}

impl<T> MaybeEmpty<T> {
pub fn into_option(self) -> Option<T> {
match self {
Self::Empty {} => None,
Self::Value(value) => Some(value),
}
}
}
}

#[derive(Clone, Debug, PartialEq, Deserialize)]
Expand Down Expand Up @@ -214,7 +230,7 @@ mod data {
pub rest_id: String,
pub core: TweetCore,
pub card: Option<TweetCard>,
pub quoted_status_result: Option<wrapper::Result<Box<ResultTweet>>>,
pub quoted_status_result: Option<wrapper::MaybeEmpty<wrapper::Result<Box<ResultTweet>>>>,
pub legacy: TweetLegacy,
}

Expand Down Expand Up @@ -474,7 +490,10 @@ fn parse_tweet(tweet: data::Tweet) -> Post {
let repost_from = if !tweet.legacy.is_quote_status {
tweet.legacy.retweeted_status_result
} else {
tweet.quoted_status_result
tweet
.quoted_status_result
.map(|q| q.into_option())
.flatten()
}
.map(|result| RepostFrom::Recursion(Box::new(parse_tweet(result.result.into_tweet()))));

Expand Down

0 comments on commit cc58fed

Please sign in to comment.