From 3a4f0ef1534cad8bfc42c7c7dcc743500b7590d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 19 Sep 2021 15:09:08 +0200 Subject: [PATCH] fix threading in chained responses --- src/group_handler/handle_mention.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/group_handler/handle_mention.rs b/src/group_handler/handle_mention.rs index 954b528..c266f0a 100644 --- a/src/group_handler/handle_mention.rs +++ b/src/group_handler/handle_mention.rs @@ -283,6 +283,8 @@ impl<'a> ProcessMention<'a> { async fn send_reply_multipart(&self, mention : String, msg : String) -> Result<(), GroupError> { let parts = smart_split(&msg, Some(mention), self.config.get_character_limit()); + + let mut parent = self.status.id.clone(); for p in parts { if let Ok(post) = StatusBuilder::new() .status(p) @@ -291,10 +293,12 @@ impl<'a> ProcessMention<'a> { } else { "text/plain" }) + .in_reply_to(&parent) .visibility(Visibility::Direct) .build() { - self.client.new_status(post).await?; + let status = self.client.new_status(post).await?; + parent = status.id; } // Sleep a bit to avoid throttling @@ -307,15 +311,25 @@ impl<'a> ProcessMention<'a> { async fn send_announcement_multipart(&self, msg : &str) -> Result<(), GroupError> { let parts = smart_split(msg, None, self.config.get_character_limit()); + let mut parent = None; for p in parts { - let post = StatusBuilder::new() + let mut builder = StatusBuilder::new(); + + builder .status(p) .content_type("text/markdown") - .visibility(Visibility::Public) + .visibility(Visibility::Public); + + if let Some(p) = parent.as_ref() { + builder.in_reply_to(p); + } + + let post = builder .build() .expect("error build status"); - self.client.new_status(post).await?; + let status = self.client.new_status(post).await?; + parent = Some(status.id); // Sleep a bit to avoid throttling tokio::time::sleep(Duration::from_secs(1)).await;