From 0c9c37e8862dfdbc26a7ef72c23eff7b1b1e4f83 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 10 Jun 2020 16:13:40 +0200 Subject: [PATCH] Support even more obscure card types --- src/parser.nim | 11 +++++++---- src/parserutils.nim | 4 +++- src/types.nim | 2 ++ src/views/tweet.nim | 6 ++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/parser.nim b/src/parser.nim index 27067eb..a4069b6 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -158,7 +158,7 @@ proc parseBroadcast(js: JsonNode): Card = proc parseCard(js: JsonNode; urls: JsonNode): Card = const imageTypes = ["summary_photo_image", "player_image", "promo_image", "photo_image_full_size", "thumbnail_image", "thumbnail", - "event_thumbnail"] + "event_thumbnail", "image"] let vals = ? js{"binding_values"} name = js{"name"}.getStr @@ -176,7 +176,7 @@ proc parseCard(js: JsonNode; urls: JsonNode): Card = result.url = js{"url"}.getStr case kind - of promoVideo, promoVideoConvo, appPlayer: + of promoVideo, promoVideoConvo, appPlayer, videoDirectMessage: result.video = some parsePromoVideo(vals) if kind == appPlayer: result.text = vals{"app_category"}.getStrVal(result.text) @@ -202,8 +202,11 @@ proc parseCard(js: JsonNode; urls: JsonNode): Card = result.url = u{"expanded_url"}.getStr break - if kind in {promoImageConvo, promoImageApp} and result.url.len == 0 or - result.url.startsWith("card://"): + if kind in {videoDirectMessage, imageDirectMessage}: + result.url.setLen 0 + + if kind in {promoImageConvo, promoImageApp, imageDirectMessage} and + result.url.len == 0 or result.url.startsWith("card://"): result.url = getPicUrl(result.image) proc parseTweet(js: JsonNode): Tweet = diff --git a/src/parserutils.nim b/src/parserutils.nim index 1bb17c9..ba1681f 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -82,8 +82,10 @@ proc getCardTitle*(js: JsonNode; kind: CardKind): string = result = js{"title"}.getStrVal if kind == promoVideoConvo: result = js{"thank_you_text"}.getStrVal(result) - if kind == liveEvent: + elif kind == liveEvent: result = js{"event_category"}.getStrVal + elif kind in {videoDirectMessage, imageDirectMessage}: + result = js{"cta1"}.getStrVal proc getBanner*(js: JsonNode): string = let url = js{"profile_banner_url"}.getImageStr diff --git a/src/types.nim b/src/types.nim index b664fc4..6b17fbd 100644 --- a/src/types.nim +++ b/src/types.nim @@ -119,6 +119,8 @@ type unified = "unified_card" moment = "moment" messageMe = "message_me" + videoDirectMessage = "video_direct_message" + imageDirectMessage = "image_direct_message" Card* = object kind*: CardKind diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 5c0ad32..900d243 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -150,8 +150,10 @@ proc renderCardImage(card: Card): VNode = proc renderCardContent(card: Card): VNode = buildHtml(tdiv(class="card-content")): h2(class="card-title"): text card.title - p(class="card-description"): text card.text - span(class="card-destination"): text card.dest + if card.text.len > 0: + p(class="card-description"): text card.text + if card.dest.len > 0: + span(class="card-destination"): text card.dest proc renderCard(card: Card; prefs: Prefs; path: string): VNode = const smallCards = {app, player, summary, storeLink}