Skip to content

Commit e686051

Browse files
committed
[Twitter] Treat reply as repost
1 parent e4b96ad commit e686051

File tree

8 files changed

+391
-196
lines changed

8 files changed

+391
-196
lines changed

Cargo.lock

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bytes = "1.10.1"
1010
chrono = "0.4.42"
1111
clap = { version = "4.5.48", features = ["derive"] }
1212
const_format = "0.2.35"
13+
futures = "0.3.31"
1314
headless_chrome = "1.0.18"
1415
http = "1.3.1"
1516
http-serde = "2.1.1"

src/platform/bilibili/source/space.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ fn parse_response(resp: data::SpaceHistory, blocked: &mut BlockedPostIds) -> any
710710
urls: PostUrls::new(url),
711711
time,
712712
is_pinned,
713-
repost_from: original.map(|original| RepostFrom::Recursion(Box::new(original))),
713+
repost_from: original.map(RepostFrom::new_quote),
714714
attachments: item
715715
.modules
716716
.dynamic

src/platform/qq/notify/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
platform::{PlatformMetadata, PlatformTrait},
1313
source::{
1414
LiveStatus, LiveStatusKind, Notification, NotificationKind, Post, PostAttachment, PostsRef,
15-
RepostFrom, StatusSource,
15+
StatusSource,
1616
},
1717
};
1818

@@ -288,7 +288,7 @@ impl Notifier {
288288
}
289289

290290
match &post.repost_from {
291-
Some(RepostFrom::Recursion(repost_from)) => {
291+
Some(repost_from) => {
292292
if !post.content.is_empty() {
293293
builder.ref_text("💬 ");
294294
builder.ref_text(format_if!(
@@ -302,9 +302,9 @@ impl Notifier {
302302
}
303303

304304
builder.ref_text("🔁 ");
305-
builder.ref_text(format!("{}: ", repost_from.user.nickname));
306-
append_media(&mut builder, repost_from.attachments(false));
307-
builder.ref_text(repost_from.content.fallback());
305+
builder.ref_text(format!("{}: ", repost_from.post.user.nickname));
306+
append_media(&mut builder, repost_from.post.attachments(false));
307+
builder.ref_text(repost_from.post.content.fallback());
308308
}
309309
None => {
310310
builder.ref_text(format_if!(

src/platform/telegram/notify/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use crate::{
2424
platform::{PlatformMetadata, PlatformTrait},
2525
source::{
2626
DocumentRef, FileRef, LiveStatus, LiveStatusKind, Notification, NotificationKind,
27-
PlaybackFormat, PlaybackRef, Post, PostAttachment, PostUrl, PostsRef, RepostFrom,
28-
StatusSource,
27+
PlaybackFormat, PlaybackRef, Post, PostAttachment, PostUrl, PostsRef, StatusSource,
2928
},
3029
};
3130

@@ -426,7 +425,7 @@ impl Notifier {
426425
));
427426

428427
match &post.repost_from {
429-
Some(RepostFrom::Recursion(repost_from)) => {
428+
Some(repost_from) => {
430429
if !post.content.is_empty() {
431430
text.push_plain("💬 ");
432431
if self.params.base.option.author_name {
@@ -444,13 +443,13 @@ impl Notifier {
444443
// post, we don't use `profile_url` here
445444
//
446445
// &repost_from.user.profile_url,
447-
if let PostUrl::Clickable(url) = &repost_from.urls_recursive().major() {
448-
text.push_link(&repost_from.user.nickname, &url.url);
446+
if let PostUrl::Clickable(url) = &repost_from.post.urls_recursive().major() {
447+
text.push_link(&repost_from.post.user.nickname, &url.url);
449448
} else {
450-
text.push_plain(&repost_from.user.nickname);
449+
text.push_plain(&repost_from.post.user.nickname);
451450
}
452451
text.push_plain(": ");
453-
text.push_content(&repost_from.content);
452+
text.push_content(&repost_from.post.content);
454453
});
455454
}
456455
None => {

src/platform/twitter/request.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,74 @@ impl TwitterRequester {
144144
.map_err(|err| anyhow!("failed to fetch user tweets: {err}"))
145145
}
146146

147+
pub async fn tweet_result_by_rest_id(
148+
&self,
149+
tweet_id: impl AsRef<str>,
150+
) -> anyhow::Result<reqwest::Response> {
151+
let tweet_id = tweet_id.as_ref();
152+
153+
let variables = json!({
154+
"tweetId": tweet_id,
155+
"includePromotedContent": true,
156+
"withBirdwatchNotes": true,
157+
"withVoice": true,
158+
"withCommunity": true
159+
});
160+
let features = json!({
161+
"creator_subscriptions_tweet_preview_api_enabled": true,
162+
"premium_content_api_read_enabled": false,
163+
"communities_web_enable_tweet_community_results_fetch": true,
164+
"c9s_tweet_anatomy_moderator_badge_enabled": true,
165+
"responsive_web_grok_analyze_button_fetch_trends_enabled": false,
166+
"responsive_web_grok_analyze_post_followups_enabled": true,
167+
"responsive_web_jetfuel_frame": true,
168+
"responsive_web_grok_share_attachment_enabled": true,
169+
"articles_preview_enabled": true,
170+
"responsive_web_edit_tweet_api_enabled": true,
171+
"graphql_is_translatable_rweb_tweet_is_translatable_enabled": true,
172+
"view_counts_everywhere_api_enabled": true,
173+
"longform_notetweets_consumption_enabled": true,
174+
"responsive_web_twitter_article_tweet_consumption_enabled": true,
175+
"tweet_awards_web_tipping_enabled": false,
176+
"responsive_web_grok_show_grok_translated_post": true,
177+
"responsive_web_grok_analysis_button_from_backend": true,
178+
"creator_subscriptions_quote_tweet_preview_enabled": false,
179+
"freedom_of_speech_not_reach_fetch_enabled": true,
180+
"standardized_nudges_misinfo": true,
181+
"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled": true,
182+
"longform_notetweets_rich_text_read_enabled": true,
183+
"longform_notetweets_inline_media_enabled": true,
184+
"payments_enabled": false,
185+
"profile_label_improvements_pcf_label_in_post_enabled": true,
186+
"responsive_web_profile_redirect_enabled": false,
187+
"rweb_tipjar_consumption_enabled": true,
188+
"verified_phone_label_enabled": false,
189+
"responsive_web_grok_image_annotation_enabled": true,
190+
"responsive_web_grok_imagine_annotation_enabled": true,
191+
"responsive_web_grok_community_note_auto_translation_is_enabled": false,
192+
"responsive_web_graphql_skip_user_profile_image_extensions_enabled": false,
193+
"responsive_web_graphql_timeline_navigation_enabled": true,
194+
"responsive_web_enhance_cards_enabled": false
195+
});
196+
let field_toggles = json!({
197+
"withArticleRichContentState": true,
198+
"withArticlePlainText": false
199+
});
200+
let mut url = Url::from_str(
201+
"https://x.com/i/api/graphql/WvlrBJ2bz8AuwoszWyie8A/TweetResultByRestId",
202+
)?;
203+
{
204+
let mut query = url.query_pairs_mut();
205+
query.append_pair("variables", &json::to_string(&variables)?);
206+
query.append_pair("features", &json::to_string(&features)?);
207+
query.append_pair("fieldToggles", &json::to_string(&field_toggles)?);
208+
}
209+
210+
self.request(url)
211+
.await
212+
.map_err(|err| anyhow!("failed to fetch tweet result by rest id: {err}"))
213+
}
214+
147215
async fn request(&self, url: impl AsRef<str>) -> anyhow::Result<reqwest::Response> {
148216
let resp = helper::reqwest_client()?
149217
.get(url.as_ref())

0 commit comments

Comments
 (0)