Function mxlink::init

source ยท
pub async fn init(init_config: &InitConfig) -> Result<MatrixLink, InitError>
Expand description

Initialize a new Matrix Link (wrapping a Matrix Client) either from an existing (persisted) session/data or by logging in anew.

Examples found in repository?
examples/quick_start.rs (line 63)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
async fn create_matrix_link() -> MatrixLink {
    let login_creds =
        LoginCredentials::UserPassword(LOGIN_USERNAME.to_owned(), LOGIN_PASSWORD.to_owned());

    let login_encryption = LoginEncryption::new(
        Some(LOGIN_ENCRYPTION_RECOVERY_PASSPHRASE.to_owned()),
        LOGIN_ENCRYPTION_RESET_ALLOWED,
    );

    let login_config = LoginConfig::new(
        HOMESERVER_URL.to_owned(),
        login_creds,
        Some(login_encryption),
        DEVICE_DISPLAY_NAME.to_owned(),
    );

    let session_file_path = std::path::PathBuf::from(PERSISTENCE_SESSION_FILE_PATH);
    let session_encryption_key = EncryptionKey::from_hex_str(PERSISTENCE_SESSION_ENCRYPTION_KEY)
        .expect("Invalid encryption key hex string");
    let db_dir_path = std::path::PathBuf::from(PERSISTENCE_DB_DIR_PATH);

    let persistence_config =
        PersistenceConfig::new(session_file_path, Some(session_encryption_key), db_dir_path);

    let init_config = InitConfig::new(login_config, persistence_config);

    mxlink::init(&init_config)
        .await
        .expect("Failed to initialize MatrixLink")
}