From cd290cf2e806152fb69a1dd8c6c5ef4d58d19cd1 Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Sat, 19 Oct 2024 14:59:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Inline=20rendering=20into=20`Not?= =?UTF-8?q?ification`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bot.rs | 1 - src/telegram/notification.rs | 23 +++++++++++++++++++++-- src/telegram/render.rs | 32 +------------------------------- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 64c2239..87b66d1 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -53,7 +53,6 @@ impl Bot { .await?; for update in updates { - info!(update.id, "Received update"); self.offset.store(update.id + 1, Ordering::Relaxed); self.on_update(update).await?; } diff --git a/src/telegram/notification.rs b/src/telegram/notification.rs index 6b7072a..bccbaac 100644 --- a/src/telegram/notification.rs +++ b/src/telegram/notification.rs @@ -1,7 +1,7 @@ use std::{collections::VecDeque, iter::once}; use bon::bon; -use maud::Render; +use maud::{Render, html}; use crate::{ marktplaats::listing::Listing, @@ -45,7 +45,26 @@ impl<'a> Notification<'a> { #[builder(into)] chat_id: ChatId, reply_parameters: Option, ) -> Self { - let html = listing.render().into_string(); + let html = { + let markup = html! { + strong { a href=(listing.https_url()) { (listing.title) } } + "\n\n" + (listing.price) + @for attribute in &listing.attributes { + (attribute) + } + "\n\n" + blockquote expandable { (listing.description()) } + "\n\n" + (listing.seller) + @if listing.location.city_name.is_some() { + strong { " • " } + (listing.location) + } + }; + markup.render().into_string() + }; + let mut image_urls: VecDeque<&str> = listing .pictures .iter() diff --git a/src/telegram/render.rs b/src/telegram/render.rs index 8811510..60f2bba 100644 --- a/src/telegram/render.rs +++ b/src/telegram/render.rs @@ -5,37 +5,7 @@ use std::borrow::Cow; use maud::{Markup, Render, html}; use url::Url; -use crate::marktplaats::listing::{ - Attribute, - Condition, - Delivery, - Euro, - Listing, - Location, - Price, - Seller, -}; - -impl Render for Listing { - fn render(&self) -> Markup { - html! { - strong { a href=(self.https_url()) { (self.title) } } - "\n\n" - (self.price) - @for attribute in &self.attributes { - (attribute) - } - "\n\n" - blockquote expandable { (self.description()) } - "\n\n" - (self.seller) - @if self.location.city_name.is_some() { - strong { " • " } - (self.location) - } - } - } -} +use crate::marktplaats::listing::{Attribute, Condition, Delivery, Euro, Location, Price, Seller}; impl Render for Price { fn render(&self) -> Markup {