Skip to content

Commit 36fbbbc

Browse files
committed
Added Sender Profile for search
1 parent 361ef38 commit 36fbbbc

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
lines changed

src/home/new_message_context_menu.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ impl WidgetMatchEvent for NewMessageContextMenu {
377377
close_menu = false;
378378
}
379379
else if self.button(id!(reply_button)).clicked(actions) {
380-
println!("clicked details {:?}", details);
381380
cx.widget_action(
382381
details.room_screen_widget_uid,
383382
&scope.path,

src/home/room_screen.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use matrix_sdk::{room::RoomMember, ruma::{
1717
sticker::StickerEventContent, Mentions}, matrix_uri::MatrixId, uint, EventId, MatrixToUri, MatrixUri, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomId
1818
}, OwnedServerName};
1919
use matrix_sdk_ui::timeline::{
20-
self, EventTimelineItem, InReplyToDetails, MemberProfileChange, ReactionsByKeyBySender, RepliedToInfo, RoomMembershipChange, TimelineDetails, TimelineEventItemId, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem
20+
self, EventTimelineItem, InReplyToDetails, MemberProfileChange, Profile, ReactionsByKeyBySender, RepliedToInfo, RoomMembershipChange, TimelineDetails, TimelineEventItemId, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem
2121
};
2222
use ruma::{OwnedUserId, UserId};
2323

@@ -1700,16 +1700,20 @@ impl RoomScreen {
17001700
TimelineUpdate::OwnUserReadReceipt(receipt) => {
17011701
tl.latest_own_user_receipt = Some(receipt);
17021702
}
1703-
TimelineUpdate::SearchResultReceived { items, count, highlights, search_term } => {
1703+
TimelineUpdate::SearchResultReceived { items, count, highlights, search_term, profile_infos } => {
17041704
let mut criteria = self.view.search_result(id!(search_result_plane)).get_search_criteria();
1705+
if criteria.search_term != search_term {
1706+
tl.search_result_state.items = Vector::new();
1707+
}
1708+
tl.search_result_state.profiles_info = profile_infos;
17051709
criteria.search_term = search_term;
17061710
self.view.search_result(id!(search_result_plane)).set_search_criteria(cx, criteria);
17071711
self.view.search_result(id!(search_result_plane)).set_result_count(cx, count);
17081712
self.view.view(id!(search_timeline)).set_visible(cx, true);
17091713
tl.search_result_state.content_drawn_since_last_update.clear();
17101714
tl.search_result_state.profile_drawn_since_last_update.clear();
17111715
for item in items {
1712-
tl.search_result_state.items.push_front(item.clone());
1716+
tl.search_result_state.items.push_front(item.clone());
17131717
}
17141718
search_portal_list.set_first_id_and_scroll(tl.search_result_state.items.len().saturating_sub(1), 0.0);
17151719
search_portal_list.set_tail_range(true);
@@ -2801,6 +2805,7 @@ pub enum TimelineUpdate {
28012805
/// Display Search result in Makepad's widget
28022806
SearchResultReceived {
28032807
items: Vec<SearchTimelineItem>,
2808+
profile_infos: BTreeMap<OwnedUserId, TimelineDetails<Profile>>,
28042809
count: u32,
28052810
highlights: Vec<String>,
28062811
search_term: String
@@ -2922,6 +2927,7 @@ pub struct SearchResultState {
29222927
content_drawn_since_last_update: RangeSet<usize>,
29232928
/// Same as `content_drawn_since_last_update`, but for the event **profiles** (avatar, username).
29242929
profile_drawn_since_last_update: RangeSet<usize>,
2930+
profiles_info: BTreeMap<OwnedUserId, TimelineDetails<Profile>>
29252931
}
29262932

29272933
#[derive(Default, Debug)]
@@ -3713,7 +3719,6 @@ pub fn populate_message_view<T,P,M>(
37133719
.set_text(cx, &format!("{}", ts_millis.get()));
37143720
}
37153721
if is_contextual {
3716-
//item.view(id!(overlay_message)).set_visible(cx, true);
37173722
item.view(id!(overlay_message)).apply_over(cx, live!{
37183723
draw_bg: {color: (vec4(1.0, 1.0, 1.0, 0.5)),}
37193724
});
@@ -4043,7 +4048,6 @@ fn draw_replied_to_message(
40434048
let fully_drawn: bool;
40444049
let show_reply: bool;
40454050
let mut replied_to_event_id = None;
4046-
40474051
if let Some(in_reply_to_details) = in_reply_to {
40484052
replied_to_event_id = Some(in_reply_to_details.event_id.to_owned());
40494053
show_reply = true;

src/home/room_search_result.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::ops::DerefMut;
1+
use std::{collections::BTreeMap, ops::DerefMut};
22

33
use indexmap::IndexMap;
44
use makepad_widgets::*;
5-
use matrix_sdk_ui::timeline::{AnyOtherFullStateEventContent, InReplyToDetails, ReactionsByKeyBySender, TimelineDetails, TimelineEventItemId};
5+
use matrix_sdk_ui::timeline::{AnyOtherFullStateEventContent, InReplyToDetails, Profile, ReactionsByKeyBySender, TimelineDetails, TimelineEventItemId};
66
use ruma::{events::{receipt::Receipt, room::message::{AudioMessageEventContent, EmoteMessageEventContent, FileMessageEventContent, FormattedBody, ImageMessageEventContent, KeyVerificationRequestEventContent, MessageType, NoticeMessageEventContent, Relation, RoomMessageEventContent, TextMessageEventContent, VideoMessageEventContent}, AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyStateEventContent, AnyTimelineEvent, FullStateEventContent}, uint, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedUserId, UserId};
77

88
use crate::{event_preview::text_preview_of_other_state, shared::room_filter_input_bar::RoomFilterAction, sliding_sync::{current_user_id, submit_async_request, MatrixRequest}, utils::unix_time_millis_to_datetime};
@@ -40,14 +40,14 @@ live_design! {
4040
text_style: <MESSAGE_TEXT_STYLE> { font_size: 10 },
4141
color: (TIMESTAMP_TEXT_COLOR)
4242
}
43-
text: "Loading earlier messages..."
43+
text: "Loading search results..."
4444
}
4545
}
4646
SearchIcon = <Icon> {
4747
align: {x: 0.0} // Align to top-right
4848
spacing: 10,
4949
margin: {top: 0, left: 10},
50-
padding: {top: 10, bottom: 10, left: 8, right: 15}
50+
padding: 10,
5151
width: Fit,
5252
height: Fit,
5353
draw_bg: {
@@ -130,14 +130,16 @@ live_design! {
130130
text: "Search All Rooms"
131131
}
132132
cancel_button = <RobrixIconButton> {
133-
align: {x: 1.0}
134-
margin: {right: 10, top: 0},
135133
width: Fit,
136-
height: 32,
137-
padding: {left: 15, right: 15}
134+
height: Fit,
135+
padding: 10,
136+
spacing: 0,
137+
margin: {left: 0, right: 15, top: -2},
138+
138139
draw_bg: {
139140
border_color: (COLOR_DANGER_RED),
140141
color: #fff0f0 // light red
142+
border_radius: 5
141143
}
142144
draw_icon: {
143145
svg_file: (ICON_CLOSE),
@@ -302,8 +304,8 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
302304
continue;
303305
};
304306
let item_drawn_status = ItemDrawnStatus {
305-
content_drawn: tl_state.content_drawn_since_last_update.contains(&tl_idx),
306-
profile_drawn: tl_state.profile_drawn_since_last_update.contains(&tl_idx),
307+
content_drawn: tl_state.search_result_state.content_drawn_since_last_update.contains(&tl_idx),
308+
profile_drawn: tl_state.search_result_state.profile_drawn_since_last_update.contains(&tl_idx),
307309
};
308310
let (item, item_new_draw_status) = {
309311
let current_item = timeline_item;
@@ -329,8 +331,9 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
329331
content = replace.original_content();
330332
}
331333
match content {
332-
Some(AnyMessageLikeEventContent::RoomMessage(mut message)) => {
334+
Some(AnyMessageLikeEventContent::RoomMessage(message)) => {
333335
let mut in_reply_to_details = None;
336+
let mut message = message.clone();
334337
if let Some(relation) = &message.relates_to {
335338
match relation {
336339
Relation::Replacement(replace) => {
@@ -344,6 +347,7 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
344347
}
345348
}
346349
let is_contextual = matches!(&current_item, SearchTimelineItem::ContextEvent(_));
350+
347351
if let MessageType::Text(text) = &mut message.msgtype {
348352
if let Some(ref mut formatted) = text.formatted {
349353
for highlight in tl_state.search_result_state.highlighted_strings.iter() {
@@ -357,7 +361,7 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
357361
text.formatted = Some(FormattedBody::html(formated_string));
358362
}
359363
}
360-
let event = &EventableWrapperAEI(event);
364+
let event = &EventableWrapperAEI(event, &tl_state.search_result_state.profiles_info);
361365
// Do not use compact view if previous event is state
362366
let prev_event = prev_event.and_then(|f| if matches!(f, AnyTimelineEvent::State(_)) { None } else { Some(f) }).map(PreviousWrapperAEI);
363367
let message = MsgTypeWrapperRMC(&message, in_reply_to_details.as_ref());
@@ -377,7 +381,7 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
377381
)
378382
}
379383
Some(AnyMessageLikeEventContent::Sticker(sticker)) => {
380-
let event = &EventableWrapperAEI(event);
384+
let event = &EventableWrapperAEI(event, &tl_state.search_result_state.profiles_info);
381385
let prev_event = prev_event.map(PreviousWrapperAEI);
382386
let is_contextual = matches!(&current_item, SearchTimelineItem::ContextEvent(_));
383387
populate_message_view(
@@ -405,7 +409,7 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
405409
let state_key = state.state_key();
406410
if let Some(content) = state.original_content() {
407411
let wrapper = AnyStateEventContentWrapper(&content, state_key);
408-
let event = &EventableWrapperAEI(event);
412+
let event = &EventableWrapperAEI(event, &tl_state.search_result_state.profiles_info);
409413
populate_small_state_event(
410414
cx,
411415
list,
@@ -430,10 +434,10 @@ pub fn search_result_draw_walk(room_screen: &mut RoomScreen, cx: &mut Cx2d, scop
430434
}
431435
};
432436
if item_new_draw_status.content_drawn {
433-
tl_state.content_drawn_since_last_update.insert(tl_idx .. tl_idx + 1);
437+
tl_state.search_result_state.content_drawn_since_last_update.insert(tl_idx .. tl_idx + 1);
434438
}
435439
if item_new_draw_status.profile_drawn {
436-
tl_state.profile_drawn_since_last_update.insert(tl_idx .. tl_idx + 1);
440+
tl_state.search_result_state.profile_drawn_since_last_update.insert(tl_idx .. tl_idx + 1);
437441
}
438442
item
439443
};
@@ -524,11 +528,9 @@ pub fn search_result_reply(cx: &mut Cx, room_screen: &RoomScreen, details: &Mess
524528
for (index, item) in tl.items.iter().enumerate() {
525529
if item.as_event().and_then(|f| f.event_id()).map(|f|Some(f.to_owned()) == details.event_id).unwrap_or(false) {
526530
timeline_details.item_id = index;
527-
println!("index: {}", index);
528531
break;
529532
}
530533
}
531-
println!("search_result_reply detail{:?}", timeline_details);
532534
room_screen.view(id!(search_timeline)).set_visible(cx, false);
533535
cx.widget_action(room_screen.widget_uid(), &Scope::empty().path, RoomFilterAction::Clear);
534536
cx.widget_action(
@@ -594,7 +596,7 @@ impl <'a>From<&AnyStateEventContentWrapper<'a>> for Option<AnyOtherFullStateEven
594596
}
595597
}
596598
}
597-
pub struct EventableWrapperAEI<'a>(pub &'a AnyTimelineEvent);
599+
pub struct EventableWrapperAEI<'a>(pub &'a AnyTimelineEvent, pub &'a BTreeMap<OwnedUserId, TimelineDetails<Profile>>);
598600

599601
impl Eventable for EventableWrapperAEI<'_> {
600602
fn timestamp(&self) -> MilliSecondsSinceUnixEpoch {
@@ -606,8 +608,8 @@ impl Eventable for EventableWrapperAEI<'_> {
606608
fn sender(&self) -> &UserId {
607609
self.0.sender()
608610
}
609-
fn sender_profile(&self) -> Option<&TimelineDetails<matrix_sdk_ui::timeline::Profile>> {
610-
None
611+
fn sender_profile(&self) -> Option<&TimelineDetails<Profile>> {
612+
self.1.get(self.sender())
611613
}
612614
fn reactions(&self) -> Option<ReactionsByKeyBySender> {
613615
None

src/sliding_sync.rs

Lines changed: 10 additions & 3 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::{
@@ -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
}

0 commit comments

Comments
 (0)