Refactor Thread -> Chain to nimsuggest errors

This commit is contained in:
Zed 2019-10-08 20:47:45 +02:00
parent 5ae2e57da8
commit e6f1e55c15
5 changed files with 18 additions and 18 deletions

View file

@ -18,7 +18,7 @@ macro genMediaGet(media: untyped; token=false) =
single = ident("get" & mediaName)
quote do:
proc `multi`*(thread: Thread | Timeline; agent: string; token="") {.async.} =
proc `multi`*(thread: Chain | Timeline; agent: string; token="") {.async.} =
if thread == nil: return
var `media` = thread.content.filterIt(it.`media`.isSome)
when `token`:

View file

@ -4,7 +4,7 @@ import sequtils, strutils, json, uri
import ".."/[types, parser, parserutils, formatters, query]
import utils, consts, media, search
proc getMedia(thread: Thread | Timeline; agent: string) {.async.} =
proc getMedia(thread: Chain | Timeline; agent: string) {.async.} =
await all(getVideos(thread, agent),
getCards(thread, agent),
getPolls(thread, agent))
@ -17,7 +17,7 @@ proc finishTimeline*(json: JsonNode; query: Query; after, agent: string): Future
if not json.hasKey("items_html"): return
let html = parseHtml(json["items_html"].to(string))
let thread = parseThread(html)
let thread = parseChain(html)
await getMedia(thread, agent)
result.content = thread.content

View file

@ -132,9 +132,9 @@ proc parseTweet*(node: XmlNode): Tweet =
let quote = Quote(tombstone: getTombstone(node.selectText(".Tombstone-label")))
result.quote = some quote
proc parseThread*(nodes: XmlNode): Thread =
proc parseChain*(nodes: XmlNode): Chain =
if nodes == nil: return
result = Thread()
result = Chain()
for n in nodes.filterIt(it.kind != xnText):
let class = n.attr("class").toLower()
if "tombstone" in class or "unavailable" in class or "withheld" in class:
@ -152,8 +152,8 @@ proc parseConversation*(node: XmlNode; after: string): Conversation =
result = Conversation(
tweet: parseTweet(tweet),
before: parseThread(node.select(".in-reply-to .stream-items")),
replies: Result[Thread](
before: parseChain(node.select(".in-reply-to .stream-items")),
replies: Result[Chain](
minId: node.selectAttr(".replies-to .stream-container", "data-min-position"),
hasMore: node.select(".stream-footer .has-more-items") != nil,
beginning: after.len == 0
@ -175,16 +175,16 @@ proc parseConversation*(node: XmlNode; after: string): Conversation =
let thread = reply.select(".stream-items")
if i == 0 and "self" in class:
result.after = parseThread(thread)
result.after = parseChain(thread)
elif "lone" in class:
result.replies.content.add parseThread(reply)
result.replies.content.add parseChain(reply)
else:
result.replies.content.add parseThread(thread)
result.replies.content.add parseChain(thread)
proc parseTimeline*(node: XmlNode; after: string): Timeline =
if node == nil: return Timeline()
result = Timeline(
content: parseThread(node.select(".stream > .stream-items")).content,
content: parseChain(node.select(".stream > .stream-items")).content,
minId: node.attr("data-min-position"),
maxId: node.attr("data-max-position"),
hasMore: node.select(".has-more-items") != nil,

View file

@ -156,15 +156,15 @@ type
photos*: seq[string]
poll*: Option[Poll]
Thread* = ref object
Chain* = ref object
content*: seq[Tweet]
more*: int
Conversation* = ref object
tweet*: Tweet
before*: Thread
after*: Thread
replies*: Result[Thread]
before*: Chain
after*: Chain
replies*: Result[Chain]
Timeline* = Result[Tweet]
@ -177,5 +177,5 @@ type
cacheDir*: string
profileCacheTime*: int
proc contains*(thread: Thread; tweet: Tweet): bool =
proc contains*(thread: Chain; tweet: Tweet): bool =
thread.content.anyIt(it.id == tweet.id)

View file

@ -3,7 +3,7 @@ import karax/[karaxdsl, vdom]
import ".."/[types, formatters]
import tweet, timeline
proc renderMoreReplies(thread: Thread): VNode =
proc renderMoreReplies(thread: Chain): VNode =
let num = if thread.more != -1: $thread.more & " " else: ""
let reply = if thread.more == 1: "reply" else: "replies"
let link = getLink(thread.content[^1])
@ -15,7 +15,7 @@ proc renderMoreReplies(thread: Thread): VNode =
a(class="more-replies-text"):
text $num & "more " & reply
proc renderReplyThread(thread: Thread; prefs: Prefs; path: string): VNode =
proc renderReplyThread(thread: Chain; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="reply thread thread-line")):
for i, tweet in thread.content:
let last = (i == thread.content.high and thread.more == 0)