From 387ec577b28d772402f39d2765bd6ec31c215786 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Mon, 29 Nov 2021 16:49:46 +0100 Subject: [PATCH] session: Add action to select room by id --- src/session/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/session/mod.rs b/src/session/mod.rs index 1e546422..c7583b26 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -46,6 +46,7 @@ use matrix_sdk::ruma::{ session::logout, }, assign, + identifiers::RoomId, }; use matrix_sdk::{ config::{ClientConfig, RequestConfig, SyncSettings}, @@ -58,6 +59,7 @@ use matrix_sdk::{ Client, Error as MatrixError, HttpError, }; use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use std::convert::TryFrom; use std::fs; use std::time::Duration; use tokio::task::JoinHandle; @@ -103,6 +105,20 @@ mod imp { session.select_room(None); }); + klass.install_action( + "session.show-room", + Some("s"), + move |session, _, parameter| { + if let Ok(room_id) = + RoomId::try_from(parameter.unwrap().get::().unwrap()) + { + session.select_room_by_id(room_id); + } else { + error!("Can't show room because the provided id is invalid"); + } + }, + ); + klass.install_action("session.logout", None, move |session, _, _| { spawn!(clone!(@weak session => async move { let priv_ = imp::Session::from_instance(&session); @@ -253,6 +269,14 @@ impl Session { .set_selected_item(room.map(|item| item.upcast())); } + pub fn select_room_by_id(&self, room_id: RoomId) { + if let Some(room) = self.room_list().get(&room_id) { + self.select_room(Some(room)); + } else { + warn!("A room with id {} couldn't be found", room_id); + } + } + pub fn login_with_password(&self, homeserver: Url, username: String, password: String) { let priv_ = imp::Session::from_instance(self); priv_.logout_on_dispose.set(true);