Use "max_position" instead of "after" for compat
This commit is contained in:
parent
381a8a106c
commit
211b086f4d
10 changed files with 17 additions and 40 deletions
|
@ -9,7 +9,7 @@ proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] =
|
||||||
Result[T](
|
Result[T](
|
||||||
hasMore: json{"has_more_items"}.getBool(false),
|
hasMore: json{"has_more_items"}.getBool(false),
|
||||||
maxId: json{"max_position"}.getStr(""),
|
maxId: json{"max_position"}.getStr(""),
|
||||||
minId: json{"min_position"}.getStr("").cleanPos(),
|
minId: json{"min_position"}.getStr(""),
|
||||||
query: query,
|
query: query,
|
||||||
beginning: after.len == 0
|
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.} =
|
proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.async.} =
|
||||||
let
|
let
|
||||||
kind = if query.kind == users: "users" else: "tweets"
|
kind = if query.kind == users: "users" else: "tweets"
|
||||||
pos = when T is Tweet: genPos(after) else: after
|
|
||||||
|
|
||||||
param = genQueryParam(query)
|
param = genQueryParam(query)
|
||||||
encoded = encodeUrl(param, usePlus=false)
|
encoded = encodeUrl(param, usePlus=false)
|
||||||
|
@ -32,7 +31,7 @@ proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.asyn
|
||||||
"src": "typd",
|
"src": "typd",
|
||||||
"include_available_features": "1",
|
"include_available_features": "1",
|
||||||
"include_entities": "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"
|
"reset_error_state": "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,21 +146,14 @@ proc getTwitterLink*(path: string; params: Table[string, string]): string =
|
||||||
username = params.getOrDefault("name")
|
username = params.getOrDefault("name")
|
||||||
query = initQuery(params, username)
|
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:
|
if "/search" notin path:
|
||||||
return $(twitter / path ? paramList)
|
return $(twitter / path ? filterParams(params))
|
||||||
|
|
||||||
let p = {
|
let p = {
|
||||||
"f": $query.kind,
|
"f": $query.kind,
|
||||||
"q": genQueryParam(query),
|
"q": genQueryParam(query),
|
||||||
"src": "typd",
|
"src": "typd",
|
||||||
"max_position": after
|
"max_position": params.getOrDefault("max_position", "0")
|
||||||
}
|
}
|
||||||
|
|
||||||
result = $(parseUri("https://twitter.com") / path ? p)
|
result = $(parseUri("https://twitter.com") / path ? p)
|
||||||
|
|
|
@ -12,12 +12,6 @@ const
|
||||||
"verified", "safe"
|
"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 =
|
template `@`(param: string): untyped =
|
||||||
if param in pms: pms[param]
|
if param in pms: pms[param]
|
||||||
else: ""
|
else: ""
|
||||||
|
@ -105,12 +99,3 @@ proc genQueryUrl*(query: Query): string =
|
||||||
|
|
||||||
if params.len > 0:
|
if params.len > 0:
|
||||||
result &= params.join("&")
|
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
|
|
||||||
|
|
|
@ -18,17 +18,17 @@ proc createListRouter*(cfg: Config) =
|
||||||
get "/@name/lists/@list":
|
get "/@name/lists/@list":
|
||||||
cond '.' notin @"name"
|
cond '.' notin @"name"
|
||||||
let
|
let
|
||||||
list = await getListTimeline(@"name", @"list", getAgent(), @"after")
|
list = await getListTimeline(@"name", @"list", getAgent(), @"max_position")
|
||||||
tweets = renderTimelineTweets(list, cookiePrefs(), request.path)
|
tweets = renderTimelineTweets(list, cookiePrefs(), request.path)
|
||||||
respList list, tweets
|
respList list, tweets
|
||||||
|
|
||||||
get "/@name/lists/@list/members":
|
get "/@name/lists/@list/members":
|
||||||
cond '.' notin @"name"
|
cond '.' notin @"name"
|
||||||
let list =
|
let list =
|
||||||
if @"after".len == 0:
|
if @"max_position".len == 0:
|
||||||
await getListMembers(@"name", @"list", getAgent())
|
await getListMembers(@"name", @"list", getAgent())
|
||||||
else:
|
else:
|
||||||
await getListMembersSearch(@"name", @"list", getAgent(), @"after")
|
await getListMembersSearch(@"name", @"list", getAgent(), @"max_position")
|
||||||
|
|
||||||
let users = renderTimelineUsers(list, cookiePrefs(), request.path)
|
let users = renderTimelineUsers(list, cookiePrefs(), request.path)
|
||||||
respList list, users
|
respList list, users
|
||||||
|
|
|
@ -21,10 +21,10 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
of users:
|
of users:
|
||||||
if "," in @"q":
|
if "," in @"q":
|
||||||
redirect("/" & @"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)
|
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
|
||||||
of tweets:
|
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)
|
let rss = "/search/rss?" & genQueryUrl(query)
|
||||||
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,
|
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,
|
||||||
cfg.title, rss=rss)
|
cfg.title, rss=rss)
|
||||||
|
|
|
@ -17,7 +17,7 @@ proc createStatusRouter*(cfg: Config) =
|
||||||
cond '.' notin @"name"
|
cond '.' notin @"name"
|
||||||
let prefs = cookiePrefs()
|
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:
|
if conversation == nil or conversation.tweet.id.len == 0:
|
||||||
var error = "Tweet not found"
|
var error = "Tweet not found"
|
||||||
if conversation != nil and conversation.tweet.tombstone.len > 0:
|
if conversation != nil and conversation.tweet.tombstone.len > 0:
|
||||||
|
|
|
@ -56,7 +56,7 @@ proc showTimeline*(request: Request; query: Query; title, rss: string): Future[s
|
||||||
agent = getAgent()
|
agent = getAgent()
|
||||||
prefs = cookiePrefs()
|
prefs = cookiePrefs()
|
||||||
name = request.get("name")
|
name = request.get("name")
|
||||||
after = request.get("after")
|
after = request.get("max_position")
|
||||||
names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||||
|
|
||||||
if names.len == 1:
|
if names.len == 1:
|
||||||
|
|
|
@ -19,7 +19,7 @@ proc renderNewer*(query: Query; path: string): VNode =
|
||||||
|
|
||||||
proc renderMore*(query: Query; minId: string): VNode =
|
proc renderMore*(query: Query; minId: string): VNode =
|
||||||
buildHtml(tdiv(class="show-more")):
|
buildHtml(tdiv(class="show-more")):
|
||||||
a(href=(&"?{getQuery(query)}after={minId}")):
|
a(href=(&"?{getQuery(query)}max_position={minId}")):
|
||||||
text "Load more"
|
text "Load more"
|
||||||
|
|
||||||
proc renderNoMore(): VNode =
|
proc renderNoMore(): VNode =
|
||||||
|
|
|
@ -8,9 +8,9 @@ after = [['mobile_test', '627635134573862912'],
|
||||||
|
|
||||||
short = [['mobile_test_6'], ['mobile_test_8'], ['picman']]
|
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']]
|
empty = [['maybethis'], ['mobile_test_10']]
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class TweetTest(BaseTestCase):
|
||||||
|
|
||||||
@parameterized.expand(after)
|
@parameterized.expand(after)
|
||||||
def test_after(self, username, index):
|
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.newest)
|
||||||
self.assert_element_present(Timeline.older)
|
self.assert_element_present(Timeline.older)
|
||||||
self.assert_element_absent(Timeline.end)
|
self.assert_element_absent(Timeline.end)
|
||||||
|
|
|
@ -81,8 +81,8 @@ retweet = [
|
||||||
]
|
]
|
||||||
|
|
||||||
reply = [
|
reply = [
|
||||||
['mobile_test?after=471336696307392513', '@mobile_test', '@mobile_test'],
|
['mobile_test?max_position=471336696307392513', '@mobile_test', '@mobile_test'],
|
||||||
['mobile_test_2?after=375101899214561280', '@mobile_test_2', '@mobile_test']
|
['mobile_test_2?max_position=375101899214561280', '@mobile_test_2', '@mobile_test']
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue