From cfc7dc8b3ef149f384bd1f2ef3989701a93c7df2 Mon Sep 17 00:00:00 2001 From: Xyoz Netsphere Date: Mon, 24 Jan 2022 12:02:56 +0100 Subject: feat(im-matrix): added multi-room support --- src/config.rs | 7 +++++-- src/main.rs | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index a4bba44..bf9af1e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use std::{fs, path::Path}; use anyhow::Result; use serde::Deserialize; +use serde_with::{serde_as, OneOrMany}; /// The main configuration. #[derive(Debug, Clone, Deserialize, Default)] @@ -36,6 +37,7 @@ pub struct Discord { } /// Configuration pertaining to the Matrix posting. +#[serde_as] #[derive(Debug, Clone, Deserialize)] pub struct Matrix { /// Matrix homeserver. @@ -46,8 +48,9 @@ pub struct Matrix { pub password: String, /// Device ID, or None if a new one should be generated. pub device_id: Option, - /// Room ID where the message should be posted to. - pub room_id: String, + /// Room ID(s) where the message should be posted to. + #[serde_as(as = "OneOrMany<_>")] + pub room_id: Vec, } /// Attempt to load the configuration from the given file. diff --git a/src/main.rs b/src/main.rs index bdaf13a..ada456c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,8 +93,10 @@ fn inner_main(opts: &Opts) -> Result<()> { } if let Some(m) = &config.matrix { - matrix::post_link(m.clone().into(), &m.room_id, &log, &permalink) - .context("Could not post link to Matrix")?; + for room_id in &m.room_id { + matrix::post_link(m.clone().into(), &room_id, &log, &permalink) + .context(format!("Could not post link to Matrix (room_id: {})", &room_id))?; + } } } } @@ -203,9 +205,11 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> { } if let Some(m) = &config.matrix { - matrix::post_link(m.clone().into(), &m.room_id, &log, &permalink) - .context("Could not post link to Matrix")?; - info!("Posted link to Matrix"); + for room_id in &m.room_id { + matrix::post_link(m.clone().into(), &room_id, &log, &permalink) + .context(format!("Could not post link to Matrix (room_id: {})", &room_id))?; + info!("Posted link to Matrix ({})", &room_id); + } } Ok(()) -- cgit v1.2.3 From 18df1606dd5a68c7ea0b8284d848dacb94ee35e8 Mon Sep 17 00:00:00 2001 From: Xyoz Netsphere Date: Mon, 24 Jan 2022 12:16:45 +0100 Subject: fix: &room_id -> room_id in matrix room loops --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index ada456c..2876777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,7 @@ fn inner_main(opts: &Opts) -> Result<()> { if let Some(m) = &config.matrix { for room_id in &m.room_id { - matrix::post_link(m.clone().into(), &room_id, &log, &permalink) + matrix::post_link(m.clone().into(), room_id, &log, &permalink) .context(format!("Could not post link to Matrix (room_id: {})", &room_id))?; } } @@ -206,7 +206,7 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> { if let Some(m) = &config.matrix { for room_id in &m.room_id { - matrix::post_link(m.clone().into(), &room_id, &log, &permalink) + matrix::post_link(m.clone().into(), room_id, &log, &permalink) .context(format!("Could not post link to Matrix (room_id: {})", &room_id))?; info!("Posted link to Matrix ({})", &room_id); } -- cgit v1.2.3 From e9c281cbf72413089788d775797906e65cae5599 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 24 Jan 2022 12:18:35 +0100 Subject: cargo fmt --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 2876777..b86f281 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,8 +94,9 @@ fn inner_main(opts: &Opts) -> Result<()> { if let Some(m) = &config.matrix { for room_id in &m.room_id { - matrix::post_link(m.clone().into(), room_id, &log, &permalink) - .context(format!("Could not post link to Matrix (room_id: {})", &room_id))?; + matrix::post_link(m.clone().into(), room_id, &log, &permalink).context( + format!("Could not post link to Matrix (room_id: {})", &room_id), + )?; } } } @@ -205,9 +206,11 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> { } if let Some(m) = &config.matrix { - for room_id in &m.room_id { - matrix::post_link(m.clone().into(), room_id, &log, &permalink) - .context(format!("Could not post link to Matrix (room_id: {})", &room_id))?; + for room_id in &m.room_id { + matrix::post_link(m.clone().into(), room_id, &log, &permalink).context(format!( + "Could not post link to Matrix (room_id: {})", + &room_id + ))?; info!("Posted link to Matrix ({})", &room_id); } } -- cgit v1.2.3