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

Get all events from joined rooms

parent a1c6fffe
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,15 +4,23 @@ mod config; ...@@ -4,15 +4,23 @@ mod config;
use crate::config::Config; use crate::config::Config;
use matrix_sdk::{ use matrix_sdk::{
deserialized_responses::EncryptionInfo,
room::Room,
ruma::{ ruma::{
events::{room::message::MessageEventContent, SyncMessageEvent}, events::{
macros::EventContent, push_rules::PushRulesEvent, room::message::MessageEventContent,
room::topic::TopicEventContent, AnyRoomEvent, AnySyncRoomEvent, StateEvent,
SyncMessageEvent,
},
UserId, UserId,
}, },
Client, Result, SyncSettings, Client, Result, SyncSettings,
}; };
use std::path::Path; use matrix_sdk::ruma::{events::SyncStateEvent, Int, MilliSecondsSinceUnixEpoch};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::path::Path;
use std::{env, process::exit}; use std::{env, process::exit};
#[tokio::main] #[tokio::main]
...@@ -51,12 +59,13 @@ async fn main() -> Result<()> { ...@@ -51,12 +59,13 @@ async fn main() -> Result<()> {
} }
let config_file = env::args().last().unwrap(); let config_file = env::args().last().unwrap();
println!("Using config file: {}", config_file);
return match config::from_file(&config_file) { return match config::from_file(&config_file) {
Ok(config) => { Ok(config) => {
let alice = UserId::try_from(config.user_name)?; let alice = UserId::try_from(config.user_name)?;
let client = Client::new(config.homeserver_url)?; let client = Client::new(config.homeserver_url)?;
// Login
client client
.login( .login(
alice.localpart(), alice.localpart(),
...@@ -65,14 +74,32 @@ async fn main() -> Result<()> { ...@@ -65,14 +74,32 @@ async fn main() -> Result<()> {
Some(config.display_name.as_str()), Some(config.display_name.as_str()),
) )
.await?; .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;
client client
.register_event_handler(|ev: SyncMessageEvent<MessageEventContent>| async move { .register_event_handler(|ev: SyncStateEvent<TopicEventContent>| async move {
println!("Received a message {:?}", ev); // You can omit any or all arguments after the first.
}) })
.await; .await;
client.sync(SyncSettings::default()).await; // Should never return // Because we sync once already we must pass the previous sync token
// let settings = SyncSettings::default().token(client.sync_token().await.unwrap());
println!("Entering sync loop");
// client.sync(settings).await;
client.sync(SyncSettings::default()).await;
Ok(()) Ok(())
} }
Err(e) => panic!( Err(e) => panic!(
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter