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
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

View file

@ -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", "")

View file

@ -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])

View file

@ -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()

View file

@ -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

View file

@ -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, ',')

View file

@ -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"