This repository has been archived on 2024-05-26. You can view files and clone it, but cannot push or open issues or pull requests.
core/src/app/status.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

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