Skip to content

Commit

Permalink
Add a new field is_pinned to struct Post
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Feb 17, 2025
1 parent 9b0ddfb commit 4772a8d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pub struct Post {
pub content: PostContent,
urls: PostUrls,
pub time: DateTime<Local>,
pub is_pinned: bool,
pub repost_from: Option<RepostFrom>,
attachments: Vec<PostAttachment>,
}
Expand Down Expand Up @@ -506,6 +507,7 @@ mod tests {
content: PostContent::plain("content1"),
urls: PostUrls::new(PostUrl::Identity("id1".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
}])),
Expand All @@ -529,6 +531,7 @@ mod tests {
content: PostContent::plain("content1"),
urls: PostUrls::new(PostUrl::Identity("id1".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand All @@ -537,6 +540,7 @@ mod tests {
content: PostContent::plain("content2"),
urls: PostUrls::new(PostUrl::Identity("id2".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand All @@ -555,6 +559,7 @@ mod tests {
content: PostContent::plain("content1"),
urls: PostUrls::new(PostUrl::Identity("id1".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand All @@ -563,6 +568,7 @@ mod tests {
content: PostContent::plain("content2"),
urls: PostUrls::new(PostUrl::Identity("id2".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand Down Expand Up @@ -596,6 +602,7 @@ mod tests {
content: PostContent::plain("content3"),
urls: PostUrls::new(PostUrl::Identity("id3".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
}])),
Expand All @@ -616,6 +623,7 @@ mod tests {
content: PostContent::plain("content1"),
urls: PostUrls::new(PostUrl::Identity("id1".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand All @@ -624,6 +632,7 @@ mod tests {
content: PostContent::plain("content2"),
urls: PostUrls::new(PostUrl::Identity("id2".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand All @@ -632,6 +641,7 @@ mod tests {
content: PostContent::plain("content3"),
urls: PostUrls::new(PostUrl::Identity("id3".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
},
Expand Down Expand Up @@ -685,6 +695,7 @@ mod tests {
content: PostContent::plain("content1"),
urls: PostUrls::new(PostUrl::Identity("id1".into())),
time: DateTime::UNIX_EPOCH.into(),
is_pinned: false,
repost_from: None,
attachments: vec![],
}])),
Expand Down
14 changes: 14 additions & 0 deletions src/source/platform/bilibili/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ mod data {
pub author: ModuleAuthor,
#[serde(rename = "module_dynamic")]
pub dynamic: ModuleDynamic,
#[serde(rename = "module_tag")]
pub tag: Option<ModuleTag>,
}

#[derive(Debug, Deserialize)]
pub struct ModuleTag {
pub text: String,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -669,11 +676,18 @@ fn parse_response(resp: data::SpaceHistory, blocked: &mut BlockedPostIds) -> any
.ok_or_else(|| anyhow!("invalid pub time, url={url:?}"))?
.into();

let is_pinned = item
.modules
.tag
.as_ref()
.is_some_and(|tag| tag.text == "置顶");

Ok(Post {
user: Some(item.modules.author.clone().into()),
content,
urls: PostUrls::new(url),
time,
is_pinned,
repost_from: original.map(|original| RepostFrom::Recursion(Box::new(original))),
attachments: item
.modules
Expand Down
1 change: 1 addition & 0 deletions src/source/platform/bilibili/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn parse_response(resp: data::SeriesArchives) -> anyhow::Result<Posts> {
)
.into(),
time,
is_pinned: false,
repost_from: None,
attachments: vec![PostAttachment::Image(PostAttachmentImage {
media_url: upgrade_to_https(&archive.pic),
Expand Down
10 changes: 10 additions & 0 deletions src/source/platform/twitter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ mod data {
pub description: String,
pub location: String,
pub name: String,
pub pinned_tweet_ids_str: Vec<String>,
pub profile_banner_url: Option<String>,
pub profile_image_url_https: String, // Very small..
pub screen_name: String,
Expand Down Expand Up @@ -606,11 +607,20 @@ fn parse_tweet(tweet: data::Tweet) -> anyhow::Result<Post> {
})?
.into();

let is_pinned = tweet
.core
.user_results
.result
.legacy
.pinned_tweet_ids_str
.contains(&tweet.rest_id);

Ok(Post {
user: Some(tweet.core.user_results.result.into()),
content: PostContent::plain(content.unwrap_or_else(|| "".into())),
urls,
time,
is_pinned,
repost_from,
attachments,
})
Expand Down

0 comments on commit 4772a8d

Please sign in to comment.