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:
parent
a7629a650a
commit
903577aba7
@ -65,6 +65,8 @@ pub struct GitlabWebhookConfig {
|
|||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
pub struct MailListConfig {
|
pub struct MailListConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
#[serde(default = "default_true")]
|
||||||
|
pub publish_on_replies: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub rooms: Vec<OwnedRoomOrAliasId>,
|
pub rooms: Vec<OwnedRoomOrAliasId>,
|
||||||
}
|
}
|
||||||
@ -89,6 +91,10 @@ pub struct Config {
|
|||||||
pub mail_archive: Option<MailArchiveConfig>,
|
pub mail_archive: Option<MailArchiveConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn load_blocking(path: &String) -> anyhow::Result<Config> {
|
fn load_blocking(path: &String) -> anyhow::Result<Config> {
|
||||||
let f = File::open(path)?;
|
let f = File::open(path)?;
|
||||||
let r = BufReader::new(f);
|
let r = BufReader::new(f);
|
||||||
|
@ -105,6 +105,7 @@ async fn handle_list(
|
|||||||
http_client: &reqwest::Client,
|
http_client: &reqwest::Client,
|
||||||
url: &String,
|
url: &String,
|
||||||
matrix_client: &Client,
|
matrix_client: &Client,
|
||||||
|
publish_on_replies: bool,
|
||||||
room_ids: &[OwnedRoomOrAliasId],
|
room_ids: &[OwnedRoomOrAliasId],
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let list_state = load_list_state(state_file).await?;
|
let list_state = load_list_state(state_file).await?;
|
||||||
@ -161,11 +162,15 @@ async fn handle_list(
|
|||||||
|
|
||||||
for room in rooms {
|
for room in rooms {
|
||||||
for item in &items {
|
for item in &items {
|
||||||
let msg =
|
if publish_on_replies || !item.title.starts_with("Re: ") {
|
||||||
RoomMessageEventContent::text_markdown(format!("\\[{}\\] [{}]({})", list.name, item.title, item.link));
|
let msg = RoomMessageEventContent::text_markdown(format!(
|
||||||
room.send(msg, None)
|
"\\[{}\\] [{}]({})",
|
||||||
.await
|
list.name, item.title, item.link
|
||||||
.with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?;
|
));
|
||||||
|
room.send(msg, None)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?;
|
||||||
|
}
|
||||||
save_list_state(
|
save_list_state(
|
||||||
ListState {
|
ListState {
|
||||||
last_pub_date: item.pub_date.value,
|
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 {
|
tokio::spawn(async move {
|
||||||
if !room_ids.is_empty() {
|
if !room_ids.is_empty() {
|
||||||
loop {
|
loop {
|
||||||
if let Err(err) =
|
if let Err(err) = handle_list(
|
||||||
handle_list(&list, &state_file, &http_client, &url, &matrix_client, &room_ids).await
|
&list,
|
||||||
|
&state_file,
|
||||||
|
&http_client,
|
||||||
|
&url,
|
||||||
|
&matrix_client,
|
||||||
|
list.publish_on_replies,
|
||||||
|
&room_ids,
|
||||||
|
)
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
warn!("{:#}", err);
|
warn!("{:#}", err);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user