parent
d9fa06a211
commit
e88f6a2b6b
|
@ -0,0 +1,3 @@
|
||||||
|
/target
|
||||||
|
config.dhall
|
||||||
|
var/*
|
|
@ -0,0 +1,24 @@
|
||||||
|
{ pkgs ? import <nixpkgs> { } }:
|
||||||
|
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
# rust
|
||||||
|
cargo
|
||||||
|
cargo-watch
|
||||||
|
rustc
|
||||||
|
rust-analyzer
|
||||||
|
rustfmt
|
||||||
|
|
||||||
|
# system
|
||||||
|
pkg-config
|
||||||
|
openssl
|
||||||
|
cmake
|
||||||
|
|
||||||
|
# dhall
|
||||||
|
dhall
|
||||||
|
dhall-json
|
||||||
|
];
|
||||||
|
|
||||||
|
RUST_LOG = "info";
|
||||||
|
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
|
||||||
|
}
|
31
src/main.rs
31
src/main.rs
|
@ -3,6 +3,8 @@ use matrix_sdk::{
|
||||||
config::{ClientConfig, SyncSettings},
|
config::{ClientConfig, SyncSettings},
|
||||||
room::Room,
|
room::Room,
|
||||||
ruma::{
|
ruma::{
|
||||||
|
api::client::r0::uiaa,
|
||||||
|
assign,
|
||||||
events::{
|
events::{
|
||||||
room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
||||||
SyncMessageEvent,
|
SyncMessageEvent,
|
||||||
|
@ -43,21 +45,12 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
// First we need to log in.
|
// First we need to log in.
|
||||||
client
|
client
|
||||||
.login(
|
.login(cfg.username.localpart(), &cfg.password, None, None)
|
||||||
cfg.username.localpart(),
|
|
||||||
&cfg.password,
|
|
||||||
Some(&cfg.client_id),
|
|
||||||
Some(APPLICATION_NAME),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Ignore old messages
|
// Ignore old messages
|
||||||
client.sync_once(SyncSettings::default()).await?;
|
client.sync_once(SyncSettings::default()).await?;
|
||||||
|
|
||||||
if cfg.key_path.exists() {
|
|
||||||
client.import_keys(cfg.key_path, "").await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
client.register_event_handler(on_room_message).await;
|
client.register_event_handler(on_room_message).await;
|
||||||
|
|
||||||
// Syncing is important to synchronize the client state with the server.
|
// Syncing is important to synchronize the client state with the server.
|
||||||
|
@ -67,6 +60,24 @@ async fn main() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn unfuck_crypto(client: Client, cfg: &Config) {
|
||||||
|
if let Err(e) = client.bootstrap_cross_signing(None).await {
|
||||||
|
if let Some(response) = e.uiaa_response() {
|
||||||
|
let auth_data = uiaa::AuthData::Password(assign!(
|
||||||
|
uiaa::Password::new(uiaa::UserIdentifier::MatrixId(&*cfg.username.as_str()), &cfg.password),
|
||||||
|
{ session: response.session.as_deref() }
|
||||||
|
));
|
||||||
|
|
||||||
|
client
|
||||||
|
.bootstrap_cross_signing(Some(auth_data))
|
||||||
|
.await
|
||||||
|
.expect("Couldn't bootstrap cross signing")
|
||||||
|
} else {
|
||||||
|
panic!("Error durign cross signing bootstrap {:#?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn on_room_message(event: SyncMessageEvent<RoomMessageEventContent>, room: Room) {
|
async fn on_room_message(event: SyncMessageEvent<RoomMessageEventContent>, room: Room) {
|
||||||
if let Room::Joined(room) = room {
|
if let Room::Joined(room) = room {
|
||||||
let msg_body = match event.content.msgtype {
|
let msg_body = match event.content.msgtype {
|
||||||
|
|
Loading…
Reference in New Issue