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

View file

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