chiark / gitweb /
Move some code into an InReplyToLine::from_id constructor.
authorSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 07:38:26 +0000 (07:38 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 08:16:16 +0000 (08:16 +0000)
That will make it easier to reuse later.

src/text.rs

index 80e47ef99ffe4ef8710b8fdafd22e088362a9c20..0c4019c4b51d083b9492263fb16380dc85c35aba 100644 (file)
@@ -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);