Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2632fbdc rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Place the matrix handle stuff in its own module

parent ab597b09
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#![allow(unused_imports)] #![allow(unused_imports)]
mod config; mod config;
mod matrix;
use crate::config::Config; use crate::config::Config;
use matrix_sdk::{ use matrix_sdk::Result;
deserialized_responses::EncryptionInfo,
room::Room,
ruma::{
events::{
macros::EventContent, push_rules::PushRulesEvent, room::message::MessageEventContent,
room::topic::TopicEventContent, AnyRoomEvent, AnySyncRoomEvent, StateEvent,
SyncMessageEvent,
},
UserId,
},
Client, LoopCtrl, Result, SyncSettings, RoomInfo,
};
use matrix_sdk::ruma::{events::SyncStateEvent, Int, MilliSecondsSinceUnixEpoch};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::path::Path; use std::path::Path;
use std::{env, process::exit}; use std::{env, process::exit};
...@@ -61,44 +47,7 @@ async fn main() -> Result<()> { ...@@ -61,44 +47,7 @@ async fn main() -> Result<()> {
let config_file = env::args().last().unwrap(); let config_file = env::args().last().unwrap();
println!("Using config file: {}", config_file); println!("Using config file: {}", config_file);
return match config::from_file(&config_file) { return match config::from_file(&config_file) {
Ok(config) => { Ok(config) => matrix::connect_and_handle(config).await,
let alice = UserId::try_from(config.user_name)?;
let client = Client::new(config.homeserver_url)?;
// Login
client
.login(
alice.localpart(),
config.user_password.as_str(),
None,
Some(config.display_name.as_str()),
)
.await?;
println!("Logged as: {}", alice);
// Don't respond to old messages
client.sync_once(SyncSettings::default()).await?;
// https://docs.rs/ruma/0.4.0/ruma/events/enum.AnySyncMessageEvent.html
client
.register_event_handler(
|ev: SyncMessageEvent<MessageEventContent>,
room: Room,
encryption_info: Option<EncryptionInfo>| async move {
println!(
"---\nROOM: {:?}\nENC: {:?}\nSME: {:?}",
room, encryption_info, ev
);
},
)
.await;
println!("Entering sync loop");
let token = client.sync_token().await.unwrap();
let settings = SyncSettings::default().token(token);
client.sync(settings).await;
Ok(())
}
Err(e) => panic!( Err(e) => panic!(
"Failed to read config file '{}' with error: {}", "Failed to read config file '{}' with error: {}",
config_file, e config_file, e
......
use crate::config::Config;
use std::convert::TryFrom;
use matrix_sdk::{
deserialized_responses::EncryptionInfo,
room::Room,
ruma::{
events::{
macros::EventContent, push_rules::PushRulesEvent, room::message::MessageEventContent,
room::topic::TopicEventContent, AnyRoomEvent, AnySyncRoomEvent, StateEvent,
SyncMessageEvent, SyncStateEvent,
},
Int, MilliSecondsSinceUnixEpoch, UserId,
},
Client, LoopCtrl, Result, RoomInfo, SyncSettings,
};
pub async fn connect_and_handle(config: Config) -> Result<()> {
let alice = UserId::try_from(config.user_name)?;
let client = Client::new(config.homeserver_url)?;
// Login
client
.login(
alice.localpart(),
config.user_password.as_str(),
None,
Some(config.display_name.as_str()),
)
.await?;
println!("Logged as: {}", alice);
// Don't respond to old messages
client.sync_once(SyncSettings::default()).await?;
// https://docs.rs/ruma/0.4.0/ruma/events/enum.AnySyncMessageEvent.html
client
.register_event_handler(
|ev: SyncMessageEvent<MessageEventContent>,
room: Room,
encryption_info: Option<EncryptionInfo>| async move {
println!(
"---\nROOM: {:?}\nENC: {:?}\nSME: {:?}",
room, encryption_info, ev
);
},
)
.await;
println!("Entering sync loop");
let token = client.sync_token().await.unwrap();
let settings = SyncSettings::default().token(token);
client.sync(settings).await;
Ok(())
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter