From 211b086f4dcff9cdcbea58e9c02179baaddf762b Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 8 Oct 2019 15:15:47 +0200 Subject: [PATCH] Use "max_position" instead of "after" for compat --- src/api/search.nim | 5 ++--- src/formatters.nim | 11 ++--------- src/query.nim | 15 --------------- src/routes/list.nim | 6 +++--- src/routes/search.nim | 4 ++-- src/routes/status.nim | 2 +- src/routes/timeline.nim | 2 +- src/views/timeline.nim | 2 +- tests/test_timeline.py | 6 +++--- tests/test_tweet.py | 4 ++-- 10 files changed, 17 insertions(+), 40 deletions(-) diff --git a/src/api/search.nim b/src/api/search.nim index dd0acd3..2a55c5a 100644 --- a/src/api/search.nim +++ b/src/api/search.nim @@ -9,7 +9,7 @@ proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] = Result[T]( hasMore: json{"has_more_items"}.getBool(false), maxId: json{"max_position"}.getStr(""), - minId: json{"min_position"}.getStr("").cleanPos(), + minId: json{"min_position"}.getStr(""), query: query, beginning: after.len == 0 ) @@ -17,7 +17,6 @@ proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] = proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.async.} = let kind = if query.kind == users: "users" else: "tweets" - pos = when T is Tweet: genPos(after) else: after param = genQueryParam(query) encoded = encodeUrl(param, usePlus=false) @@ -32,7 +31,7 @@ proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.asyn "src": "typd", "include_available_features": "1", "include_entities": "1", - "max_position": if pos.len > 0: pos else: "0", + "max_position": if after.len > 0: after else: "0", "reset_error_state": "false" } diff --git a/src/formatters.nim b/src/formatters.nim index f34af74..69d1a94 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -146,21 +146,14 @@ proc getTwitterLink*(path: string; params: Table[string, string]): string = username = params.getOrDefault("name") query = initQuery(params, username) - var after = params.getOrDefault("after", "0") - if query.kind notin {userList, users} and "/members" notin path: - after = after.genPos() - - var paramList = filterParams(params).mapIt( - if it[0] == "after": ("max_position", after) else: it) - if "/search" notin path: - return $(twitter / path ? paramList) + return $(twitter / path ? filterParams(params)) let p = { "f": $query.kind, "q": genQueryParam(query), "src": "typd", - "max_position": after + "max_position": params.getOrDefault("max_position", "0") } result = $(parseUri("https://twitter.com") / path ? p) diff --git a/src/query.nim b/src/query.nim index bb5bf97..1cede1d 100644 --- a/src/query.nim +++ b/src/query.nim @@ -12,12 +12,6 @@ const "verified", "safe" ] -# Experimental, this might break in the future -# Till then, it results in shorter urls -const - posPrefix = "thGAVUV0VFVB" - posSuffix = "EjUAFQAlAFUAFQAA" - template `@`(param: string): untyped = if param in pms: pms[param] else: "" @@ -105,12 +99,3 @@ proc genQueryUrl*(query: Query): string = if params.len > 0: result &= params.join("&") - -proc cleanPos*(pos: string): string = - pos.multiReplace((posPrefix, ""), (posSuffix, "")) - -proc genPos*(pos: string): string = - if pos.len == 0 or pos == "0": return pos - result = posPrefix & pos - if "A==" notin result: - result &= posSuffix diff --git a/src/routes/list.nim b/src/routes/list.nim index 9206504..b393e65 100644 --- a/src/routes/list.nim +++ b/src/routes/list.nim @@ -18,17 +18,17 @@ proc createListRouter*(cfg: Config) = get "/@name/lists/@list": cond '.' notin @"name" let - list = await getListTimeline(@"name", @"list", getAgent(), @"after") + list = await getListTimeline(@"name", @"list", getAgent(), @"max_position") tweets = renderTimelineTweets(list, cookiePrefs(), request.path) respList list, tweets get "/@name/lists/@list/members": cond '.' notin @"name" let list = - if @"after".len == 0: + if @"max_position".len == 0: await getListMembers(@"name", @"list", getAgent()) else: - await getListMembersSearch(@"name", @"list", getAgent(), @"after") + await getListMembersSearch(@"name", @"list", getAgent(), @"max_position") let users = renderTimelineUsers(list, cookiePrefs(), request.path) respList list, users diff --git a/src/routes/search.nim b/src/routes/search.nim index 0b5ab16..46cb255 100644 --- a/src/routes/search.nim +++ b/src/routes/search.nim @@ -21,10 +21,10 @@ proc createSearchRouter*(cfg: Config) = of users: if "," in @"q": redirect("/" & @"q") - let users = await getSearch[Profile](query, @"after", getAgent()) + let users = await getSearch[Profile](query, @"max_position", getAgent()) resp renderMain(renderUserSearch(users, prefs), request, cfg.title) of tweets: - let tweets = await getSearch[Tweet](query, @"after", getAgent()) + let tweets = await getSearch[Tweet](query, @"max_position", getAgent()) let rss = "/search/rss?" & genQueryUrl(query) resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request, cfg.title, rss=rss) diff --git a/src/routes/status.nim b/src/routes/status.nim index 8329b29..0798126 100644 --- a/src/routes/status.nim +++ b/src/routes/status.nim @@ -17,7 +17,7 @@ proc createStatusRouter*(cfg: Config) = cond '.' notin @"name" let prefs = cookiePrefs() - let conversation = await getTweet(@"name", @"id", @"after", getAgent()) + let conversation = await getTweet(@"name", @"id", @"max_position", getAgent()) if conversation == nil or conversation.tweet.id.len == 0: var error = "Tweet not found" if conversation != nil and conversation.tweet.tombstone.len > 0: diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index baee8ca..fad8e66 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -56,7 +56,7 @@ proc showTimeline*(request: Request; query: Query; title, rss: string): Future[s agent = getAgent() prefs = cookiePrefs() name = request.get("name") - after = request.get("after") + after = request.get("max_position") names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0) if names.len == 1: diff --git a/src/views/timeline.nim b/src/views/timeline.nim index c2dff1e..ebbc8bd 100644 --- a/src/views/timeline.nim +++ b/src/views/timeline.nim @@ -19,7 +19,7 @@ proc renderNewer*(query: Query; path: string): VNode = proc renderMore*(query: Query; minId: string): VNode = buildHtml(tdiv(class="show-more")): - a(href=(&"?{getQuery(query)}after={minId}")): + a(href=(&"?{getQuery(query)}max_position={minId}")): text "Load more" proc renderNoMore(): VNode = diff --git a/tests/test_timeline.py b/tests/test_timeline.py index 8829735..036452a 100644 --- a/tests/test_timeline.py +++ b/tests/test_timeline.py @@ -8,9 +8,9 @@ after = [['mobile_test', '627635134573862912'], short = [['mobile_test_6'], ['mobile_test_8'], ['picman']] -no_more = [['mobile_test_8?after=159455542543257601']] +no_more = [['mobile_test_8?max_position=159455542543257601']] -none_found = [['mobile_test_8?after=159455542543257600']] +none_found = [['mobile_test_8?max_position=159455542543257600']] empty = [['maybethis'], ['mobile_test_10']] @@ -28,7 +28,7 @@ class TweetTest(BaseTestCase): @parameterized.expand(after) def test_after(self, username, index): - self.open_nitter(f'{username}?after={index}') + self.open_nitter(f'{username}?max_position={index}') self.assert_element_present(Timeline.newest) self.assert_element_present(Timeline.older) self.assert_element_absent(Timeline.end) diff --git a/tests/test_tweet.py b/tests/test_tweet.py index 9c86a74..5b8ed05 100644 --- a/tests/test_tweet.py +++ b/tests/test_tweet.py @@ -81,8 +81,8 @@ retweet = [ ] reply = [ - ['mobile_test?after=471336696307392513', '@mobile_test', '@mobile_test'], - ['mobile_test_2?after=375101899214561280', '@mobile_test_2', '@mobile_test'] + ['mobile_test?max_position=471336696307392513', '@mobile_test', '@mobile_test'], + ['mobile_test_2?max_position=375101899214561280', '@mobile_test_2', '@mobile_test'] ]