Refactor Thread -> Chain to nimsuggest errors
This commit is contained in:
parent
5ae2e57da8
commit
e6f1e55c15
|
@ -18,7 +18,7 @@ macro genMediaGet(media: untyped; token=false) =
|
||||||
single = ident("get" & mediaName)
|
single = ident("get" & mediaName)
|
||||||
|
|
||||||
quote do:
|
quote do:
|
||||||
proc `multi`*(thread: Thread | Timeline; agent: string; token="") {.async.} =
|
proc `multi`*(thread: Chain | Timeline; agent: string; token="") {.async.} =
|
||||||
if thread == nil: return
|
if thread == nil: return
|
||||||
var `media` = thread.content.filterIt(it.`media`.isSome)
|
var `media` = thread.content.filterIt(it.`media`.isSome)
|
||||||
when `token`:
|
when `token`:
|
||||||
|
|
|
@ -4,7 +4,7 @@ import sequtils, strutils, json, uri
|
||||||
import ".."/[types, parser, parserutils, formatters, query]
|
import ".."/[types, parser, parserutils, formatters, query]
|
||||||
import utils, consts, media, search
|
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),
|
await all(getVideos(thread, agent),
|
||||||
getCards(thread, agent),
|
getCards(thread, agent),
|
||||||
getPolls(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
|
if not json.hasKey("items_html"): return
|
||||||
|
|
||||||
let html = parseHtml(json["items_html"].to(string))
|
let html = parseHtml(json["items_html"].to(string))
|
||||||
let thread = parseThread(html)
|
let thread = parseChain(html)
|
||||||
|
|
||||||
await getMedia(thread, agent)
|
await getMedia(thread, agent)
|
||||||
result.content = thread.content
|
result.content = thread.content
|
||||||
|
|
|
@ -132,9 +132,9 @@ proc parseTweet*(node: XmlNode): Tweet =
|
||||||
let quote = Quote(tombstone: getTombstone(node.selectText(".Tombstone-label")))
|
let quote = Quote(tombstone: getTombstone(node.selectText(".Tombstone-label")))
|
||||||
result.quote = some quote
|
result.quote = some quote
|
||||||
|
|
||||||
proc parseThread*(nodes: XmlNode): Thread =
|
proc parseChain*(nodes: XmlNode): Chain =
|
||||||
if nodes == nil: return
|
if nodes == nil: return
|
||||||
result = Thread()
|
result = Chain()
|
||||||
for n in nodes.filterIt(it.kind != xnText):
|
for n in nodes.filterIt(it.kind != xnText):
|
||||||
let class = n.attr("class").toLower()
|
let class = n.attr("class").toLower()
|
||||||
if "tombstone" in class or "unavailable" in class or "withheld" in class:
|
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(
|
result = Conversation(
|
||||||
tweet: parseTweet(tweet),
|
tweet: parseTweet(tweet),
|
||||||
before: parseThread(node.select(".in-reply-to .stream-items")),
|
before: parseChain(node.select(".in-reply-to .stream-items")),
|
||||||
replies: Result[Thread](
|
replies: Result[Chain](
|
||||||
minId: node.selectAttr(".replies-to .stream-container", "data-min-position"),
|
minId: node.selectAttr(".replies-to .stream-container", "data-min-position"),
|
||||||
hasMore: node.select(".stream-footer .has-more-items") != nil,
|
hasMore: node.select(".stream-footer .has-more-items") != nil,
|
||||||
beginning: after.len == 0
|
beginning: after.len == 0
|
||||||
|
@ -175,16 +175,16 @@ proc parseConversation*(node: XmlNode; after: string): Conversation =
|
||||||
let thread = reply.select(".stream-items")
|
let thread = reply.select(".stream-items")
|
||||||
|
|
||||||
if i == 0 and "self" in class:
|
if i == 0 and "self" in class:
|
||||||
result.after = parseThread(thread)
|
result.after = parseChain(thread)
|
||||||
elif "lone" in class:
|
elif "lone" in class:
|
||||||
result.replies.content.add parseThread(reply)
|
result.replies.content.add parseChain(reply)
|
||||||
else:
|
else:
|
||||||
result.replies.content.add parseThread(thread)
|
result.replies.content.add parseChain(thread)
|
||||||
|
|
||||||
proc parseTimeline*(node: XmlNode; after: string): Timeline =
|
proc parseTimeline*(node: XmlNode; after: string): Timeline =
|
||||||
if node == nil: return Timeline()
|
if node == nil: return Timeline()
|
||||||
result = 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"),
|
minId: node.attr("data-min-position"),
|
||||||
maxId: node.attr("data-max-position"),
|
maxId: node.attr("data-max-position"),
|
||||||
hasMore: node.select(".has-more-items") != nil,
|
hasMore: node.select(".has-more-items") != nil,
|
||||||
|
|
|
@ -156,15 +156,15 @@ type
|
||||||
photos*: seq[string]
|
photos*: seq[string]
|
||||||
poll*: Option[Poll]
|
poll*: Option[Poll]
|
||||||
|
|
||||||
Thread* = ref object
|
Chain* = ref object
|
||||||
content*: seq[Tweet]
|
content*: seq[Tweet]
|
||||||
more*: int
|
more*: int
|
||||||
|
|
||||||
Conversation* = ref object
|
Conversation* = ref object
|
||||||
tweet*: Tweet
|
tweet*: Tweet
|
||||||
before*: Thread
|
before*: Chain
|
||||||
after*: Thread
|
after*: Chain
|
||||||
replies*: Result[Thread]
|
replies*: Result[Chain]
|
||||||
|
|
||||||
Timeline* = Result[Tweet]
|
Timeline* = Result[Tweet]
|
||||||
|
|
||||||
|
@ -177,5 +177,5 @@ type
|
||||||
cacheDir*: string
|
cacheDir*: string
|
||||||
profileCacheTime*: int
|
profileCacheTime*: int
|
||||||
|
|
||||||
proc contains*(thread: Thread; tweet: Tweet): bool =
|
proc contains*(thread: Chain; tweet: Tweet): bool =
|
||||||
thread.content.anyIt(it.id == tweet.id)
|
thread.content.anyIt(it.id == tweet.id)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import karax/[karaxdsl, vdom]
|
||||||
import ".."/[types, formatters]
|
import ".."/[types, formatters]
|
||||||
import tweet, timeline
|
import tweet, timeline
|
||||||
|
|
||||||
proc renderMoreReplies(thread: Thread): VNode =
|
proc renderMoreReplies(thread: Chain): VNode =
|
||||||
let num = if thread.more != -1: $thread.more & " " else: ""
|
let num = if thread.more != -1: $thread.more & " " else: ""
|
||||||
let reply = if thread.more == 1: "reply" else: "replies"
|
let reply = if thread.more == 1: "reply" else: "replies"
|
||||||
let link = getLink(thread.content[^1])
|
let link = getLink(thread.content[^1])
|
||||||
|
@ -15,7 +15,7 @@ proc renderMoreReplies(thread: Thread): VNode =
|
||||||
a(class="more-replies-text"):
|
a(class="more-replies-text"):
|
||||||
text $num & "more " & reply
|
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")):
|
buildHtml(tdiv(class="reply thread thread-line")):
|
||||||
for i, tweet in thread.content:
|
for i, tweet in thread.content:
|
||||||
let last = (i == thread.content.high and thread.more == 0)
|
let last = (i == thread.content.high and thread.more == 0)
|
||||||
|
|
Loading…
Reference in New Issue