Fix multi-timeline infinite scroll, minor refactor

This commit is contained in:
Zed 2020-05-02 19:22:43 +02:00
parent 4c35d0b723
commit 9197c686d3
3 changed files with 33 additions and 26 deletions

View File

@ -18,9 +18,9 @@ proc createListRouter*(cfg: Config) =
get "/@name/lists/@list":
cond '.' notin @"name"
let list = await getListTimeline(@"name", @"list", @"max_position", getAgent())
respList list, renderTimelineTweets(list, cookiePrefs(), request.path)
respList(list, renderTimelineTweets(list, cookiePrefs(), request.path))
get "/@name/lists/@list/members":
cond '.' notin @"name"
let list = await getListMembers(@"name", @"list", @"max_position", getAgent())
respList list, renderTimelineUsers(list, cookiePrefs(), request.path)
respList(list, renderTimelineUsers(list, cookiePrefs(), request.path))

View File

@ -18,7 +18,7 @@ proc showRss*(req: Request; hostname: string; query: Query): Future[(string, str
if names.len == 1:
(profile, timeline) =
await fetchSingleTimeline(names[0], after, getAgent(), query, media=false)
await fetchSingleTimeline(after, getAgent(), query, media=false)
else:
let multiQuery = query.getMultiQuery(names)
timeline = await getSearch[Tweet](multiQuery, after, getAgent(), media=false)
@ -60,18 +60,19 @@ proc createRssRouter*(cfg: Config) =
get "/@name/rss":
cond '.' notin @"name"
let (rss, minId) = await showRss(request, cfg.hostname, Query())
let (rss, minId) = await showRss(request, cfg.hostname, Query(fromUser: @[@"name"]))
respRss(rss, minId)
get "/@name/@tab/rss":
cond '.' notin @"name"
cond @"tab" in ["with_replies", "media", "search"]
let name = @"name"
let query =
case @"tab"
of "with_replies": getReplyQuery(@"name")
of "media": getMediaQuery(@"name")
of "search": initQuery(params(request), name=(@"name"))
else: Query()
of "with_replies": getReplyQuery(name)
of "media": getMediaQuery(name)
of "search": initQuery(params(request), name=name)
else: Query(fromUser: @[name])
let (rss, minId) = await showRss(request, cfg.hostname, query)
respRss(rss, minId)

View File

@ -16,16 +16,17 @@ proc getQuery*(request: Request; tab, name: string): Query =
of "with_replies": getReplyQuery(name)
of "media": getMediaQuery(name)
of "search": initQuery(params(request), name=name)
else: Query()
else: Query(fromUser: @[name])
proc fetchTimeline*(name, after, agent: string; query: Query): Future[Timeline] =
proc fetchTimeline*(after, agent: string; query: Query): Future[Timeline] =
case query.kind
of QueryKind.media: getMediaTimeline(name, after, agent)
of posts: getTimeline(name, after, agent)
of QueryKind.media: getMediaTimeline(query.fromUser[0], after, agent)
of posts: getTimeline(query.fromUser[0], after, agent)
else: getSearch[Tweet](query, after, agent)
proc fetchSingleTimeline*(name, after, agent: string; query: Query;
proc fetchSingleTimeline*(after, agent: string; query: Query;
media=true): Future[(Profile, Timeline)] {.async.} =
let name = query.fromUser[0]
var timeline: Timeline
var profile: Profile
var cachedProfile = hasCachedProfile(name)
@ -37,7 +38,7 @@ proc fetchSingleTimeline*(name, after, agent: string; query: Query;
(profile, timeline) = await getProfileAndTimeline(name, after, agent, media)
cache(profile)
else:
let timelineFut = fetchTimeline(name, after, agent, query)
let timelineFut = fetchTimeline(after, agent, query)
if cachedProfile.isNone:
profile = await getCachedProfile(name, agent)
timeline = await timelineFut
@ -57,18 +58,16 @@ proc get*(req: Request; key: string): string =
proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
rss, after: string): Future[string] {.async.} =
let agent = getAgent()
let names = getNames(request.get("name"))
if names.len != 1:
if query.fromUser.len != 1:
let
multiQuery = query.getMultiQuery(names)
timeline = await getSearch[Tweet](multiQuery, after, agent)
timeline = await getSearch[Tweet](query, after, agent)
html = renderTweetSearch(timeline, prefs, getPath())
return renderMain(html, request, cfg, "Multi", rss=rss)
let
rail = getPhotoRail(names[0], agent, skip=(query.kind == media))
(p, t) = await fetchSingleTimeline(names[0], after, agent, query)
rail = getPhotoRail(query.fromUser[0], agent, skip=(query.kind == media))
(p, t) = await fetchSingleTimeline(after, agent, query)
r = await rail
if p.username.len == 0: return
if p.suspended:
@ -83,10 +82,6 @@ template respTimeline*(timeline: typed) =
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
resp timeline
template respScroll*(timeline: typed) =
timeline.beginning = true # don't render "load newest"
resp $renderTimelineTweets(timeline, prefs, getPath())
proc createTimelineRouter*(cfg: Config) =
setProfileCacheTime(cfg.profileCacheTime)
@ -97,10 +92,21 @@ proc createTimelineRouter*(cfg: Config) =
let
prefs = cookiePrefs()
after = @"max_position"
query = request.getQuery(@"tab", @"name")
names = getNames(@"name")
var query = request.getQuery(@"tab", @"name")
if names.len != 1:
query = query.getMultiQuery(names)
if @"scroll".len > 0:
respScroll(await fetchTimeline(@"name", after, getAgent(), query))
if query.fromUser.len != 1:
let timeline = await getSearch[Tweet](query, after, getAgent())
timeline.beginning = true
resp $renderTweetSearch(timeline, prefs, getPath())
else:
let timeline = await fetchTimeline(after, getAgent(), query)
timeline.beginning = true
resp $renderTimelineTweets(timeline, prefs, getPath())
var rss = "/$1/$2/rss" % [@"name", @"tab"]
if @"tab".len == 0: