fix media tab, remove likes tab

This commit is contained in:
Cynthia Foxwell 2024-08-16 12:45:29 -06:00
parent 501b395f26
commit 04f745c5eb
7 changed files with 41 additions and 26 deletions

View file

@ -24,14 +24,15 @@ proc getGraphUserTweets*(id: string; kind: TimelineKind; after=""): Future[Profi
if id.len == 0: return if id.len == 0: return
let let
cursor = if after.len > 0: "\"cursor\":\"$1\"," % after else: "" cursor = if after.len > 0: "\"cursor\":\"$1\"," % after else: ""
variables = userTweetsVariables % [id, cursor] variables = if kind == TimelineKind.media: userMediaVariables % [id, cursor] else: userTweetsVariables % [id, cursor]
params = {"variables": variables, "features": gqlFeatures} fieldToggles = """{"withArticlePlainText":true}"""
params = {"variables": variables, "features": gqlFeatures, "fieldToggles": fieldToggles}
(url, apiId) = case kind (url, apiId) = case kind
of TimelineKind.tweets: (graphUserTweets, Api.userTweets) of TimelineKind.tweets: (graphUserTweets, Api.userTweets)
of TimelineKind.replies: (graphUserTweetsAndReplies, Api.userTweetsAndReplies) of TimelineKind.replies: (graphUserTweetsAndReplies, Api.userTweetsAndReplies)
of TimelineKind.media: (graphUserMedia, Api.userMedia) of TimelineKind.media: (graphUserMedia, Api.userMedia)
js = await fetch(url ? params, apiId) 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.} = proc getGraphListTweets*(id: string; after=""): Future[Timeline] {.async.} =
if id.len == 0: return if id.len == 0: return

View file

@ -19,7 +19,7 @@ const
graphUserById* = graphql / "oPppcargziU1uDQHAUmH-A/UserResultByIdQuery" graphUserById* = graphql / "oPppcargziU1uDQHAUmH-A/UserResultByIdQuery"
graphUserTweets* = graphql / "3JNH4e9dq1BifLxAa3UMWg/UserWithProfileTweetsQueryV2" graphUserTweets* = graphql / "3JNH4e9dq1BifLxAa3UMWg/UserWithProfileTweetsQueryV2"
graphUserTweetsAndReplies* = graphql / "8IS8MaO-2EN6GZZZb8jF0g/UserWithProfileTweetsAndRepliesQueryV2" graphUserTweetsAndReplies* = graphql / "8IS8MaO-2EN6GZZZb8jF0g/UserWithProfileTweetsAndRepliesQueryV2"
graphUserMedia* = graphql / "PDfFf8hGeJvUCiTyWtw4wQ/MediaTimelineV2" graphUserMedia* = graphql / "dexO_2tohK86JDudXXG3Yw/UserMedia"
graphTweet* = graphql / "q94uRCEn65LZThakYcPT6g/TweetDetail" graphTweet* = graphql / "q94uRCEn65LZThakYcPT6g/TweetDetail"
graphTweetResult* = graphql / "sITyJdhRPpvpEjg4waUmTA/TweetResultByIdQuery" graphTweetResult* = graphql / "sITyJdhRPpvpEjg4waUmTA/TweetResultByIdQuery"
graphSearchTimeline* = graphql / "gkjsKepM6gl_HmFWoWKfgg/SearchTimeline" graphSearchTimeline* = graphql / "gkjsKepM6gl_HmFWoWKfgg/SearchTimeline"
@ -51,8 +51,11 @@ const
gqlFeatures* = """{ gqlFeatures* = """{
"android_graphql_skip_api_media_color_palette": false, "android_graphql_skip_api_media_color_palette": false,
"articles_preview_enabled": false,
"blue_business_profile_image_shape_enabled": false, "blue_business_profile_image_shape_enabled": false,
"c9s_tweet_anatomy_moderator_badge_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_subscription_count_enabled": false,
"creator_subscriptions_tweet_preview_api_enabled": true, "creator_subscriptions_tweet_preview_api_enabled": true,
"freedom_of_speech_not_reach_fetch_enabled": false, "freedom_of_speech_not_reach_fetch_enabled": false,
@ -74,6 +77,7 @@ const
"responsive_web_twitter_article_tweet_consumption_enabled": false, "responsive_web_twitter_article_tweet_consumption_enabled": false,
"responsive_web_twitter_blue_verified_badge_is_enabled": true, "responsive_web_twitter_blue_verified_badge_is_enabled": true,
"rweb_lists_timeline_redesign_enabled": true, "rweb_lists_timeline_redesign_enabled": true,
"rweb_tipjar_consumption_enabled": false,
"rweb_video_timestamps_enabled": true, "rweb_video_timestamps_enabled": true,
"spaces_2022_h2_clipping": true, "spaces_2022_h2_clipping": true,
"spaces_2022_h2_spaces_communities": true, "spaces_2022_h2_spaces_communities": true,
@ -114,26 +118,37 @@ const
# "withVoice": false, # "withVoice": false,
# "withV2Timeline": true # "withV2Timeline": true
# } # }
# """ # """.replace(" ", "").replace("\n", "")
userTweetsVariables* = """{ userTweetsVariables* = """{
"rest_id": "$1", $2 "rest_id": "$1",
$2
"count": 20 "count": 20
}""" }""".replace(" ", "").replace("\n", "")
listTweetsVariables* = """{ listTweetsVariables* = """{
"rest_id": "$1", $2 "rest_id": "$1",
$2
"count": 20 "count": 20
}""" }""".replace(" ", "").replace("\n", "")
reactorsVariables* = """{ reactorsVariables* = """{
"tweetId" : "$1", $2 "tweetId": "$1",
"count" : 20, $2
"count": 20,
"includePromotedContent": false "includePromotedContent": false
}""" }""".replace(" ", "").replace("\n", "")
followVariables* = """{ followVariables* = """{
"userId" : "$1", $2 "userId": "$1",
"count" : 20, $2
"count": 20,
"includePromotedContent": false "includePromotedContent": false
}""" }""".replace(" ", "").replace("\n", "")
userMediaVariables* = """{
"userId": "$1",
$2
"count": 20,
"includePromotedContent": false
}""".replace(" ", "").replace("\n", "")

View file

@ -110,7 +110,7 @@ proc createRssRouter*(cfg: Config) =
case tab case tab
of "with_replies": getReplyQuery(name) of "with_replies": getReplyQuery(name)
of "media": getMediaQuery(name) of "media": getMediaQuery(name)
of "favorites": getFavoritesQuery(name) #of "favorites": getFavoritesQuery(name)
of "search": initQuery(params(request), name=name) of "search": initQuery(params(request), name=name)
else: Query(fromUser: @[name]) else: Query(fromUser: @[name])

View file

@ -16,7 +16,7 @@ proc getQuery*(request: Request; tab, name: string): Query =
case tab case tab
of "with_replies": getReplyQuery(name) of "with_replies": getReplyQuery(name)
of "media": getMediaQuery(name) of "media": getMediaQuery(name)
of "favorites": getFavoritesQuery(name) #of "favorites": getFavoritesQuery(name)
of "search": initQuery(params(request), name=name) of "search": initQuery(params(request), name=name)
else: Query(fromUser: @[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 posts: await getGraphUserTweets(userId, TimelineKind.tweets, after)
of replies: await getGraphUserTweets(userId, TimelineKind.replies, after) of replies: await getGraphUserTweets(userId, TimelineKind.replies, after)
of media: await getGraphUserTweets(userId, TimelineKind.media, 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)) else: Profile(tweets: await getGraphTweetSearch(query, after))
result.user = await user result.user = await user
@ -111,7 +111,7 @@ proc createTimelineRouter*(cfg: Config) =
get "/@name/?@tab?/?": get "/@name/?@tab?/?":
cond '.' notin @"name" cond '.' notin @"name"
cond @"name" notin ["pic", "gif", "video", "search", "settings", "login", "intent", "i"] 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 let
prefs = cookiePrefs() prefs = cookiePrefs()
after = getCursor() after = getCursor()

View file

@ -117,9 +117,9 @@ proc getUserMedia*(id: string; after=""): Future[string] {.async.} =
if id.len == 0: return if id.len == 0: return
let let
cursor = if after.len > 0: "\"cursor\":\"$1\"," % after else: "" cursor = if after.len > 0: "\"cursor\":\"$1\"," % after else: ""
variables = userTweetsVariables % [id, cursor] variables = userMediaVariables % [id, cursor]
params = {"variables": variables, "features": gqlFeatures} 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.} = proc getTweetById*(id: string; after=""): Future[string] {.async.} =
let let

View file

@ -70,7 +70,6 @@ proc renderUserCard*(user: User; prefs: Prefs; path: string): VNode =
renderStat(user.following, "following") renderStat(user.following, "following")
a(href="/" & user.username & "/followers"): a(href="/" & user.username & "/followers"):
renderStat(user.followers, "followers") renderStat(user.followers, "followers")
a(href="/" & user.username & "/favorites"):
renderStat(user.likes, "likes") renderStat(user.likes, "likes")
proc renderPhotoRail(profile: Profile): VNode = proc renderPhotoRail(profile: Profile): VNode =

View file

@ -38,8 +38,8 @@ proc renderProfileTabs*(query: Query; username: string; cfg: Config): VNode =
a(href=(link & "/with_replies")): text "Tweets & Replies" a(href=(link & "/with_replies")): text "Tweets & Replies"
li(class=query.getTabClass(media)): li(class=query.getTabClass(media)):
a(href=(link & "/media")): text "Media" a(href=(link & "/media")): text "Media"
li(class=query.getTabClass(favorites)): #li(class=query.getTabClass(favorites)):
a(href=(link & "/favorites")): text "Likes" #a(href=(link & "/favorites")): text "Likes"
li(class=query.getTabClass(tweets)): li(class=query.getTabClass(tweets)):
a(href=(link & "/search")): text "Search" a(href=(link & "/search")): text "Search"