2023-07-06 18:47:06 +00:00
|
|
|
use matrix_sdk::Client;
|
|
|
|
use matrix_sdk::ruma::{room_id, RoomId, ServerName};
|
2023-07-04 16:32:57 +00:00
|
|
|
|
|
|
|
pub enum State {
|
|
|
|
None,
|
|
|
|
Main,
|
|
|
|
Setup,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Status {
|
|
|
|
state: State,
|
|
|
|
account_name: String,
|
|
|
|
account_user_id: String,
|
2023-07-06 18:47:06 +00:00
|
|
|
|
|
|
|
client: Option<Client>,
|
|
|
|
rooms: Vec<matrix_sdk::room::Joined>,
|
|
|
|
current_room_id: Option<u32>,
|
2023-07-04 16:32:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 18:47:06 +00:00
|
|
|
impl Status {
|
|
|
|
pub fn new(client: Option<Client>) -> Self {
|
|
|
|
let rooms = match &client {
|
|
|
|
Some(c) => c.joined_rooms(),
|
|
|
|
None => Vec::new(),
|
|
|
|
};
|
|
|
|
|
2023-07-04 16:32:57 +00:00
|
|
|
Self {
|
|
|
|
state: State::None,
|
|
|
|
account_name: "".to_string(),
|
|
|
|
account_user_id: "".to_string(),
|
2023-07-06 18:47:06 +00:00
|
|
|
client,
|
|
|
|
rooms,
|
|
|
|
current_room_id: Some(0),
|
2023-07-04 16:32:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn account_name(&self) -> &String {
|
|
|
|
&self.account_name
|
|
|
|
}
|
|
|
|
|
2023-07-06 15:34:55 +00:00
|
|
|
pub fn set_account_name(&mut self, name: String) {
|
|
|
|
self.account_name = name;
|
|
|
|
}
|
|
|
|
|
2023-07-04 16:32:57 +00:00
|
|
|
pub fn account_user_id(&self) -> &String {
|
|
|
|
&self.account_user_id
|
|
|
|
}
|
|
|
|
|
2023-07-06 15:34:55 +00:00
|
|
|
pub fn set_account_user_id(&mut self, user_id: String) {
|
|
|
|
self.account_user_id = user_id;
|
|
|
|
}
|
|
|
|
|
2023-07-06 18:47:06 +00:00
|
|
|
pub fn room(&self) -> Option<&matrix_sdk::room::Joined> {
|
|
|
|
self.rooms.get(self.current_room_id? as usize)
|
2023-07-04 16:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn state(&self) -> &State {
|
|
|
|
&self.state
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_state(&mut self, state: State) {
|
|
|
|
self.state = state;
|
|
|
|
}
|
|
|
|
}
|