Skip to content

Commit e05e6d0

Browse files
authored
Merge pull request #619 from kevinaboos/fetch_room_previews_dynamically
2 parents faeb999 + 9a6cfdc commit e05e6d0

11 files changed

Lines changed: 420 additions & 199 deletions

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl App {
571571
return;
572572
}
573573

574-
log!("Navigating to destination room: {}, closing room {room_to_close:?}", destination_room.room_id);
574+
log!("Navigating to destination room {} ({:?}), closing room {room_to_close:?}", destination_room.room_id, destination_room.room_name);
575575

576576
// Select and scroll to the destination room in the rooms list.
577577
let new_selected_room = SelectedRoom::JoinedRoom {

src/home/invite_screen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::Deref;
88
use makepad_widgets::*;
99
use matrix_sdk::ruma::OwnedRoomId;
1010

11-
use crate::{app::AppStateAction, home::rooms_list::RoomsListRef, join_leave_room_modal::{JoinLeaveModalKind, JoinLeaveRoomModalAction}, room::{BasicRoomDetails, RoomPreviewAvatar}, shared::{avatar::AvatarWidgetRefExt, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, restore_status_view::RestoreStatusViewWidgetExt}, sliding_sync::{submit_async_request, MatrixRequest}, utils::{self, room_name_or_id}};
11+
use crate::{app::AppStateAction, home::rooms_list::RoomsListRef, join_leave_room_modal::{JoinLeaveModalKind, JoinLeaveRoomModalAction}, room::{BasicRoomDetails, FetchedRoomAvatar}, shared::{avatar::AvatarWidgetRefExt, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, restore_status_view::RestoreStatusViewWidgetExt}, sliding_sync::{submit_async_request, MatrixRequest}, utils::{self, room_name_or_id}};
1212

1313
use super::rooms_list::{InviteState, InviterInfo};
1414

@@ -451,15 +451,15 @@ impl Widget for InviteScreen {
451451
let room_view = self.view.view(id!(room_view));
452452
let room_avatar = room_view.avatar(id!(room_avatar));
453453
match &info.room_avatar {
454-
RoomPreviewAvatar::Text(text) => {
454+
FetchedRoomAvatar::Text(text) => {
455455
room_avatar.show_text(
456456
cx,
457457
None,
458458
None, // don't make this avatar clickable.
459459
text,
460460
);
461461
}
462-
RoomPreviewAvatar::Image(avatar_bytes) => {
462+
FetchedRoomAvatar::Image(avatar_bytes) => {
463463
let _ = room_avatar.show_image(
464464
cx,
465465
None, // don't make this avatar clickable.

src/home/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ pub mod loading_pane;
1010
pub mod location_preview;
1111
pub mod main_desktop_ui;
1212
pub mod main_mobile_ui;
13-
pub mod room_preview;
1413
pub mod room_screen;
1514
pub mod room_read_receipt;
1615
pub mod rooms_list;
16+
pub mod rooms_list_entry;
1717
pub mod rooms_list_header;
1818
pub mod rooms_sidebar;
1919
pub mod spaces_dock;
@@ -26,9 +26,9 @@ pub fn live_design(cx: &mut Cx) {
2626
home_screen::live_design(cx);
2727
loading_pane::live_design(cx);
2828
location_preview::live_design(cx);
29-
rooms_list::live_design(cx);
29+
rooms_list_entry::live_design(cx);
3030
rooms_list_header::live_design(cx);
31-
room_preview::live_design(cx);
31+
rooms_list::live_design(cx);
3232
edited_indicator::live_design(cx);
3333
editing_pane::live_design(cx);
3434
new_message_context_menu::live_design(cx);

src/home/room_screen.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use matrix_sdk::{
1919
sticker::{StickerEventContent, StickerMediaSource},
2020
},
2121
matrix_uri::MatrixId, uint, EventId, MatrixToUri, MatrixUri, OwnedEventId, OwnedMxcUri, OwnedRoomId, UserId
22-
}, OwnedServerName, SuccessorRoom
22+
}, OwnedServerName
2323
};
2424
use matrix_sdk_ui::timeline::{
2525
self, EmbeddedEvent, EncryptedMessage, EventTimelineItem, InReplyToDetails, MemberProfileChange, MsgLikeContent, MsgLikeKind, OtherMessageLike, PollState, RoomMembershipChange, TimelineDetails, TimelineEventItemId, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem
2626
};
2727

2828
use crate::{
29-
app::AppStateAction, avatar_cache, event_preview::{plaintext_body_of_timeline_item, text_preview_of_encrypted_message, text_preview_of_member_profile_change, text_preview_of_other_message_like, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, home::{edited_indicator::EditedIndicatorWidgetRefExt, link_preview::{LinkPreviewCache, LinkPreviewRef, LinkPreviewWidgetRefExt}, loading_pane::{LoadingPaneState, LoadingPaneWidgetExt}, rooms_list::RoomsListRef}, media_cache::{MediaCache, MediaCacheEntry}, profile::{
29+
app::AppStateAction, avatar_cache, event_preview::{plaintext_body_of_timeline_item, text_preview_of_encrypted_message, text_preview_of_member_profile_change, text_preview_of_other_message_like, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, home::{edited_indicator::EditedIndicatorWidgetRefExt, link_preview::{LinkPreviewCache, LinkPreviewRef, LinkPreviewWidgetRefExt}, loading_pane::{LoadingPaneState, LoadingPaneWidgetExt}, rooms_list::RoomsListRef, tombstone_footer::SuccessorRoomDetails}, media_cache::{MediaCache, MediaCacheEntry}, profile::{
3030
user_profile::{AvatarState, ShowUserProfileAction, UserProfile, UserProfileAndRoomId, UserProfilePaneInfo, UserProfileSlidingPaneRef, UserProfileSlidingPaneWidgetExt},
3131
user_profile_cache,
3232
},
@@ -1393,10 +1393,10 @@ impl RoomScreen {
13931393
TimelineUpdate::OwnUserReadReceipt(receipt) => {
13941394
tl.latest_own_user_receipt = Some(receipt);
13951395
}
1396-
TimelineUpdate::Tombstoned(successor_room) => {
1396+
TimelineUpdate::Tombstoned(successor_room_details) => {
13971397
self.view.room_input_bar(id!(room_input_bar))
1398-
.update_tombstone_footer(cx, &tl.room_id, successor_room.as_ref());
1399-
tl.tombstone_info = successor_room;
1398+
.update_tombstone_footer(cx, &tl.room_id, Some(&successor_room_details));
1399+
tl.tombstone_info = Some(successor_room_details);
14001400
}
14011401
}
14021402
}
@@ -1954,6 +1954,17 @@ impl RoomScreen {
19541954
successor_room,
19551955
} = timeline_endpoints;
19561956

1957+
// Start with the basic tombstone info, and fetch the full details
1958+
// if the room has been tombstoned.
1959+
let tombstone_info = if let Some(sr) = successor_room {
1960+
submit_async_request(MatrixRequest::GetSuccessorRoomDetails {
1961+
tombstoned_room_id: room_id.clone(),
1962+
});
1963+
Some(SuccessorRoomDetails::Basic(sr))
1964+
} else {
1965+
None
1966+
};
1967+
19571968
let tl_state = TimelineUiState {
19581969
room_id: room_id.clone(),
19591970
// Initially, we assume the user has all power levels by default.
@@ -1978,7 +1989,7 @@ impl RoomScreen {
19781989
prev_first_index: None,
19791990
scrolled_past_read_marker: false,
19801991
latest_own_user_receipt: None,
1981-
tombstone_info: successor_room,
1992+
tombstone_info,
19821993
};
19831994
(tl_state, true)
19841995
};
@@ -2147,6 +2158,7 @@ impl RoomScreen {
21472158
cx,
21482159
&tl_state.room_id,
21492160
saved_room_input_bar_state,
2161+
tl_state.user_power,
21502162
tl_state.tombstone_info.as_ref(),
21512163
);
21522164
}
@@ -2168,7 +2180,7 @@ impl RoomScreen {
21682180
self.room_id = Some(room_id.clone());
21692181

21702182
// We initially tell every MentionableTextInput widget that the current user
2171-
// *does not* has privileges to notify the entire room;
2183+
// *does not* have privileges to notify the entire room;
21722184
// this gets properly updated when room PowerLevels get fetched.
21732185
cx.action(MentionableTextInputAction::PowerLevelsUpdated {
21742186
room_id: room_id.clone(),
@@ -2418,10 +2430,9 @@ pub enum TimelineUpdate {
24182430
UserPowerLevels(UserPowerLevels),
24192431
/// An update to the currently logged-in user's own read receipt for this room.
24202432
OwnUserReadReceipt(Receipt),
2421-
/// A notice that the given room has been tombstoned,
2422-
/// includes a `SuccessorRoom` that contains the successor room.
2423-
/// If the room is not tombstoned, then the `SuccessorRoom` is `None`.
2424-
Tombstoned(Option<SuccessorRoom>),
2433+
/// A notice that the given room has been tombstoned (closed)
2434+
/// and replaced by the given successor room.
2435+
Tombstoned(SuccessorRoomDetails),
24252436
}
24262437

24272438
thread_local! {
@@ -2534,9 +2545,9 @@ struct TimelineUiState {
25342545
scrolled_past_read_marker: bool,
25352546
latest_own_user_receipt: Option<Receipt>,
25362547

2537-
/// If this room has been tombstoned, this has details of its successor room.
2538-
/// If the room is not tombstoned, this is `None`.
2539-
tombstone_info: Option<SuccessorRoom>,
2548+
/// If `Some`, this room has been tombstoned and the details of its successor room
2549+
/// are contained within. If `None`, the room has not been tombstoned.
2550+
tombstone_info: Option<SuccessorRoomDetails>,
25402551
}
25412552

25422553
#[derive(Default, Debug)]

src/home/rooms_list.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use makepad_widgets::*;
44
use matrix_sdk::{ruma::{events::tag::Tags, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId, OwnedRoomId, OwnedUserId}, RoomState};
55
use crate::{
66
app::{AppState, SelectedRoom},
7-
room::{room_display_filter::{RoomDisplayFilter, RoomDisplayFilterBuilder, RoomFilterCriteria, SortFn}, RoomPreviewAvatar},
7+
room::{room_display_filter::{RoomDisplayFilter, RoomDisplayFilterBuilder, RoomFilterCriteria, SortFn}, FetchedRoomAvatar},
88
shared::{collapsible_header::{CollapsibleHeaderAction, CollapsibleHeaderWidgetRefExt, HeaderCategory}, jump_to_bottom_button::UnreadMessageCount, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, room_filter_input_bar::RoomFilterAction},
99
sliding_sync::{submit_async_request, MatrixRequest, PaginationDirection}, utils::room_name_or_id,
1010
};
11-
use super::room_preview::RoomPreviewAction;
11+
use super::rooms_list_entry::RoomsListEntryAction;
1212

1313
/// Whether to pre-paginate visible rooms at least once in order to
14-
/// be able to display the latest message in the room preview,
14+
/// be able to display the latest message in a room's RoomsListEntry,
1515
/// and to have something to immediately show when a user first opens a room.
1616
const PREPAGINATE_VISIBLE_ROOMS: bool = true;
1717

@@ -54,7 +54,7 @@ live_design! {
5454
use crate::shared::avatar::Avatar;
5555
use crate::shared::html_or_plaintext::HtmlOrPlaintext;
5656
use crate::shared::collapsible_header::*;
57-
use crate::home::room_preview::*;
57+
use crate::home::rooms_list_entry::*;
5858

5959
StatusLabel = <View> {
6060
width: Fill, height: Fit,
@@ -86,7 +86,7 @@ live_design! {
8686
flow: Down, spacing: 0.0
8787

8888
collapsible_header = <CollapsibleHeader> {}
89-
room_preview = <RoomPreview> {}
89+
rooms_list_entry = <RoomsListEntry> {}
9090
empty = <View> {}
9191
status_label = <StatusLabel> {}
9292
bottom_filler = <View> {
@@ -137,7 +137,7 @@ pub enum RoomsListUpdate {
137137
/// Update the avatar (image) for the given room.
138138
UpdateRoomAvatar {
139139
room_id: OwnedRoomId,
140-
avatar: RoomPreviewAvatar,
140+
avatar: FetchedRoomAvatar,
141141
},
142142
/// Update whether the given room is a direct room.
143143
UpdateIsDirect {
@@ -218,10 +218,10 @@ pub struct JoinedRoomInfo {
218218
pub latest: Option<(MilliSecondsSinceUnixEpoch, String)>,
219219
/// The avatar for this room: either an array of bytes holding the avatar image
220220
/// or a string holding the first Unicode character of the room name.
221-
pub avatar: RoomPreviewAvatar,
221+
pub avatar: FetchedRoomAvatar,
222222
/// Whether this room has been paginated at least once.
223223
/// We pre-paginate visible rooms at least once in order to
224-
/// be able to display the latest message in the room preview,
224+
/// be able to display the latest message in the RoomsListEntry
225225
/// and to have something to immediately show when a user first opens a room.
226226
pub has_been_paginated: bool,
227227
/// Whether this room is currently selected in the UI.
@@ -247,7 +247,7 @@ pub struct InvitedRoomInfo {
247247
pub alt_aliases: Vec<OwnedRoomAliasId>,
248248
/// The avatar for this room: either an array of bytes holding the avatar image
249249
/// or a string holding the first Unicode character of the room name.
250-
pub room_avatar: RoomPreviewAvatar,
250+
pub room_avatar: FetchedRoomAvatar,
251251
/// Info about the user who invited us to this room, if available.
252252
pub inviter_info: Option<InviterInfo>,
253253
/// The timestamp and Html text content of the latest message in this room.
@@ -309,7 +309,7 @@ pub struct RoomsList {
309309
/// This is a shared reference to the thread-local [`ALL_INVITED_ROOMS`] variable.
310310
#[rust] invited_rooms: Rc<RefCell<HashMap<OwnedRoomId, InvitedRoomInfo>>>,
311311

312-
/// The set of all joined rooms and their cached preview info.
312+
/// The set of all joined rooms and their cached info.
313313
/// This includes both direct rooms and regular rooms.
314314
#[rust] all_joined_rooms: HashMap<OwnedRoomId, JoinedRoomInfo>,
315315

@@ -828,16 +828,6 @@ impl RoomsList {
828828
regular_rooms_indexes,
829829
)
830830
}
831-
832-
/// Returns a room's avatar and displayable name.
833-
pub fn get_room_avatar_and_name(&self, room_id: &OwnedRoomId) -> Option<(RoomPreviewAvatar, Option<String>)> {
834-
self.all_joined_rooms.get(room_id)
835-
.map(|room_info| (room_info.avatar.clone(), room_info.room_name.clone()))
836-
.or_else(|| {
837-
self.invited_rooms.borrow().get(room_id)
838-
.map(|room_info| (room_info.room_avatar.clone(), room_info.room_name.clone()))
839-
})
840-
}
841831
}
842832

843833
impl Widget for RoomsList {
@@ -856,7 +846,7 @@ impl Widget for RoomsList {
856846
|cx| self.view.handle_event(cx, event, &mut Scope::with_props(&props))
857847
);
858848
for list_action in list_actions {
859-
if let RoomPreviewAction::Clicked(clicked_room_id) = list_action.as_widget_action().cast() {
849+
if let RoomsListEntryAction::Clicked(clicked_room_id) = list_action.as_widget_action().cast() {
860850
let new_selected_room = if let Some(jr) = self.all_joined_rooms.get(&clicked_room_id) {
861851
SelectedRoom::JoinedRoom {
862852
room_id: jr.room_id.clone().into(),
@@ -970,10 +960,10 @@ impl Widget for RoomsList {
970960
else if let Some(invited_room_id) = get_invited_room_id(portal_list_index) {
971961
let mut invited_rooms_mut = self.invited_rooms.borrow_mut();
972962
if let Some(invited_room) = invited_rooms_mut.get_mut(invited_room_id) {
973-
let item = list.item(cx, portal_list_index, live_id!(room_preview));
963+
let item = list.item(cx, portal_list_index, live_id!(rooms_list_entry));
974964
invited_room.is_selected =
975965
self.current_active_room.as_deref() == Some(invited_room_id);
976-
// Pass the room info down to the RoomPreview widget via Scope.
966+
// Pass the room info down to the RoomsListEntry widget via Scope.
977967
scope = Scope::with_props(&*invited_room);
978968
item.draw_all(cx, &mut scope);
979969
} else {
@@ -995,7 +985,7 @@ impl Widget for RoomsList {
995985
}
996986
else if let Some(direct_room_id) = get_direct_room_id(portal_list_index) {
997987
if let Some(direct_room) = self.all_joined_rooms.get_mut(direct_room_id) {
998-
let item = list.item(cx, portal_list_index, live_id!(room_preview));
988+
let item = list.item(cx, portal_list_index, live_id!(rooms_list_entry));
999989
direct_room.is_selected =
1000990
self.current_active_room.as_ref() == Some(direct_room_id);
1001991

@@ -1008,7 +998,7 @@ impl Widget for RoomsList {
1008998
direction: PaginationDirection::Backwards,
1009999
});
10101000
}
1011-
// Pass the room info down to the RoomPreview widget via Scope.
1001+
// Pass the room info down to the RoomsListEntry widget via Scope.
10121002
scope = Scope::with_props(&*direct_room);
10131003
item.draw_all(cx, &mut scope);
10141004
} else {
@@ -1030,7 +1020,7 @@ impl Widget for RoomsList {
10301020
}
10311021
else if let Some(regular_room_id) = get_regular_room_id(portal_list_index) {
10321022
if let Some(regular_room) = self.all_joined_rooms.get_mut(regular_room_id) {
1033-
let item = list.item(cx, portal_list_index, live_id!(room_preview));
1023+
let item = list.item(cx, portal_list_index, live_id!(rooms_list_entry));
10341024
regular_room.is_selected =
10351025
self.current_active_room.as_ref() == Some(regular_room_id);
10361026

@@ -1043,7 +1033,7 @@ impl Widget for RoomsList {
10431033
direction: PaginationDirection::Backwards,
10441034
});
10451035
}
1046-
// Pass the room info down to the RoomPreview widget via Scope.
1036+
// Pass the room info down to the RoomsListEntry widget via Scope.
10471037
scope = Scope::with_props(&*regular_room);
10481038
item.draw_all(cx, &mut scope);
10491039
} else {
@@ -1087,13 +1077,8 @@ impl RoomsListRef {
10871077
};
10881078
inner.is_room_loaded(room_id)
10891079
}
1090-
1091-
/// See [`RoomsList::get_room_avatar_and_name()`].
1092-
pub fn get_room_avatar_and_name(&self, room_id: &OwnedRoomId) -> Option<(RoomPreviewAvatar, Option<String>)> {
1093-
let inner = self.borrow()?;
1094-
inner.get_room_avatar_and_name(room_id)
1095-
}
10961080
}
1081+
10971082
pub struct RoomsListScopeProps {
10981083
/// Whether the RoomsList's inner PortalList was scrolling
10991084
/// when the latest finger down event occurred.

0 commit comments

Comments
 (0)