Add option to toggle publishing for mailing list replies

For some lists, such as release announcement lists, you may not want
replies to posts published.
This commit is contained in:
Brian Tarricone 2024-02-05 11:49:57 -08:00
parent a7629a650a
commit 903577aba7
2 changed files with 26 additions and 7 deletions

View File

@ -65,6 +65,8 @@ pub struct GitlabWebhookConfig {
#[derive(Clone, Deserialize)]
pub struct MailListConfig {
pub name: String,
#[serde(default = "default_true")]
pub publish_on_replies: bool,
#[serde(default)]
pub rooms: Vec<OwnedRoomOrAliasId>,
}
@ -89,6 +91,10 @@ pub struct Config {
pub mail_archive: Option<MailArchiveConfig>,
}
fn default_true() -> bool {
true
}
fn load_blocking(path: &String) -> anyhow::Result<Config> {
let f = File::open(path)?;
let r = BufReader::new(f);

View File

@ -105,6 +105,7 @@ async fn handle_list(
http_client: &reqwest::Client,
url: &String,
matrix_client: &Client,
publish_on_replies: bool,
room_ids: &[OwnedRoomOrAliasId],
) -> anyhow::Result<()> {
let list_state = load_list_state(state_file).await?;
@ -161,11 +162,15 @@ async fn handle_list(
for room in rooms {
for item in &items {
let msg =
RoomMessageEventContent::text_markdown(format!("\\[{}\\] [{}]({})", list.name, item.title, item.link));
if publish_on_replies || !item.title.starts_with("Re: ") {
let msg = RoomMessageEventContent::text_markdown(format!(
"\\[{}\\] [{}]({})",
list.name, item.title, item.link
));
room.send(msg, None)
.await
.with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?;
}
save_list_state(
ListState {
last_pub_date: item.pub_date.value,
@ -207,8 +212,16 @@ pub fn start_polling(config: MailArchiveConfig, matrix_client: Client) -> anyhow
tokio::spawn(async move {
if !room_ids.is_empty() {
loop {
if let Err(err) =
handle_list(&list, &state_file, &http_client, &url, &matrix_client, &room_ids).await
if let Err(err) = handle_list(
&list,
&state_file,
&http_client,
&url,
&matrix_client,
list.publish_on_replies,
&room_ids,
)
.await
{
warn!("{:#}", err);
}