Skip to content

Commit

Permalink
fixed crashed
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoon committed Oct 7, 2024
1 parent 057ab12 commit 5a7412f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/home/rooms_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ pub struct RoomsList {
#[rust] max_known_rooms: Option<u32>,
#[live] room_type: String
}

pub struct TotalLoadedRoomsCount(u32);
impl RoomsList {
fn update_status_rooms_count(&mut self) {
fn update_status_rooms_count(&mut self, cx: &mut Cx) {
let total_loaded_rooms_count = if cx.has_global::<TotalLoadedRoomsCount>() {
cx.get_global::<TotalLoadedRoomsCount>().0
} else { 0 };
self.status = if let Some(max_rooms) = self.max_known_rooms {
format!("Loaded {} of {} total rooms.", self.all_rooms.len(), max_rooms)
format!("Loaded {} of {} total rooms.", total_loaded_rooms_count, max_rooms)
} else {
format!("Loaded {} rooms.", self.all_rooms.len())
};
Expand All @@ -206,6 +209,11 @@ impl Widget for RoomsList {
num_updates += 1;
match update {
RoomsListUpdate::AddRoom(room) => {
if cx.has_global::<TotalLoadedRoomsCount>() {
cx.get_global::<TotalLoadedRoomsCount>().0 += 1;
} else {
cx.set_global(TotalLoadedRoomsCount(1));
}
self.all_rooms.push(room);
}
RoomsListUpdate::UpdateRoomAvatar { room_id, avatar } => {
Expand Down Expand Up @@ -244,7 +252,7 @@ impl Widget for RoomsList {
}
RoomsListUpdate::LoadedRooms { max_rooms } => {
self.max_known_rooms = max_rooms;
self.update_status_rooms_count();
self.update_status_rooms_count(cx);
}
RoomsListUpdate::Status { status } => {
self.status = status;
Expand Down Expand Up @@ -327,7 +335,7 @@ impl Widget for RoomsList {
item
}
// Draw the status label as the bottom entry.
else if item_id == status_label_id {
else if item_id == status_label_id && self.room_type == "room" {
let item = list.item(cx, item_id, live_id!(status_label)).unwrap();
item.as_view().apply_over(cx, live!{
height: Fit,
Expand Down
13 changes: 10 additions & 3 deletions src/home/rooms_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,17 @@ live_design! {
}
}
}

<RoomsList> {
}
<CachedWidget> {
people_list = <RoomsList> {
width: Fill, height: 75
room_type: "people"
}

}
<View> {
flow: Down, spacing: 20
padding: {top: 20},
width: Fill, height: Fit
<CollapsableTitle> {
title = {
text: "Channels"
Expand All @@ -154,6 +160,7 @@ live_design! {
}
}
<CachedWidget> {
height: Fit,
rooms_list = <RoomsList> {
room_type: "room"
}
Expand Down
2 changes: 2 additions & 0 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,11 @@ fn handle_room_list_service_loading_state(mut loading_state: Subscriber<RoomList
match state {
RoomListLoadingState::NotLoaded => {
enqueue_rooms_list_update(RoomsListUpdate::NotLoaded, false);
enqueue_rooms_list_update(RoomsListUpdate::NotLoaded, true);
}
RoomListLoadingState::Loaded { maximum_number_of_rooms } => {
enqueue_rooms_list_update(RoomsListUpdate::LoadedRooms { max_rooms: maximum_number_of_rooms }, false);
enqueue_rooms_list_update(RoomsListUpdate::LoadedRooms { max_rooms: maximum_number_of_rooms }, true);
}
}
}
Expand Down

0 comments on commit 5a7412f

Please sign in to comment.