Skip to content

Commit 4c1435d

Browse files
authored
Merge pull request #596 from kevinaboos/simplify_tombstone_room_footer
2 parents e42b82c + 5a1a19a commit 4c1435d

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/home/room_screen.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,9 @@ impl RoomScreen {
14271427

14281428
let mut done_loading = false;
14291429
let mut should_continue_backwards_pagination = false;
1430-
let mut num_updates = 0;
14311430
let mut typing_users = None;
1431+
let mut did_tombstone_change = false;
1432+
let mut num_updates = 0;
14321433
while let Ok(update) = tl.update_receiver.try_recv() {
14331434
num_updates += 1;
14341435
match update {
@@ -1695,14 +1696,10 @@ impl RoomScreen {
16951696
tl.latest_own_user_receipt = Some(receipt);
16961697
}
16971698
TimelineUpdate::Tombstoned(tombstone_info) => {
1698-
if let Some(tombstone_info) = &tombstone_info {
1699-
self.view.tombstone_footer(id!(tombstone_footer)).show(cx, &tl.room_id, tombstone_info);
1700-
self.view.view(id!(message_input_view)).set_visible(cx, false);
1701-
} else {
1702-
self.view.tombstone_footer(id!(tombstone_footer)).hide(cx);
1703-
self.view.view(id!(message_input_view)).set_visible(cx, true);
1704-
}
17051699
tl.tombstone_info = tombstone_info;
1700+
// Because `tl` borrows `self` here, we can't call `self.show_tombstone_footer()`
1701+
// until later when the borrow ends.
1702+
did_tombstone_change = true;
17061703
}
17071704
}
17081705
}
@@ -1725,6 +1722,10 @@ impl RoomScreen {
17251722
.show_or_hide(cx, &users);
17261723
}
17271724

1725+
if did_tombstone_change {
1726+
self.update_tombstone_footer(cx);
1727+
}
1728+
17281729
if num_updates > 0 {
17291730
// log!("Applied {} timeline updates for room {}, redrawing with {} items...", num_updates, tl.room_id, tl.items.len());
17301731
self.redraw(cx);
@@ -2378,13 +2379,13 @@ impl RoomScreen {
23782379
// Now, restore the visual state of this timeline from its previously-saved state.
23792380
self.restore_state(cx, &mut tl_state);
23802381

2381-
// Show or hide the tombstone footer based on the timeline's UI state.
2382-
self.show_tombstone_footer(cx, &tl_state);
2383-
2384-
// As the final step, store the tl_state for this room into this RoomScreen widget,
2385-
// such that it can be accessed in future event/draw handlers.
2382+
// Store the tl_state for this room into this RoomScreen widget,
2383+
// such that it can be accessed in future functions like event/draw handlers.
23862384
self.tl_state = Some(tl_state);
23872385

2386+
// Show or hide the tombstone footer based on the timeline's UI state.
2387+
self.update_tombstone_footer(cx);
2388+
23882389
// Now that we have restored the TimelineUiState into this RoomScreen widget,
23892390
// we can proceed to processing pending background updates.
23902391
self.process_timeline_updates(cx, &self.portal_list(id!(list)));
@@ -2608,16 +2609,17 @@ impl RoomScreen {
26082609
tl.last_scrolled_index = first_index;
26092610
}
26102611

2611-
/// If the current room is tombstoned, show the tombstone footer and hide the message input bar.
2612-
/// Otherwise, hide the tombstone footer and show the message input bar.
2613-
fn show_tombstone_footer(&mut self, cx: &mut Cx, tl_state: &TimelineUiState) {
2614-
if let Some(tombstone_info) = &tl_state.tombstone_info {
2615-
self.view.tombstone_footer(id!(tombstone_footer)).show(cx, &tl_state.room_id, tombstone_info);
2616-
self.view.view(id!(message_input_view)).set_visible(cx, false);
2617-
} else {
2618-
self.view.tombstone_footer(id!(tombstone_footer)).hide(cx);
2619-
self.view.view(id!(message_input_view)).set_visible(cx, true);
2612+
/// Updates this room's tombstone footer visibility based on the timeline's tombstoned state.
2613+
fn update_tombstone_footer(&self, cx: &mut Cx) {
2614+
if let Some(tl_state) = self.tl_state.as_ref() {
2615+
if let Some(tombstone_info) = &tl_state.tombstone_info {
2616+
self.view.tombstone_footer(id!(tombstone_footer)).show(cx, &tl_state.room_id, tombstone_info);
2617+
self.view.view(id!(message_input_view)).set_visible(cx, false);
2618+
return;
2619+
}
26202620
}
2621+
self.view.tombstone_footer(id!(tombstone_footer)).hide(cx);
2622+
self.view.view(id!(message_input_view)).set_visible(cx, true);
26212623
}
26222624
}
26232625

src/home/tombstone_footer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,10 @@ impl TombstoneFooter {
190190
});
191191
}
192192

193-
/// Hides the tombstone footer, making it invisible and clearing any successor room information.
193+
/// Hides the tombstone footer and clears any successor room information.
194194
fn hide(&mut self, cx: &mut Cx) {
195195
self.set_visible(cx, false);
196196
self.successor_info = None;
197-
self.view
198-
.label_set(ids![replacement_reason, successor_room_name])
199-
.set_text(cx, "");
200197
}
201198
}
202199

0 commit comments

Comments
 (0)