⚡️ Remove the periodic pooling to get the rooms (joined or not)
This commit is contained in:
45
src/base.rs
45
src/base.rs
@@ -16,7 +16,7 @@ use tokio::select;
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use crate::components::chats_window::interface::Interface as ChatsWinInterface;
|
||||
use crate::matrix_interface::client::{Client, RoomTopicEvent};
|
||||
use crate::matrix_interface::client::{Client, RoomEvent};
|
||||
use crate::matrix_interface::requester::{Receivers, Requester};
|
||||
use crate::matrix_interface::worker_tasks::LoginStyle;
|
||||
|
||||
@@ -133,21 +133,30 @@ impl AppSettings {
|
||||
|
||||
pub static APP_SETTINGS: AtomRef<AppSettings> = AtomRef(|_| AppSettings::new());
|
||||
|
||||
async fn on_room(room: Room, rooms_ref: &UseAtomRef<ByIdRooms>) {
|
||||
let room_id = room.id();
|
||||
|
||||
async fn on_room(room_id: OwnedRoomId, room: Room, rooms_ref: &UseAtomRef<ByIdRooms>) {
|
||||
// TODO: Update rooms
|
||||
rooms_ref
|
||||
.write()
|
||||
.insert(room_id, RefCell::<Room>::new(room));
|
||||
}
|
||||
|
||||
pub async fn on_room_topic(room_topic_event: RoomTopicEvent, rooms_ref: &UseAtomRef<ByIdRooms>) {
|
||||
let room_id = room_topic_event.0;
|
||||
async fn on_joining_invitation(
|
||||
room_id: OwnedRoomId,
|
||||
room: Room,
|
||||
rooms_ref: &UseAtomRef<ByIdRooms>,
|
||||
) {
|
||||
debug!(
|
||||
"You're invited to join the \"{}\" room",
|
||||
room.name().unwrap()
|
||||
);
|
||||
// TODO: Update rooms
|
||||
rooms_ref
|
||||
.write()
|
||||
.insert(room_id, RefCell::<Room>::new(room));
|
||||
}
|
||||
|
||||
pub async fn on_room_topic(room_id: OwnedRoomId, topic: String, rooms_ref: &UseAtomRef<ByIdRooms>) {
|
||||
if let Some(room_ref) = rooms_ref.read().get(&room_id) {
|
||||
let topic = room_topic_event.1;
|
||||
|
||||
let mut room = room_ref.borrow_mut();
|
||||
room.topic = Some(RefCell::new(topic));
|
||||
} else {
|
||||
@@ -161,21 +170,20 @@ pub async fn sync_rooms(
|
||||
rooms_ref: UseAtomRef<ByIdRooms>,
|
||||
) {
|
||||
if let Some(_is_logged) = rx.next().await {
|
||||
let mut rooms_receiver = receivers.rooms_receiver.borrow_mut();
|
||||
let mut room_topic_receiver = receivers.room_topic_receiver.borrow_mut();
|
||||
let mut rooms_receiver = receivers.room_receiver.borrow_mut();
|
||||
|
||||
loop {
|
||||
// TODO: Remove select if no more receivers will be used.
|
||||
select! {
|
||||
res = rooms_receiver.recv() => {
|
||||
if let Ok(room) = res {
|
||||
on_room(room, &rooms_ref).await;
|
||||
if let Ok(room_event) = res {
|
||||
match room_event {
|
||||
RoomEvent::MemberEvent(room_id, room) => on_room(room_id, room, &rooms_ref).await,
|
||||
RoomEvent::InviteEvent(room_id, room) => on_joining_invitation(room_id, room, &rooms_ref).await,
|
||||
RoomEvent::TopicEvent(room_id, topic) => on_room_topic(room_id, topic, &rooms_ref).await,
|
||||
};
|
||||
}
|
||||
},
|
||||
res = room_topic_receiver.recv() => {
|
||||
if let Ok(room_topic_event) = res {
|
||||
on_room_topic(room_topic_event, &rooms_ref).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,7 +203,8 @@ pub async fn login(
|
||||
if homeserver_url.is_some() && username.is_some() && password.is_some() {
|
||||
let client = Client::spawn(homeserver_url.unwrap()).await;
|
||||
|
||||
client.init().await;
|
||||
// TODO: Handle error case.
|
||||
let _ = client.init().await;
|
||||
|
||||
match client
|
||||
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
|
||||
|
Reference in New Issue
Block a user