From 7c35875fbfb00dd4782445b9fbf709bd181654c3 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 4 Dec 2019 05:58:18 +0100 Subject: [PATCH] Support RSS for multi-timelines --- src/routes/router_utils.nim | 4 ++++ src/routes/rss.nim | 18 +++++++++++++++--- src/routes/timeline.nim | 10 +++++----- src/views/rss.nimf | 12 ++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/routes/router_utils.nim b/src/routes/router_utils.nim index 2aedd6c..0aa46b4 100644 --- a/src/routes/router_utils.nim +++ b/src/routes/router_utils.nim @@ -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) diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 74b91c6..324c311 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -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: diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index 084817f..3b6b954 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -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)) diff --git a/src/views/rss.nimf b/src/views/rss.nimf index c7feabc..d425bc5 100644 --- a/src/views/rss.nimf +++ b/src/views/rss.nimf @@ -56,20 +56,24 @@ #end for #end proc # -#proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string): string = +#proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string; multi=false): string = #let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us") #result = "" +#let user = (if multi: "" else: "@") & profile.username +#var title = profile.fullname +#if not multi: title &= " / " & user +#end if - ${profile.fullname} / @${profile.username} + ${title} https://${hostname}/${profile.username} - Twitter feed for: @${profile.username}. Generated by ${hostname} + Twitter feed for: ${user}. Generated by ${hostname} en-us 40 - ${profile.fullname} / @${profile.username} + ${title} https://${hostname}/${profile.username} https://${hostname}${getPicUrl(profile.getUserPic(style="_400x400"))} 128