From: Simon Tatham Date: Thu, 4 Jan 2024 07:38:26 +0000 (+0000) Subject: Move some code into an InReplyToLine::from_id constructor. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=c9978f81582d19e30e5567237c8912b80867f57f;p=mastodonochrome.git Move some code into an InReplyToLine::from_id constructor. That will make it easier to reuse later. --- diff --git a/src/text.rs b/src/text.rs index 80e47ef..0c4019c 100644 --- a/src/text.rs +++ b/src/text.rs @@ -918,6 +918,16 @@ impl InReplyToLine { para: para } } + + pub fn from_id(id: &str, client: &mut Client) -> Self { + let parent_text = match client.status_by_id(id) { + Ok(st) => Html::new(&st.content).to_para(), + Err(e) => Paragraph::new().add(&ColouredString::plain( + &format!("[unavailable: {}]", e) + )), + }; + Self::new(parent_text) + } } impl TextFragment for InReplyToLine { @@ -1662,15 +1672,7 @@ impl StatusDisplay { let irt = match &st.in_reply_to_id { None => None, - Some(id) => { - let parent_text = match client.status_by_id(id) { - Ok(st) => Html::new(&st.content).to_para(), - Err(e) => Paragraph::new().add(&ColouredString::plain( - &format!("[unavailable: {}]", e) - )), - }; - Some(InReplyToLine::new(parent_text)) - } + Some(id) => Some(InReplyToLine::from_id(id, client)), }; let content = Html::new(&st.content);