From 04f745c5ebbd581bd912047d1fa17ec7affa5226 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Fri, 16 Aug 2024 12:45:29 -0600 Subject: [PATCH] fix media tab, remove likes tab --- src/api.nim | 9 +++++---- src/consts.nim | 39 ++++++++++++++++++++++++++------------ src/routes/rss.nim | 2 +- src/routes/timeline.nim | 6 +++--- src/routes/twitter_api.nim | 4 ++-- src/views/profile.nim | 3 +-- src/views/search.nim | 4 ++-- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/api.nim b/src/api.nim index ef60812..bc5db05 100644 --- a/src/api.nim +++ b/src/api.nim @@ -24,14 +24,15 @@ proc getGraphUserTweets*(id: string; kind: TimelineKind; after=""): Future[Profi if id.len == 0: return let cursor = if after.len > 0: "\"cursor\":\"$1\"," % after else: "" - variables = userTweetsVariables % [id, cursor] - params = {"variables": variables, "features": gqlFeatures} + variables = if kind == TimelineKind.media: userMediaVariables % [id, cursor] else: userTweetsVariables % [id, cursor] + fieldToggles = """{"withArticlePlainText":true}""" + params = {"variables": variables, "features": gqlFeatures, "fieldToggles": fieldToggles} (url, apiId) = case kind of TimelineKind.tweets: (graphUserTweets, Api.userTweets) of TimelineKind.replies: (graphUserTweetsAndReplies, Api.userTweetsAndReplies) of TimelineKind.media: (graphUserMedia, Api.userMedia) js = await fetch(url ? params, apiId) - result = parseGraphTimeline(js, "user", after) + result = parseGraphTimeline(js, if kind == TimelineKind.media: "" else: "user", after) proc getGraphListTweets*(id: string; after=""): Future[Timeline] {.async.} = if id.len == 0: return @@ -82,7 +83,7 @@ proc getFavorites*(id: string; cfg: Config; after=""): Future[Profile] {.async.} } if after.len > 0: variables["cursor"] = % after - let + let url = consts.favorites ? {"variables": $variables, "features": gqlFeatures} result = parseGraphTimeline(await fetch(url, Api.favorites), after) diff --git a/src/consts.nim b/src/consts.nim index 3b5b300..8eb2057 100644 --- a/src/consts.nim +++ b/src/consts.nim @@ -19,7 +19,7 @@ const graphUserById* = graphql / "oPppcargziU1uDQHAUmH-A/UserResultByIdQuery" graphUserTweets* = graphql / "3JNH4e9dq1BifLxAa3UMWg/UserWithProfileTweetsQueryV2" graphUserTweetsAndReplies* = graphql / "8IS8MaO-2EN6GZZZb8jF0g/UserWithProfileTweetsAndRepliesQueryV2" - graphUserMedia* = graphql / "PDfFf8hGeJvUCiTyWtw4wQ/MediaTimelineV2" + graphUserMedia* = graphql / "dexO_2tohK86JDudXXG3Yw/UserMedia" graphTweet* = graphql / "q94uRCEn65LZThakYcPT6g/TweetDetail" graphTweetResult* = graphql / "sITyJdhRPpvpEjg4waUmTA/TweetResultByIdQuery" graphSearchTimeline* = graphql / "gkjsKepM6gl_HmFWoWKfgg/SearchTimeline" @@ -51,8 +51,11 @@ const gqlFeatures* = """{ "android_graphql_skip_api_media_color_palette": false, + "articles_preview_enabled": false, "blue_business_profile_image_shape_enabled": false, "c9s_tweet_anatomy_moderator_badge_enabled": false, + "communities_web_enable_tweet_community_results_fetch": false, + "creator_subscriptions_quote_tweet_preview_enabled": false, "creator_subscriptions_subscription_count_enabled": false, "creator_subscriptions_tweet_preview_api_enabled": true, "freedom_of_speech_not_reach_fetch_enabled": false, @@ -74,6 +77,7 @@ const "responsive_web_twitter_article_tweet_consumption_enabled": false, "responsive_web_twitter_blue_verified_badge_is_enabled": true, "rweb_lists_timeline_redesign_enabled": true, + "rweb_tipjar_consumption_enabled": false, "rweb_video_timestamps_enabled": true, "spaces_2022_h2_clipping": true, "spaces_2022_h2_spaces_communities": true, @@ -114,26 +118,37 @@ const # "withVoice": false, # "withV2Timeline": true # } -# """ +# """.replace(" ", "").replace("\n", "") userTweetsVariables* = """{ - "rest_id": "$1", $2 + "rest_id": "$1", + $2 "count": 20 -}""" +}""".replace(" ", "").replace("\n", "") listTweetsVariables* = """{ - "rest_id": "$1", $2 + "rest_id": "$1", + $2 "count": 20 -}""" +}""".replace(" ", "").replace("\n", "") reactorsVariables* = """{ - "tweetId" : "$1", $2 - "count" : 20, + "tweetId": "$1", + $2 + "count": 20, "includePromotedContent": false -}""" +}""".replace(" ", "").replace("\n", "") followVariables* = """{ - "userId" : "$1", $2 - "count" : 20, + "userId": "$1", + $2 + "count": 20, "includePromotedContent": false -}""" +}""".replace(" ", "").replace("\n", "") + + userMediaVariables* = """{ + "userId": "$1", + $2 + "count": 20, + "includePromotedContent": false +}""".replace(" ", "").replace("\n", "") \ No newline at end of file diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 0896536..2cae3af 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -110,7 +110,7 @@ proc createRssRouter*(cfg: Config) = case tab of "with_replies": getReplyQuery(name) of "media": getMediaQuery(name) - of "favorites": getFavoritesQuery(name) + #of "favorites": getFavoritesQuery(name) of "search": initQuery(params(request), name=name) else: Query(fromUser: @[name]) diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index b71e182..96e61a5 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -16,7 +16,7 @@ proc getQuery*(request: Request; tab, name: string): Query = case tab of "with_replies": getReplyQuery(name) of "media": getMediaQuery(name) - of "favorites": getFavoritesQuery(name) + #of "favorites": getFavoritesQuery(name) of "search": initQuery(params(request), name=name) else: Query(fromUser: @[name]) @@ -57,7 +57,7 @@ proc fetchProfile*(after: string; query: Query; cfg: Config; skipRail=false; of posts: await getGraphUserTweets(userId, TimelineKind.tweets, after) of replies: await getGraphUserTweets(userId, TimelineKind.replies, after) of media: await getGraphUserTweets(userId, TimelineKind.media, after) - of favorites: await getFavorites(userId, cfg, after) + #of favorites: await getFavorites(userId, cfg, after) else: Profile(tweets: await getGraphTweetSearch(query, after)) result.user = await user @@ -111,7 +111,7 @@ proc createTimelineRouter*(cfg: Config) = get "/@name/?@tab?/?": cond '.' notin @"name" cond @"name" notin ["pic", "gif", "video", "search", "settings", "login", "intent", "i"] - cond @"tab" in ["with_replies", "media", "search", "favorites", "following", "followers", ""] + cond @"tab" in ["with_replies", "media", "search", "following", "followers", ""] let prefs = cookiePrefs() after = getCursor() diff --git a/src/routes/twitter_api.nim b/src/routes/twitter_api.nim index 0b8eef3..ba3507e 100644 --- a/src/routes/twitter_api.nim +++ b/src/routes/twitter_api.nim @@ -117,9 +117,9 @@ proc getUserMedia*(id: string; after=""): Future[string] {.async.} = if id.len == 0: return let cursor = if after.len > 0: "\"cursor\":\"$1\"," % after else: "" - variables = userTweetsVariables % [id, cursor] + variables = userMediaVariables % [id, cursor] params = {"variables": variables, "features": gqlFeatures} - result = await fetchRaw(graphUserTweets ? params, Api.userMedia) + result = await fetchRaw(graphUserMedia ? params, Api.userMedia) proc getTweetById*(id: string; after=""): Future[string] {.async.} = let diff --git a/src/views/profile.nim b/src/views/profile.nim index b89bf43..7f15288 100644 --- a/src/views/profile.nim +++ b/src/views/profile.nim @@ -70,8 +70,7 @@ proc renderUserCard*(user: User; prefs: Prefs; path: string): VNode = renderStat(user.following, "following") a(href="/" & user.username & "/followers"): renderStat(user.followers, "followers") - a(href="/" & user.username & "/favorites"): - renderStat(user.likes, "likes") + renderStat(user.likes, "likes") proc renderPhotoRail(profile: Profile): VNode = let count = insertSep($profile.user.media, ',') diff --git a/src/views/search.nim b/src/views/search.nim index 0e5e808..abcc236 100644 --- a/src/views/search.nim +++ b/src/views/search.nim @@ -38,8 +38,8 @@ proc renderProfileTabs*(query: Query; username: string; cfg: Config): VNode = a(href=(link & "/with_replies")): text "Tweets & Replies" li(class=query.getTabClass(media)): a(href=(link & "/media")): text "Media" - li(class=query.getTabClass(favorites)): - a(href=(link & "/favorites")): text "Likes" + #li(class=query.getTabClass(favorites)): + #a(href=(link & "/favorites")): text "Likes" li(class=query.getTabClass(tweets)): a(href=(link & "/search")): text "Search"