Skip search requests when query is empty

This commit is contained in:
Zed 2021-12-28 07:25:37 +01:00
parent 1e1e034237
commit aa2fed19d7
2 changed files with 12 additions and 5 deletions

View File

@ -67,11 +67,16 @@ proc getSearch*[T](query: Query; after=""): Future[Result[T]] {.async.} =
searchMode = ("tweet_search_mode", "live")
parse = parseTimeline
let
q = genQueryParam(query)
url = search ? genParams(searchParams & @[("q", q), searchMode], after)
result = parse(await fetch(url), after)
result.query = query
let q = genQueryParam(query)
if q.len == 0 or q == emptyQuery:
return Result[T](beginning: true, query: query)
let url = search ? genParams(searchParams & @[("q", q), searchMode], after)
try:
result = parse(await fetch(url), after)
result.query = query
except InternalError:
return Result[T](beginning: true, query: query)
proc getTweetImpl(id: string; after=""): Future[Conversation] {.async.} =
let url = tweet / (id & ".json") ? genParams(cursor=after)

View File

@ -12,6 +12,8 @@ const
"verified", "safe"
]
emptyQuery* = "include:nativeretweets"
template `@`(param: string): untyped =
if param in pms: pms[param]
else: ""