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))

View File

@ -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
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<atom:link href="https://${hostname}/${profile.username}/rss" rel="self" type="application/rss+xml" />
<title>${profile.fullname} / @${profile.username}</title>
<title>${title}</title>
<link>https://${hostname}/${profile.username}</link>
<description>Twitter feed for: @${profile.username}. Generated by ${hostname}</description>
<description>Twitter feed for: ${user}. Generated by ${hostname}</description>
<language>en-us</language>
<ttl>40</ttl>
<image>
<title>${profile.fullname} / @${profile.username}</title>
<title>${title}</title>
<link>https://${hostname}/${profile.username}</link>
<url>https://${hostname}${getPicUrl(profile.getUserPic(style="_400x400"))}</url>
<width>128</width>