Skip to content

Commit ca2ca78

Browse files
committed
move room_search_result underneath room_screen mod
1 parent 02b09db commit ca2ca78

7 files changed

+261
-205
lines changed

src/event_preview.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn plaintext_body_of_timeline_item(
151151
).text
152152
}
153153
TimelineItemContent::OtherState(other_state) => {
154-
text_preview_of_other_state(other_state.content(), true, other_state.state_key())
154+
text_preview_of_other_state(other_state.content(), false, other_state.state_key())
155155
.unwrap_or_else(|| TextPreview::from((
156156
String::from("initiated another state change."),
157157
BeforeText::UsernameWithoutColon,

src/home/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod main_mobile_ui;
1111
pub mod room_preview;
1212
pub mod room_screen;
1313
pub mod room_read_receipt;
14-
pub mod room_search_result;
1514
pub mod rooms_list;
1615
pub mod rooms_sidebar;
1716
pub mod spaces_dock;
@@ -29,7 +28,7 @@ pub fn live_design(cx: &mut Cx) {
2928
new_message_context_menu::live_design(cx);
3029
invite_screen::live_design(cx);
3130
room_screen::live_design(cx);
32-
room_search_result::live_design(cx);
31+
room_screen::search_result::live_design(cx);
3332
room_read_receipt::live_design(cx);
3433
rooms_sidebar::live_design(cx);
3534
main_mobile_ui::live_design(cx);

src/home/new_message_context_menu.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
use bitflags::bitflags;
55
use makepad_widgets::*;
66
use matrix_sdk::ruma::OwnedEventId;
7+
use matrix_sdk_ui::timeline::InReplyToDetails;
8+
use ruma::events::room::message::MessageType;
79

810
use crate::sliding_sync::UserPowerLevels;
911

10-
use super::room_screen::{Eventable, MessageAction, MessageOrSticker, MsgTypeAble};
12+
use super::room_screen::{MessageViewFromEvent, MessageAction, MessageOrSticker};
1113

1214
const BUTTON_HEIGHT: f64 = 35.0; // KEEP IN SYNC WITH BUTTON_HEIGHT BELOW
1315
const MENU_WIDTH: f64 = 215.0; // KEEP IN SYNC WITH MENU_WIDTH BELOW
@@ -246,7 +248,7 @@ bitflags! {
246248
}
247249
}
248250
impl MessageAbilities {
249-
pub fn from_user_power_and_event_generic<T: Eventable, M: MsgTypeAble>(
251+
pub fn from_user_power_and_event<T: MessageViewFromEvent, M: ContextMenuFromEvent>(
250252
user_power_levels: &UserPowerLevels,
251253
event_tl_item: &T,
252254
_message: &MessageOrSticker<M>,
@@ -618,3 +620,9 @@ impl NewMessageContextMenuRef {
618620
inner.show(cx, details)
619621
}
620622
}
623+
pub trait ContextMenuFromEvent {
624+
fn msgtype(&self) -> &MessageType;
625+
fn body(&self) -> &str;
626+
fn in_reply_to(&self) -> Option<&InReplyToDetails>;
627+
fn is_searched_result(&self) -> bool;
628+
}

src/home/room_read_receipt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use makepad_widgets::*;
77
use matrix_sdk::ruma::{events::receipt::Receipt, EventId, OwnedUserId, RoomId};
88
use std::cmp;
99

10-
use super::room_screen::Eventable;
10+
use super::room_screen::MessageViewFromEvent;
1111

1212

1313
/// The maximum number of items to display in the read receipts AvatarRow
@@ -226,7 +226,7 @@ impl AvatarRowRef {
226226
/// room ID, and an EventTimelineItem, this will populate the avatar
227227
/// row of the item with the read receipts of the event.
228228
///
229-
pub fn populate_read_receipts<T: Eventable>(
229+
pub fn populate_read_receipts<T: MessageViewFromEvent>(
230230
item: &WidgetRef,
231231
cx: &mut Cx,
232232
room_id: &RoomId,

src/home/room_screen.rs

Lines changed: 77 additions & 160 deletions
Large diffs are not rendered by default.

src/home/room_search_result.rs

Lines changed: 154 additions & 31 deletions
Large diffs are not rendered by default.

src/sliding_sync.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use matrix_sdk::{
1616
}, sliding_sync::VersionBuilder, Client, ClientBuildError, Error, OwnedServerName, Room, RoomMemberships, RoomState
1717
};
1818
use matrix_sdk_ui::{
19-
room_list_service::{self, RoomListLoadingState}, sync_service::{self, SyncService}, timeline::{AnyOtherFullStateEventContent, EventTimelineItem, MembershipChange, RepliedToInfo, TimelineEventItemId, TimelineItem, TimelineItemContent}, RoomListService, Timeline
19+
room_list_service::{self, RoomListLoadingState}, sync_service::{self, SyncService}, timeline::{AnyOtherFullStateEventContent, EventTimelineItem, MembershipChange, RepliedToInfo, TimelineDetails, TimelineEventItemId, TimelineItem, TimelineItemContent}, RoomListService, Timeline
2020
};
2121
use robius_open::Uri;
2222
use tokio::{
@@ -30,7 +30,7 @@ use std::io;
3030
use ruma::{api::client::{filter::RoomEventFilter, search::search_events::v3::{Criteria, EventContext, OrderBy, Request}}, events::AnyTimelineEvent, uint};
3131
use crate::{
3232
app_data_dir, avatar_cache::AvatarUpdate, event_preview::text_preview_of_timeline_item, home::{
33-
invite_screen::{JoinRoomAction, LeaveRoomAction}, room_screen::TimelineUpdate, room_search_result::SearchTimelineItem, rooms_list::{self, enqueue_rooms_list_update, InvitedRoomInfo, InviterInfo, JoinedRoomInfo, RoomPreviewAvatar, RoomsListUpdate}
33+
invite_screen::{JoinRoomAction, LeaveRoomAction}, room_screen::{TimelineUpdate, SearchTimelineItem}, rooms_list::{self, enqueue_rooms_list_update, InvitedRoomInfo, InviterInfo, JoinedRoomInfo, RoomPreviewAvatar, RoomsListUpdate}
3434
}, login::login_screen::LoginAction, media_cache::{MediaCacheEntry, MediaCacheEntryRef}, persistent_state::{self, ClientSessionPersisted}, profile::{
3535
user_profile::{AvatarState, UserProfile},
3636
user_profile_cache::{enqueue_user_profile_update, UserProfileUpdate},
@@ -382,7 +382,7 @@ pub enum MatrixRequest {
382382
matrix_id: MatrixId,
383383
via: Vec<OwnedServerName>
384384
},
385-
/// General Matrix Search API with given categorie
385+
/// General Matrix Search API with given categories
386386
SearchMessages {
387387
/// The room to search for message.
388388
room_id: OwnedRoomId,
@@ -838,7 +838,7 @@ async fn async_worker(
838838

839839
let _typing_notices_task = Handle::current().spawn(async move {
840840
while let Ok(user_ids) = typing_notice_receiver.recv().await {
841-
log!("Received typing notifications for room {room_id}: {user_ids:?}");
841+
//log!("Received typing notifications for room {room_id}: {user_ids:?}");
842842
let mut users = Vec::with_capacity(user_ids.len());
843843
for user_id in user_ids {
844844
users.push(
@@ -1148,8 +1148,16 @@ async fn async_worker(
11481148
let mut last_room_id = None;
11491149
let result = response.search_categories;
11501150
let mut items = vec![];
1151+
let mut profile_infos = BTreeMap::new();
11511152
for item in result.room_events.results.iter() {
11521153
let Some(event) = item.result.as_ref().and_then(|f|f.deserialize().ok()) else { continue };
1154+
for (user_id, profile) in item.context.profile_info.iter() {
1155+
profile_infos.entry(user_id.clone()).or_insert_with(|| TimelineDetails::Ready(matrix_sdk_ui::timeline::Profile{
1156+
display_name: profile.displayname.clone(),
1157+
display_name_ambiguous: false,
1158+
avatar_url:profile.avatar_url.clone()
1159+
}));
1160+
}
11531161
item.context.events_after.iter().rev().for_each(|f| {
11541162
if let Ok(timeline_event) = f.deserialize() {
11551163
items.push(SearchTimelineItem::ContextEvent(timeline_event));
@@ -1181,7 +1189,6 @@ async fn async_worker(
11811189
if last_room_id != &room_id {
11821190
*last_room_id = room_id.clone();
11831191
items.push(SearchTimelineItem::RoomHeader(room_id));
1184-
11851192
}
11861193
} else {
11871194
last_room_id = Some(room_id.clone());
@@ -1191,7 +1198,7 @@ async fn async_worker(
11911198
}
11921199
let count = result.room_events.count.and_then(|f| f.to_string().parse().ok()).unwrap_or(0);
11931200
let highlights = result.room_events.highlights;
1194-
if let Err(e) = sender.send(TimelineUpdate::SearchResultReceived { items, count, highlights, search_term: search_term.clone() }) {
1201+
if let Err(e) = sender.send(TimelineUpdate::SearchResultReceived { items, count, highlights, search_term: search_term.clone(), profile_infos }) {
11951202
error!("Failed to search message in {room_id}; error: {e:?}");
11961203
enqueue_popup_notification(format!("Failed to search message. Error: {e}"));
11971204
}
@@ -2865,6 +2872,8 @@ fn register_core_task(
28652872

28662873
async fn abort_core_task(core_task: CoreTask) {
28672874
if let Ok(mut tasks) = CORE_TASKS.lock() {
2868-
tasks.remove(&core_task);
2875+
if let Some(handle) = tasks.remove(&core_task) {
2876+
handle.abort();
2877+
}
28692878
}
28702879
}

0 commit comments

Comments
 (0)