Support RSS for multi-timelines

This commit is contained in:
Zed
2019-12-04 05:58:18 +01:00
parent fba7ed2a19
commit 7c35875fbf
4 changed files with 32 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import strutils, sequtils
import ../utils, ../prefs
export utils, prefs
@@ -9,3 +10,6 @@ template getPath*(): untyped {.dirty.} =
template refPath*(): untyped {.dirty.} =
if @"referer".len > 0: @"referer" else: "/"
proc getNames*(name: string): seq[string] =
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)

View File

@@ -9,11 +9,23 @@ import ../views/general
include "../views/rss.nimf"
proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
let (profile, timeline) =
await fetchSingleTimeline(name, "", getAgent(), query, media=false)
var profile: Profile
var timeline: Timeline
let names = getNames(name)
if names.len == 1:
(profile, timeline) =
await fetchSingleTimeline(names[0], "", getAgent(), query, media=false)
else:
timeline = await fetchMultiTimeline(names, "", getAgent(), query, media=false)
# this is kinda dumb
profile = Profile(
username: name,
fullname: names.join(" | "),
userpic: "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
)
if timeline != nil:
return renderTimelineRss(timeline, profile, hostname)
return renderTimelineRss(timeline, profile, hostname, multi=(names.len > 1))
template respRss*(rss: typed) =
if rss.len == 0:

View File

@@ -38,13 +38,13 @@ proc fetchSingleTimeline*(name, after, agent: string; query: Query;
if profile.username.len == 0: return
return (profile, timeline)
proc fetchMultiTimeline*(names: seq[string]; after, agent: string;
query: Query): Future[Timeline] {.async.} =
proc fetchMultiTimeline*(names: seq[string]; after, agent: string; query: Query;
media=true): Future[Timeline] {.async.} =
var q = query
q.fromUser = names
if q.kind == posts and "replies" notin q.excludes:
q.excludes.add "replies"
return await getSearch[Tweet](q, after, agent)
return await getSearch[Tweet](q, after, agent, media)
proc get*(req: Request; key: string): string =
if key in params(req): params(req)[key]
@@ -56,13 +56,13 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; rss: string): Fu
prefs = cookiePrefs()
name = request.get("name")
after = request.get("max_position")
names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
names = getNames(name)
if names.len != 1:
let
timeline = await fetchMultiTimeline(names, after, agent, query)
html = renderTweetSearch(timeline, prefs, getPath())
return renderMain(html, request, cfg, "Multi")
return renderMain(html, request, cfg, "Multi", rss=rss)
let
rail = getPhotoRail(names[0], agent, skip=(query.kind == media))