From e6f1e55c150430a7f0b7b22d6d0f9cce06bcd339 Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 8 Oct 2019 20:47:45 +0200 Subject: [PATCH] Refactor Thread -> Chain to nimsuggest errors --- src/api/media.nim | 2 +- src/api/timeline.nim | 4 ++-- src/parser.nim | 16 ++++++++-------- src/types.nim | 10 +++++----- src/views/status.nim | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/api/media.nim b/src/api/media.nim index cdc4af6..e3e5267 100644 --- a/src/api/media.nim +++ b/src/api/media.nim @@ -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`: diff --git a/src/api/timeline.nim b/src/api/timeline.nim index 9f167d0..bed761a 100644 --- a/src/api/timeline.nim +++ b/src/api/timeline.nim @@ -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 diff --git a/src/parser.nim b/src/parser.nim index ffca991..7263452 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -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, diff --git a/src/types.nim b/src/types.nim index d23f76d..3fb362e 100644 --- a/src/types.nim +++ b/src/types.nim @@ -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) diff --git a/src/views/status.nim b/src/views/status.nim index 048908a..821fb76 100644 --- a/src/views/status.nim +++ b/src/views/status.nim @@ -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)