diff --git a/src/api.nim b/src/api.nim index ca3e659..de421cd 100644 --- a/src/api.nim +++ b/src/api.nim @@ -58,7 +58,7 @@ proc getGraphUser*(username: string): Future[User] {.async.} = proc getGraphUserById*(id: string): Future[User] {.async.} = if id.len == 0 or id.any(c => not c.isDigit): return let - url = apiReq(graphUserById, """{"rest_id": "$1"}""" % id) + url = apiReq(graphUserById, userByRestIdVars % id) js = await fetchRaw(url) result = parseGraphUser(js) diff --git a/src/consts.nim b/src/consts.nim index ff4aa42..f5e0064 100644 --- a/src/consts.nim +++ b/src/consts.nim @@ -9,7 +9,7 @@ const graphUser* = "IGgvgiOx4QZndDHuD3x9TQ/UserByScreenName" graphUserV2* = "-ZzAG_Bckx16LMbEvHC3lg/UserResultByScreenNameQuery" - graphUserById* = "-DAaa9jPxPswYeI2fZ9rug/UserResultByIdQuery" + graphUserById* = "xvmVfRLmnr1alc5f2dib0Q/UserByRestId" graphUserTweetsV2* = "LE3eTyeqhBh2g-fX85O2eQ/UserWithProfileTweetsQueryV2" graphUserTweetsAndRepliesV2* = "AcYHjc_YAx-9_rKWdMsKvA/UserWithProfileTweetsAndRepliesQueryV2" graphUserTweets* = "PNd0vlufvrcIwrAnBYKE9g/UserTweets" @@ -174,6 +174,11 @@ const "withCommunity": false }""".replace(" ", "").replace("\n", "") + userByRestIdVars* = """{ + "userId": "$1", + "withSafetyModeUserFields": true +}""".replace(" ", "").replace("\n", "") + communityTweetsVars* = """{ "communityId": "$1", $2 "count": 20, diff --git a/tests/test_profile.py b/tests/test_profile.py index cbf0256..f8a17e3 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -33,6 +33,12 @@ banner_image = [ ['mobile_test', 'profile_banners%2F82135242%2F1384108037%2F1500x500'] ] +# (user_id, expected_username) — resolving a numeric id to a profile (issue #1433) +id_redirects = [ + ['12', 'jack'], + ['44196397', 'elonmusk'] +] + class ProfileTest(BaseTestCase): @parameterized.expand(profiles) @@ -93,3 +99,19 @@ class ProfileTest(BaseTestCase): self.open_nitter(username) banner = self.find_element(Profile.banner + ' img') self.assertIn(url, banner.get_attribute('src')) + + +class UserIdRedirectTest(BaseTestCase): + @parameterized.expand(id_redirects) + def test_i_user_redirect(self, user_id, username): + """/i/user/ resolves the numeric id and redirects to the profile (issue #1433)""" + self.open_nitter(f'i/user/{user_id}') + self.assert_true(self.get_current_url().rstrip('/').endswith(f'/{username}')) + self.assert_exact_text(f'@{username}', Profile.username) + + @parameterized.expand(id_redirects) + def test_intent_user_redirect(self, user_id, username): + """/intent/user?user_id= redirects to the profile (issue #1433)""" + self.open_nitter(f'intent/user?user_id={user_id}') + self.assert_true(self.get_current_url().rstrip('/').endswith(f'/{username}')) + self.assert_exact_text(f'@{username}', Profile.username)