Also 'cargo clippy --fix', as current clippy warns on more things.
This commit is contained in:
@@ -18,7 +18,7 @@ use std::{fmt, process::exit, time::Duration};
|
||||
|
||||
use matrix_sdk::{
|
||||
config::SyncSettings,
|
||||
room::Joined,
|
||||
room::Room,
|
||||
ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId},
|
||||
BaseRoom, Client,
|
||||
};
|
||||
@@ -26,12 +26,8 @@ use serde::de;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
async fn build_sync_settings(matrix_client: &Client) -> SyncSettings {
|
||||
let mut settings = SyncSettings::default().timeout(Duration::from_secs(30));
|
||||
if let Some(token) = matrix_client.sync_token().await {
|
||||
settings = settings.token(token);
|
||||
}
|
||||
settings
|
||||
async fn build_sync_settings() -> SyncSettings {
|
||||
SyncSettings::default().timeout(Duration::from_secs(30))
|
||||
}
|
||||
|
||||
pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
||||
@@ -41,21 +37,21 @@ pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
||||
.build()
|
||||
.await?;
|
||||
client
|
||||
.matrix_auth()
|
||||
.login_username(&config.user_id, &config.password)
|
||||
.initial_device_display_name("Bebot")
|
||||
.send()
|
||||
.await?;
|
||||
info!("Connected to matrix as {}; waiting for first sync", config.user_id);
|
||||
|
||||
let settings = build_sync_settings(&client).await;
|
||||
let settings = build_sync_settings().await;
|
||||
client.sync_once(settings).await?;
|
||||
info!("First matrix sync complete");
|
||||
|
||||
let sync_client = client.clone();
|
||||
tokio::spawn(async move {
|
||||
let settings = build_sync_settings(&sync_client).await;
|
||||
let settings = build_sync_settings().await;
|
||||
if let Err(err) = sync_client.sync(settings).await {
|
||||
error!("Matrix sync failed: {}", err);
|
||||
error!("Matrix sync failed: {err}");
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
@@ -63,7 +59,7 @@ pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
pub async fn ensure_room_joined(matrix_client: &Client, room_id: &OwnedRoomOrAliasId) -> anyhow::Result<Joined> {
|
||||
pub async fn ensure_room_joined(matrix_client: &Client, room_id: &OwnedRoomOrAliasId) -> anyhow::Result<Room> {
|
||||
fn room_matches(a_room: &BaseRoom, our_room: &OwnedRoomOrAliasId) -> bool {
|
||||
let our_room_str = our_room.as_str();
|
||||
a_room.room_id().as_str() == our_room_str
|
||||
@@ -85,11 +81,11 @@ pub async fn ensure_room_joined(matrix_client: &Client, room_id: &OwnedRoomOrAli
|
||||
.iter()
|
||||
.find(|a_room| room_matches(a_room, room_id))
|
||||
{
|
||||
invited.accept_invitation().await?;
|
||||
invited.join().await?;
|
||||
} else {
|
||||
matrix_client.join_room_by_id_or_alias(room_id, &[]).await?;
|
||||
}
|
||||
let settings = build_sync_settings(matrix_client).await;
|
||||
let settings = build_sync_settings().await;
|
||||
matrix_client.sync_once(settings).await?;
|
||||
room = matrix_client
|
||||
.joined_rooms()
|
||||
|
Reference in New Issue
Block a user