Include retweets in "Tweets & Replies"

This commit is contained in:
Zed 2019-07-04 11:55:19 +02:00
parent 6186ae7a9f
commit 83931e7044
4 changed files with 37 additions and 24 deletions

View File

@ -139,7 +139,7 @@ a:hover {
} }
.replying-to { .replying-to {
color: hsla(240,1%,73%,.7); color: hsla(240,1%,73%,.9);
margin: 4px 0; margin: 4px 0;
} }

View File

@ -45,9 +45,9 @@ routes:
cond '.' notin @"name" cond '.' notin @"name"
respTimeline(await showTimeline(@"name", @"after", none(Query))) respTimeline(await showTimeline(@"name", @"after", none(Query)))
get "/@name/search/?": get "/@name/search":
cond '.' notin @"name" cond '.' notin @"name"
let query = initQuery(@"filter", @"sep", @"name") let query = initQuery(@"filter", @"include", @"not", @"sep", @"name")
respTimeline(await showTimeline(@"name", @"after", some(query))) respTimeline(await showTimeline(@"name", @"after", some(query)))
get "/@name/replies": get "/@name/replies":

View File

@ -5,9 +5,11 @@ import types
const const
separators = @["AND", "OR"] separators = @["AND", "OR"]
validFilters = @[ validFilters = @[
"media", "images", "videos", "native_video", "twimg", "media", "images", "twimg",
"links", "quote", "replies", "mentions", "native_video", "consumer_video", "pro_video",
"news", "verified", "safe" "links", "news", "quote", "mentions",
"replies", "retweets", "nativeretweets",
"verified", "safe"
] ]
# Experimental, this might break in the future # Experimental, this might break in the future
@ -16,25 +18,31 @@ const
posPrefix = "thGAVUV0VFVBa" posPrefix = "thGAVUV0VFVBa"
posSuffix = "EjUAFQAlAFUAFQAA" posSuffix = "EjUAFQAlAFUAFQAA"
proc initQuery*(filter, separator: string; name=""): Query = proc initQuery*(filters, includes, excludes, separator: string; name=""): Query =
var sep = separator.strip().toUpper() var sep = separator.strip().toUpper()
Query( Query(
filter: filter.split(",").filterIt(it in validFilters), queryType: custom,
sep: if sep in separators: sep else: "AND", filters: filters.split(",").filterIt(it in validFilters),
includes: includes.split(",").filterIt(it in validFilters),
excludes: excludes.split(",").filterIt(it in validFilters),
fromUser: name, fromUser: name,
queryType: custom sep: if sep in separators: sep else: ""
) )
proc getMediaQuery*(name: string): Query = proc getMediaQuery*(name: string): Query =
Query( Query(
filter: @["twimg", "native_video"], queryType: media,
sep: "OR", filters: @["twimg", "native_video"],
fromUser: name, fromUser: name,
queryType: media sep: "OR"
) )
proc getReplyQuery*(name: string): Query = proc getReplyQuery*(name: string): Query =
Query(fromUser: name, queryType: replies) Query(
queryType: replies,
includes: @["nativeretweets"],
fromUser: name
)
proc genQueryParam*(query: Query): string = proc genQueryParam*(query: Query): string =
var filters: seq[string] var filters: seq[string]
@ -43,9 +51,11 @@ proc genQueryParam*(query: Query): string =
if query.fromUser.len > 0: if query.fromUser.len > 0:
param = &"from:{query.fromUser} " param = &"from:{query.fromUser} "
for f in query.filter: for f in query.filters:
filters.add "filter:" & f filters.add "filter:" & f
for e in query.exclude: for i in query.includes:
filters.add "include:" & i
for e in query.excludes:
filters.add "-filter:" & e filters.add "-filter:" & e
return strip(param & filters.join(&" {query.sep} ")) return strip(param & filters.join(&" {query.sep} "))
@ -55,10 +65,12 @@ proc genQueryUrl*(query: Query): string =
if query.queryType != custom: return if query.queryType != custom: return
var params: seq[string] var params: seq[string]
if query.filter.len > 0: if query.filters.len > 0:
params &= "filter=" & query.filter.join(",") params &= "filter=" & query.filters.join(",")
if query.exclude.len > 0: if query.includes.len > 0:
params &= "not=" & query.exclude.join(",") params &= "include=" & query.includes.join(",")
if query.excludes.len > 0:
params &= "not=" & query.excludes.join(",")
if query.sep.len > 0: if query.sep.len > 0:
params &= "sep=" & query.sep params &= "sep=" & query.sep
if params.len > 0: if params.len > 0:

View File

@ -35,11 +35,12 @@ type
replies, media, custom = "search" replies, media, custom = "search"
Query* = object Query* = object
filter*: seq[string]
exclude*: seq[string]
sep*: string
fromUser*: string
queryType*: QueryType queryType*: QueryType
filters*: seq[string]
includes*: seq[string]
excludes*: seq[string]
fromUser*: string
sep*: string
VideoType* = enum VideoType* = enum
vmap, m3u8, mp4 vmap, m3u8, mp4