Compare commits
11
Commits
aa47e38536
...
0b700cabc4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b700cabc4
|
||
|
|
e28e963927
|
||
|
|
856ac37e45
|
||
|
|
6169182aff
|
||
|
|
cdd841a681
|
||
|
|
e392067042
|
||
|
|
b343536032
|
||
|
|
57b0760c99
|
||
|
|
9e4d6f2ed6
|
||
|
|
8911bacdec
|
||
|
|
ae1cfa4666
|
No files matched your search
+9
-9
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*!
|
||||
* matrix-lolopener v0.1.0
|
||||
*
|
||||
* Copyright (C) 2026 The 1312 Media Collective
|
||||
@@ -56,8 +56,8 @@ impl Config {
|
||||
|
||||
let serialized_config = fs::read_to_string(config_file).map_err(|e| {
|
||||
match e.kind() {
|
||||
io::ErrorKind::NotFound => Error::FileNotFoundError(config_file.into()),
|
||||
io::ErrorKind::PermissionDenied => Error::PermissionDeniedError(),
|
||||
io::ErrorKind::NotFound => Error::FileNotFound(config_file.into()),
|
||||
io::ErrorKind::PermissionDenied => Error::PermissionDenied(),
|
||||
_ => e.into(),
|
||||
}
|
||||
})?;
|
||||
@@ -71,21 +71,21 @@ impl Config {
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)] // we use Debug, so inner fields are never read
|
||||
pub enum Error {
|
||||
FileNotFoundError(String),
|
||||
PermissionDeniedError(),
|
||||
InvalidFormatError(serde_yaml::Error),
|
||||
IoError(io::Error),
|
||||
FileNotFound(String),
|
||||
PermissionDenied(),
|
||||
InvalidFormat(serde_yaml::Error),
|
||||
Io(io::Error),
|
||||
}
|
||||
|
||||
impl From<serde_yaml::Error> for Error {
|
||||
fn from(e: serde_yaml::Error) -> Self {
|
||||
Self::InvalidFormatError(e)
|
||||
Self::InvalidFormat(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(e: io::Error) -> Self {
|
||||
Self::IoError(e)
|
||||
Self::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*!
|
||||
* matrix-lolopener v0.1.0
|
||||
*
|
||||
* Copyright (C) 2026 The 1312 Media Collective
|
||||
@@ -50,7 +50,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
// it holds a tuple with an HTML message and a list of rooms to post to
|
||||
let (bcast_tx, bcast_rx) = broadcast::channel::<(String, Vec<String>)>(1024);
|
||||
|
||||
let handle: JoinHandle<_> = (|| {
|
||||
let handle: JoinHandle<_> = {
|
||||
let matrix_ready = Arc::clone(&matrix_ready);
|
||||
let config = Arc::clone(&config);
|
||||
|
||||
@@ -68,14 +68,12 @@ async fn main() -> anyhow::Result<()> {
|
||||
debug!("Sending msg {}", msg);
|
||||
//XXX: Panic if the matrix module can't get the message
|
||||
bcast_tx.send((msg.into(), config.rooms.clone())).unwrap();
|
||||
|
||||
()
|
||||
}).await.unwrap(); //XXX: Panic if the mqtt broker fails
|
||||
})
|
||||
})();
|
||||
};
|
||||
|
||||
login_and_sync(
|
||||
config.homeserver_uri.clone().into(),
|
||||
config.homeserver_uri.clone(),
|
||||
&config.auth,
|
||||
matrix_ready,
|
||||
bcast_rx
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*!
|
||||
* matrix-lolopener v0.1.0
|
||||
*
|
||||
* Copyright (C) 2024 The 1312 Media Collective
|
||||
@@ -87,10 +87,12 @@ async fn send_to_room(
|
||||
Ok(_) => {
|
||||
info!("Posting to room {}", room.room_id());
|
||||
room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await?;
|
||||
|
||||
return Ok(());
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Failed to join room {e:?}");
|
||||
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
@@ -158,7 +160,6 @@ pub async fn login_and_sync(
|
||||
Ok(_) => return Ok(()),
|
||||
Err(e) => {
|
||||
error!("Sync error: {e:?}");
|
||||
()
|
||||
}
|
||||
},
|
||||
recv = rx.recv() => match recv {
|
||||
@@ -179,7 +180,7 @@ pub async fn login_and_sync(
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
panic!("Broadcast channel is lagging: {e:?}");
|
||||
panic!("Broken channel: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-20
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*!
|
||||
* matrix-lolopener v0.1.0
|
||||
*
|
||||
* Copyright (C) 2026 The 1312 Media Collective
|
||||
@@ -54,13 +54,12 @@ impl MQTT {
|
||||
mqttoptions.set_keep_alive(Duration::from_secs(5));
|
||||
|
||||
let (client, eventloop) = AsyncClient::new(mqttoptions, 1);
|
||||
let mqtt = MQTT {
|
||||
config: config,
|
||||
client: client,
|
||||
eventloop: eventloop,
|
||||
};
|
||||
|
||||
mqtt
|
||||
MQTT {
|
||||
config,
|
||||
client,
|
||||
eventloop,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn subscribe<F: Fn(StatusMessage)>(&mut self, callback: F) -> Result<()> {
|
||||
@@ -71,13 +70,10 @@ impl MQTT {
|
||||
let notification = self.eventloop.poll().await?;
|
||||
debug!("Notification = {:?}", notification);
|
||||
|
||||
match notification {
|
||||
Event::Incoming(Incoming::Publish(p)) => {
|
||||
let msg: StatusMessage = serde_json::from_slice(p.payload.as_ref())?;
|
||||
info!("Message: {:?}", msg);
|
||||
callback(msg);
|
||||
},
|
||||
_ => (),
|
||||
if let Event::Incoming(Incoming::Publish(p)) = notification {
|
||||
let msg: StatusMessage = serde_json::from_slice(p.payload.as_ref())?;
|
||||
info!("Message: {:?}", msg);
|
||||
callback(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,26 +85,26 @@ impl MQTT {
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)] // we use Debug, so inner fields are never read
|
||||
pub enum Error {
|
||||
MQTTClientError(rumqttc::ClientError),
|
||||
MQTTConnectionError(rumqttc::ConnectionError),
|
||||
InvalidFormatError(serde_json::Error),
|
||||
MQTTClient(rumqttc::ClientError),
|
||||
MQTTConnection(rumqttc::ConnectionError),
|
||||
InvalidFormat(serde_json::Error),
|
||||
}
|
||||
|
||||
impl From<rumqttc::ClientError> for Error {
|
||||
fn from(e: rumqttc::ClientError) -> Self {
|
||||
Self::MQTTClientError(e)
|
||||
Self::MQTTClient(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rumqttc::ConnectionError> for Error {
|
||||
fn from(e: rumqttc::ConnectionError) -> Self {
|
||||
Self::MQTTConnectionError(e)
|
||||
Self::MQTTConnection(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
fn from(e: serde_json::Error) -> Self {
|
||||
Self::InvalidFormatError(e)
|
||||
Self::InvalidFormat(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user