Skip to content

Commit

Permalink
🚧 Inline rendering into Notification
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Oct 19, 2024
1 parent 29aed73 commit cd290cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
Expand Down
23 changes: 21 additions & 2 deletions src/telegram/notification.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -45,7 +45,26 @@ impl<'a> Notification<'a> {
#[builder(into)] chat_id: ChatId,
reply_parameters: Option<ReplyParameters>,
) -> 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()
Expand Down
32 changes: 1 addition & 31 deletions src/telegram/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cd290cf

Please sign in to comment.