Skip to content

Commit 4f5552d

Browse files
committed
Added notify to ensure room is open for scroll to message
1 parent 7d43c68 commit 4f5552d

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

src/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,11 @@ impl MatchEvent for App {
241241
cx.action(MainDesktopUiAction::LoadDockFromAppState);
242242
}
243243

244-
if let RoomsListAction::Selected(selected_room, _) = action.as_widget_action().cast() {
244+
if let RoomsListAction::Selected(selected_room) = action.as_widget_action().cast() {
245245
// A room has been selected, update the app state and navigate to the main content view.
246246
let display_name = room_name_or_id(selected_room.room_name(), selected_room.room_id());
247247
self.app_state.selected_room = Some(selected_room);
248+
248249
// Set the Stack Navigation header to show the name of the newly-selected room.
249250
self.ui
250251
.label(id!(main_content_view.header.content.title_container.title))
@@ -424,7 +425,7 @@ impl AppMain for App {
424425

425426
// Forward events to the MatchEvent trait implementation.
426427
self.match_event(cx, event);
427-
let scope = &mut Scope::with_data(&mut self.app_state);
428+
let scope: &mut Scope<'_, '_> = &mut Scope::with_data(&mut self.app_state);
428429
self.ui.handle_event(cx, event, scope);
429430

430431
/*

src/home/main_desktop_ui.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use makepad_widgets::*;
22
use matrix_sdk::ruma::OwnedRoomId;
3-
use std::collections::HashMap;
3+
use tokio::sync::Notify;
4+
use std::{collections::HashMap, sync::Arc};
45

56
use crate::{app::{AppState, AppStateAction, SelectedRoom}, shared::message_search_input_bar::{MessageSearchAction, MessageSearchInputBarRef}, utils::room_name_or_id};
67
use super::{invite_screen::InviteScreenWidgetRefExt, room_screen::RoomScreenWidgetRefExt, rooms_list::RoomsListAction};
@@ -338,13 +339,14 @@ impl WidgetMatchEvent for MainDesktopUI {
338339

339340
// Handle RoomsList actions, which are updates from the rooms list.
340341
match widget_action.cast() {
341-
RoomsListAction::Selected(selected_room, notify) => {
342+
RoomsListAction::Selected(selected_room) => {
342343
// Note that this cannot be performed within draw_walk() as the draw flow prevents from
343344
// performing actions that would trigger a redraw, and the Dock internally performs (and expects)
344345
// a redraw to be happening in order to draw the tab content.
345346
self.focus_or_create_tab(cx, selected_room);
346-
if let Some(notify) = notify {
347-
notify.notify_one(); // Notify the waiting task that the room has been focused.
347+
if cx.has_global::<Arc<Notify>>() {
348+
let notify = cx.get_global::<Arc<Notify>>();
349+
notify.notify_one();
348350
}
349351
}
350352
RoomsListAction::InviteAccepted { room_id, room_name } => {

src/home/main_mobile_ui.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
use makepad_widgets::*;
23

34
use crate::{
@@ -54,7 +55,7 @@ impl Widget for MainMobileUI {
5455
for action in actions {
5556
match action.as_widget_action().cast() {
5657
// This is currently handled in the top-level App.
57-
RoomsListAction::Selected(_selected_room, _) => {}
58+
RoomsListAction::Selected(_selected_room) => { }
5859
// Because the MainMobileUI is drawn based on the AppState only,
5960
// all we need to do is update the AppState here.
6061
RoomsListAction::InviteAccepted { room_id, .. } => {
@@ -85,7 +86,7 @@ impl Widget for MainMobileUI {
8586
// Get a reference to the `RoomScreen` widget and tell it which room's data to show.
8687
self.view
8788
.room_screen(id!(room_screen))
88-
.set_displayed_room(cx, room_id.clone().into(), room_name.clone());
89+
.set_displayed_room(cx, room_id.clone().into(), room_name.clone());
8990
}
9091
Some(SelectedRoom::InvitedRoom { room_id, room_name }) => {
9192
show_welcome = false;

src/home/room_screen.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,6 @@ impl Widget for RoomScreen {
14031403
TimelineItemContent::MsgLike(msg_like_content) => match &msg_like_content.kind {
14041404
MsgLikeKind::Message(_) | MsgLikeKind::Sticker(_) => {
14051405
let prev_event = tl_idx.checked_sub(1).and_then(|i| tl_items.get(i));
1406-
println!("msg_like_content {:?}", msg_like_content.as_message().unwrap().body());
14071406
populate_message_view(
14081407
cx,
14091408
list,
@@ -2673,6 +2672,10 @@ impl RoomScreen {
26732672
});
26742673

26752674
self.show_timeline(cx);
2675+
if cx.has_global::<Arc<Notify>>() {
2676+
let notify = cx.get_global::<Arc<Notify>>();
2677+
notify.notify_one();
2678+
}
26762679
}
26772680

26782681
/// Sends read receipts based on the current scroll position of the timeline.
@@ -3639,7 +3642,6 @@ pub fn populate_text_message_content(
36393642
if let Some(fb) = formatted_body.as_ref()
36403643
.and_then(|fb| (fb.format == MessageFormat::Html).then_some(fb))
36413644
{
3642-
println!("fb.body {:?}", fb.body);
36433645
message_content_widget.show_html(
36443646
cx,
36453647
utils::linkify(
@@ -4445,10 +4447,15 @@ impl Widget for Message {
44454447
room_name,
44464448
};
44474449
let notify = Arc::new(Notify::new());
4450+
if !cx.has_global::<Arc<Notify>>() {
4451+
cx.set_global(notify.clone());
4452+
} else {
4453+
*(cx.get_global()) = notify.clone();
4454+
}
44484455
cx.widget_action(
44494456
self.widget_uid(),
44504457
&scope.path,
4451-
RoomsListAction::Selected(target_selected_room, Some(notify.clone()))
4458+
RoomsListAction::Selected(target_selected_room)
44524459
);
44534460
submit_async_request(MatrixRequest::WaitForRoomOpenToJump { notify, room_id: jump_request.room_id.clone(), event_id: jump_request.event_id.clone() });
44544461
}

src/home/rooms_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn enqueue_rooms_list_update(update: RoomsListUpdate) {
159159
#[derive(Debug, Clone, DefaultNone)]
160160
pub enum RoomsListAction {
161161
/// A new room was selected.
162-
Selected(SelectedRoom, Option<Arc<tokio::sync::Notify>>),
162+
Selected(SelectedRoom),
163163
/// A new room was joined from an accepted invite,
164164
/// meaning that the existing `InviteScreen` should be converted
165165
/// to a `RoomScreen` to display now-joined room.
@@ -787,7 +787,7 @@ impl Widget for RoomsList {
787787
cx.widget_action(
788788
self.widget_uid(),
789789
&scope.path,
790-
RoomsListAction::Selected(new_selected_room, None),
790+
RoomsListAction::Selected(new_selected_room),
791791
);
792792
self.redraw(cx);
793793
}

src/right_panel/search_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
rooms_list::RoomsListRef,
2626
},
2727
shared::{
28-
avatar::AvatarWidgetRefExt, html_or_plaintext::HtmlOrPlaintextWidgetRefExt, message_search_input_bar::{MessageSearchAction, MessageSearchInputBarRef}, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, styles::COLOR_WARNING_YELLOW, timestamp::TimestampWidgetRefExt
28+
avatar::AvatarWidgetRefExt, html_or_plaintext::HtmlOrPlaintextWidgetRefExt, message_search_input_bar::{MessageSearchAction, MessageSearchInputBarRef}, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, timestamp::TimestampWidgetRefExt
2929
},
3030
sliding_sync::{submit_async_request, MatrixRequest},
3131
utils::unix_time_millis_to_datetime,

src/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ pub const MEDIA_THUMBNAIL_FORMAT: MediaFormatConst = MediaFormatConst::Thumbnail
330330
}
331331
);
332332

333-
/// Removes leading whitespace and HTML whitespace tags (`<p>` and `<br>`) from the given `text`.
333+
/// Removes leading whitespace and HTML whitespace tags (`<mx-reply>`, `<p>` and `<br>`) from the given `text`.
334334
pub fn trim_start_html_whitespace(mut text: &str) -> &str {
335335
let mut prev_text_len = text.len();
336336
loop {
337337
text = text
338+
.trim_start_matches("<mx-reply>")
338339
.trim_start_matches("<p>")
339340
.trim_start_matches("<br>")
340341
.trim_start_matches("<br/>")

0 commit comments

Comments
 (0)