aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornetworkjanitor <networkjanitor@xafy.de>2024-07-18 04:47:40 +0200
committernetworkjanitor <networkjanitor@xafy.de>2024-07-18 04:47:40 +0200
commita141d4fcdeba85d07e190338cf9386019ea03de9 (patch)
tree55eb10780866a8807746c332413646d1c980530a /src
parent3eef38c0fabba76216d548e3668f54a5f8549805 (diff)
downloadezau-a141d4fcdeba85d07e190338cf9386019ea03de9.tar.gz
ezau-a141d4fcdeba85d07e190338cf9386019ea03de9.tar.bz2
ezau-a141d4fcdeba85d07e190338cf9386019ea03de9.zip
wip: update Cargo.lock dependencies, doc
Diffstat (limited to 'src')
-rw-r--r--src/matrix.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/matrix.rs b/src/matrix.rs
index 0b77b21..8be0e38 100644
--- a/src/matrix.rs
+++ b/src/matrix.rs
@@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
use anyhow::Result;
use evtclib::Log;
-use log::{debug, info};
+use log::{debug, info, warn, error};
use tokio::runtime::Runtime;
use tokio::fs;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
@@ -139,7 +139,7 @@ pub fn post_link(user: MatrixUser, room_id: &str, log: &Log, link: &str) -> Resu
/// Restore a previous session.
/// Copied from the matrix-rust-sdk persist-session example.
async fn restore_session(session_file: &Path) -> anyhow::Result<(Client, Option<String>)> {
- println!("Previous session found in '{}'", session_file.to_string_lossy());
+ debug!("Previous session found in '{}'", session_file.to_string_lossy());
// The session was serialized as JSON in a file.
let serialized_session = fs::read_to_string(session_file).await?;
@@ -153,7 +153,7 @@ async fn restore_session(session_file: &Path) -> anyhow::Result<(Client, Option<
.build()
.await?;
- println!("Restoring session for {}…", user_session.meta.user_id);
+ debug!("Restoring session for {}…", user_session.meta.user_id);
// Restore the Matrix user session.
client.restore_session(user_session).await?;
@@ -164,7 +164,7 @@ async fn restore_session(session_file: &Path) -> anyhow::Result<(Client, Option<
/// Login with a new device.
/// Copied from the matrix-rust-sdk persist-session example.
async fn login(data_dir: &Path, session_file: &Path, homeserver: String, username: String, password: String) -> anyhow::Result<Client> {
- println!("No previous session found, logging in…");
+ info!("No previous session found, logging in…");
let (client, client_session) = build_client(data_dir, homeserver).await?;
let matrix_auth = client.matrix_auth();
@@ -176,12 +176,12 @@ async fn login(data_dir: &Path, session_file: &Path, homeserver: String, usernam
.await
{
Ok(_) => {
- println!("Logged in as {username}");
+ info!("Logged in as {username}");
break;
}
Err(error) => {
- println!("Error logging in: {error}");
- println!("Please try again\n");
+ error!("Error logging in: {error}");
+ error!("Please try again\n");
}
}
}
@@ -195,7 +195,7 @@ async fn login(data_dir: &Path, session_file: &Path, homeserver: String, usernam
serde_json::to_string(&FullSession { client_session, user_session, sync_token: None })?;
fs::write(session_file, serialized_session).await?;
- println!("Session persisted in {}", session_file.to_string_lossy());
+ info!("Session persisted in {}", session_file.to_string_lossy());
// After logging in, you might want to verify this session with another one, or bootstrap
// cross-signing if this is your first session with encryption, or if you need to reset
@@ -236,8 +236,8 @@ async fn build_client(data_dir: &Path, homeserver: String) -> anyhow::Result<(Cl
matrix_sdk::ClientBuildError::AutoDiscovery(_)
| matrix_sdk::ClientBuildError::Url(_)
| matrix_sdk::ClientBuildError::Http(_) => {
- println!("Error checking the homeserver: {error}");
- println!("Please try again\n");
+ error!("Error checking the homeserver: {error}");
+ error!("Please try again\n");
}
_ => {
// Forward other errors, it's unlikely we can retry with a different outcome.
@@ -255,7 +255,7 @@ async fn sync(
initial_sync_token: Option<String>,
session_file: &Path,
) -> anyhow::Result<()> {
- println!("Launching a first sync to ignore past messages…");
+ debug!("Launching a first sync to ignore past messages…");
// Enable room members lazy-loading, it will speed up the initial sync a lot
// with accounts in lots of rooms.
@@ -285,13 +285,13 @@ async fn sync(
break;
}
Err(error) => {
- println!("An error occurred during initial sync: {error}");
- println!("Trying again…");
+ warn!("An error occurred during initial sync: {error}");
+ warn!("Trying again…");
}
}
}
- println!("The client is ready!");
+ debug!("The client is ready!");
Ok(())
}
@@ -344,7 +344,9 @@ async fn find_message(
{
if msg.sender() == my_id && msg.origin_server_ts() >= time_limit {
// filters out redacted messages - but apparently it doesn't?
- // maybe the sync is still wrong and doesn't
+ // as_original() should return only the original, if not redacted.
+ // maybe the sync is still wrong and doesn't "apply" redactions to
+ // room.messages?
if let Some(orig_msg) = &msg.as_original() {
match &orig_msg.content.relates_to {
Some(relation) =>