Skip to content

Commit

Permalink
Merge pull request #93 from kevinaboos/immutable_borrow_find_widgets
Browse files Browse the repository at this point in the history
Use new Makepad version to reduce/remove clones and mutable pre-borrows
  • Loading branch information
kevinaboos authored Jul 23, 2024
2 parents 46b6d8d + 6841917 commit d5621df
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 45 deletions.
62 changes: 31 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions src/profile/user_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,30 +626,33 @@ impl Widget for UserProfileSlidingPane {
// Apply this update to the current user profile pane (if relevant).
if let Some(our_info) = self.info.as_mut() {
let val = update.apply_to_current_pane(our_info);
log!("Applied user profile update to current pane, returned {}", val);
redraw_this_pane |= val;
}
// Insert the updated info into the cache
update.apply_to_cache(cache);
}

// TODO: it's probably better to re-fetch the user profile info from the cache here
// just once, after all updates have been processed, instead of doing it
// repeatedly for each update.
// That also has the side benefit of avoiding a timing issue where a UI Signal
// does not happend at the same time as a user profile element being fetched,
// such as an avatar coming in later after the Signal has already been handled.
});
}

if redraw_this_pane {
log!("Redrawing user profile pane due to user profile update");
// log!("Redrawing user profile pane due to user profile update");
self.redraw(cx);
}

let copy_link_to_user_button = self.button(id!(copy_link_to_user_button));
let ignore_user_button = self.button(id!(ignore_user_button));

let Some(info) = self.info.as_ref() else { return };

if let Event::Actions(actions) = event {

// TODO: handle actions for the `direct_message_button`

if copy_link_to_user_button.clicked(actions) {
if self.button(id!(copy_link_to_user_button)).clicked(actions) {
let matrix_to_uri = info.user_id.matrix_to_uri().to_string();
cx.copy_to_clipboard(&matrix_to_uri);
// TODO: show a toast message instead of a log message
Expand All @@ -662,7 +665,7 @@ impl Widget for UserProfileSlidingPane {

// The `ignore_user_button` require room membership info.
if let Some(room_member) = info.room_member.as_ref() {
if ignore_user_button.clicked(actions) {
if self.button(id!(ignore_user_button)).clicked(actions) {
submit_async_request(MatrixRequest::IgnoreUser {
ignore: !room_member.is_ignored(),
room_id: info.room_id.clone(),
Expand All @@ -679,11 +682,11 @@ impl Widget for UserProfileSlidingPane {


fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
let Some(info) = self.info.clone() else {
self.visible = true;
let Some(info) = self.info.as_ref() else {
self.visible = false;
return self.view.draw_walk(cx, scope, walk);
};
self.visible = true;

// Set the user name, using the user ID as a fallback.
self.label(id!(user_name)).set_text(info.displayable_name());
Expand Down
2 changes: 1 addition & 1 deletion src/shared/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl WidgetNode for Modal {
self.view.redraw(cx);
}

fn find_widgets(&mut self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
fn find_widgets(&self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
self.view.find_widgets(path, cached, results);
}
}
4 changes: 2 additions & 2 deletions src/shared/portal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl WidgetNode for PortalView {
self.view.redraw(cx);
}

fn find_widgets(&mut self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
fn find_widgets(&self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
self.view.find_widgets(path, cached, results);
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ impl WidgetNode for Portal {
}
}

fn find_widgets(&mut self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
fn find_widgets(&self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
self.view.find_widgets(path, cached, results);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ async fn timeline_subscriber_handler(

let send_update = |timeline_items: Vector<Arc<TimelineItem>>, changed_indices: Range<usize>, clear_cache: bool, num_updates: usize| {
if num_updates > 0 {
log!("timeline_subscriber: applied {num_updates} updates for room {room_id}, timeline now has {} items. Clear cache? {clear_cache}. Changes: {changed_indices:?}.", timeline_items.len());
// log!("timeline_subscriber: applied {num_updates} updates for room {room_id}, timeline now has {} items. Clear cache? {clear_cache}. Changes: {changed_indices:?}.", timeline_items.len());
sender.send(TimelineUpdate::NewItems {
items: timeline_items,
changed_indices,
Expand All @@ -849,7 +849,7 @@ async fn timeline_subscriber_handler(
}
};

const LOG_DIFFS: bool = true;
const LOG_DIFFS: bool = false;

while let Some(batch) = subscriber.next().await {
let mut num_updates = 0;
Expand Down

0 comments on commit d5621df

Please sign in to comment.