Always show retweets unless excluded in search

This commit is contained in:
Zed 2020-06-17 14:12:38 +02:00
parent 0e58c36bae
commit 33f0ab0ba5
4 changed files with 9 additions and 16 deletions

View File

@ -3,7 +3,6 @@ import strutils, strformat, sequtils, tables, uri
import types
const
# separators = @["AND", "OR"]
validFilters* = @[
"media", "images", "twimg", "videos",
"native_video", "consumer_video", "pro_video",
@ -30,9 +29,6 @@ proc initQuery*(pms: Table[string, string]; name=""): Query =
if name.len > 0:
result.fromUser = name.split(",")
if @"e-nativeretweets".len == 0:
result.includes.add "nativeretweets"
proc getMediaQuery*(name: string): Query =
Query(
kind: media,
@ -44,11 +40,10 @@ proc getMediaQuery*(name: string): Query =
proc getReplyQuery*(name: string): Query =
Query(
kind: replies,
includes: @["nativeretweets"],
fromUser: @[name]
)
proc genQueryParam*(query: Query; rewriteReplies=true): string =
proc genQueryParam*(query: Query): string =
var
filters: seq[string]
param: string
@ -68,6 +63,9 @@ proc genQueryParam*(query: Query; rewriteReplies=true): string =
if i < query.fromUser.high:
param &= "OR "
if "nativeretweets" notin query.excludes:
param &= "include:nativeretweets "
for f in query.filters:
filters.add "filter:" & f
for e in query.excludes:

View File

@ -21,8 +21,9 @@ proc showRss*(req: Request; hostname: string; query: Query): Future[Rss] {.async
(profile, timeline) =
await fetchSingleTimeline(after, query, skipRail=true)
else:
let multiQuery = query.getMultiQuery(names)
timeline = await getSearch[Tweet](multiQuery, after)
var q = query
q.fromUser = names
timeline = await getSearch[Tweet](q, after)
# this is kinda dumb
profile = Profile(
username: name,

View File

@ -13,7 +13,7 @@ export search
proc createSearchRouter*(cfg: Config) =
router search:
get "/search/?":
if @"q".len > 200:
if @"q".len > 500:
resp Http400, showError("Search input too long.", cfg)
let

View File

@ -73,12 +73,6 @@ proc fetchSingleTimeline*(after: string; query: Query; skipRail=false):
return (profile, timeline, await rail)
proc getMultiQuery*(q: Query; names: seq[string]): Query =
result = q
result.fromUser = names
if q.kind == posts and "replies" notin q.excludes:
result.excludes.add "replies"
proc get*(req: Request; key: string): string =
params(req).getOrDefault(key)
@ -118,7 +112,7 @@ proc createTimelineRouter*(cfg: Config) =
var query = request.getQuery(@"tab", @"name")
if names.len != 1:
query = query.getMultiQuery(names)
query.fromUser = names
if @"scroll".len > 0:
if query.fromUser.len != 1: