Skip to content

Searching messages in a room (not encrypted) #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bytesize = "1.3.0"
bitflags = "2.6.0"
indexmap = "2.6.0"
blurhash = { version = "0.2.3", default-features = false }
ruma = { git = "https://github.com/ruma/ruma", rev = "7755c7cbc580f8d8aea30d78cc1a6850b1a6fd39", default-features = false, features = ["api", "client-api-c"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
22 changes: 21 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use makepad_widgets::*;
use matrix_sdk::ruma::{OwnedRoomId, RoomId};

use crate::{
home::{new_message_context_menu::NewMessageContextMenuWidgetRefExt, room_screen::MessageAction, rooms_list::RoomsListAction}, login::login_screen::LoginAction, shared::{callout_tooltip::{CalloutTooltipOptions, CalloutTooltipWidgetRefExt, TooltipAction}, popup_list::PopupNotificationAction}, utils::room_name_or_id, verification::VerificationAction, verification_modal::{VerificationModalAction, VerificationModalWidgetRefExt}
home::{new_message_context_menu::NewMessageContextMenuWidgetRefExt, room_screen::MessageAction, rooms_list::RoomsListAction}, login::login_screen::LoginAction, shared::{callout_tooltip::{CalloutTooltipOptions, CalloutTooltipWidgetRefExt, TooltipAction}, message_search_input_bar::MessageSearchAction, popup_list::PopupNotificationAction}, utils::room_name_or_id, verification::VerificationAction, verification_modal::{VerificationModalAction, VerificationModalWidgetRefExt}
};

live_design! {
Expand Down Expand Up @@ -242,6 +242,7 @@ impl MatchEvent for App {
&Scope::default().path,
StackNavigationAction::NavigateTo(live_id!(main_content_view))
);
self.ui.view(id!(message_search_input_view)).set_visible(cx, true);
self.ui.redraw(cx);
}

Expand All @@ -251,6 +252,7 @@ impl MatchEvent for App {
}
AppStateAction::FocusNone => {
self.app_state.selected_room = None;
self.ui.view(id!(message_search_input_view)).set_visible(cx, false);
}
AppStateAction::UpgradedInviteToJoinedRoom(room_id) => {
if let Some(selected_room) = self.app_state.selected_room.as_mut() {
Expand Down Expand Up @@ -318,6 +320,24 @@ impl MatchEvent for App {
// }
// _ => {}
// }
match action.as_widget_action().cast() {
MessageSearchAction::Click(_) => {
self.ui
.view(id!(main_content_view.header.content.message_search_input_mobile_view))
.apply_over(cx, live!{
width: 220
});
}
MessageSearchAction::Clear => {
self.ui
.view(id!(main_content_view.header.content.message_search_input_mobile_view))
.apply_over(cx, live!{
width: 150
});
}
_ => {}
}

}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/event_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn text_preview_of_timeline_item(
text_preview_of_member_profile_change(profile_change, sender_username, true)
}
TimelineItemContent::OtherState(other_state) => {
text_preview_of_other_state(other_state, true)
text_preview_of_other_state(other_state.content(), true, other_state.state_key())
.unwrap_or_else(|| TextPreview::from((
String::from("<i>initiated another state change</i>"),
BeforeText::UsernameWithoutColon,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn plaintext_body_of_timeline_item(
).text
}
TimelineItemContent::OtherState(other_state) => {
text_preview_of_other_state(other_state, false)
text_preview_of_other_state(other_state.content(), false, other_state.state_key())
.unwrap_or_else(|| TextPreview::from((
String::from("initiated another state change."),
BeforeText::UsernameWithoutColon,
Expand Down Expand Up @@ -315,10 +315,11 @@ pub fn text_preview_of_redacted_message(

/// Returns a text preview of the given other state event as an Html-formatted string.
pub fn text_preview_of_other_state(
other_state: &timeline::OtherState,
other_state: &AnyOtherFullStateEventContent,
format_as_html: bool,
state_key: &str,
) -> Option<TextPreview> {
let text = match other_state.content() {
let text = match other_state {
AnyOtherFullStateEventContent::RoomAliases(FullStateEventContent::Original { content, .. }) => {
let mut s = String::from("set this room's aliases to ");
let last_alias = content.aliases.len() - 1;
Expand Down Expand Up @@ -404,17 +405,17 @@ pub fn text_preview_of_other_state(
}
AnyOtherFullStateEventContent::SpaceParent(_) => {
let state_key = if format_as_html {
htmlize::escape_text(other_state.state_key())
htmlize::escape_text(state_key)
} else {
Cow::Borrowed(other_state.state_key())
Cow::Borrowed(state_key)
};
Some(format!("set this room's parent space to \"{state_key}\"."))
}
AnyOtherFullStateEventContent::SpaceChild(_) => {
let state_key = if format_as_html {
htmlize::escape_text(other_state.state_key())
htmlize::escape_text(state_key)
} else {
Cow::Borrowed(other_state.state_key())
Cow::Borrowed(state_key)
};
Some(format!("added a new child to this space: \"{state_key}\"."))
}
Expand Down
43 changes: 39 additions & 4 deletions src/home/home_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ live_design! {
use crate::home::spaces_dock::SpacesDock;
use crate::shared::styles::*;
use crate::shared::room_filter_input_bar::RoomFilterInputBar;
use crate::shared::message_search_input_bar::MessageSearchInputBar;
use crate::home::main_desktop_ui::MainDesktopUI;

NavigationWrapper = {{NavigationWrapper}} {
Expand All @@ -32,11 +33,30 @@ live_design! {

<View> {
flow: Down
width: Fill, height: Fill

<CachedWidget> {
<RoomFilterInputBar> {}
width: Fill, height: Fill,
spacing: 2,
<View> {
flow: Overlay,
width: Fill,
height: Fit,
<CachedWidget> {
<RoomFilterInputBar> {
width: 300
}
}
message_search_input_view = <View> {
width: Fill, height: Fit,
visible: false,
align: {x: 1.0},
<CachedWidget> {
message_search_input_bar = <MessageSearchInputBar> {
width: 300,
}
}
}

}

<MainDesktopUI> {}
}
}
Expand Down Expand Up @@ -75,6 +95,21 @@ live_design! {
}
}
}
<View> {
height: Fit,
width: Fill,
align: {x: 1.0 }
message_search_input_mobile_view = <View> {
height: Fit,
width: 150,
align: {x: 1.0 }
<CachedWidget> {
message_search_input_bar = <MessageSearchInputBar> {
width: 300
}
}
}
}
}
}
body = {
Expand Down
4 changes: 2 additions & 2 deletions src/home/main_desktop_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use makepad_widgets::*;
use matrix_sdk::ruma::OwnedRoomId;
use std::collections::HashMap;

use crate::{app::{AppState, AppStateAction, SelectedRoom}, utils::room_name_or_id};
use crate::{app::{AppState, AppStateAction, SelectedRoom}, shared::message_search_input_bar::MessageSearchAction, utils::room_name_or_id};
use super::{invite_screen::InviteScreenWidgetRefExt, room_screen::RoomScreenWidgetRefExt, rooms_list::RoomsListAction};

live_design! {
use link::theme::*;
use link::shaders::*;
Expand Down Expand Up @@ -210,6 +209,7 @@ impl MainDesktopUI {
dock.close_tab(cx, tab_id);
self.tab_to_close = None;
self.open_rooms.remove(&tab_id);
cx.widget_action(self.widget_uid(), &Scope::empty().path, MessageSearchAction::Clear);
}

/// Replaces an invite with a joined room in the dock.
Expand Down
1 change: 1 addition & 0 deletions src/home/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn live_design(cx: &mut Cx) {
new_message_context_menu::live_design(cx);
invite_screen::live_design(cx);
room_screen::live_design(cx);
room_screen::search_result::live_design(cx);
room_read_receipt::live_design(cx);
rooms_sidebar::live_design(cx);
main_mobile_ui::live_design(cx);
Expand Down
18 changes: 12 additions & 6 deletions src/home/new_message_context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
use bitflags::bitflags;
use makepad_widgets::*;
use matrix_sdk::ruma::OwnedEventId;
use matrix_sdk_ui::timeline::EventTimelineItem;
use matrix_sdk_ui::timeline::InReplyToDetails;
use ruma::events::room::message::MessageType;

use crate::sliding_sync::UserPowerLevels;

use super::room_screen::{MessageAction, MessageOrSticker};
use super::room_screen::{MessageDisplay, MessageAction, MessageOrSticker};

const BUTTON_HEIGHT: f64 = 35.0; // KEEP IN SYNC WITH BUTTON_HEIGHT BELOW
const MENU_WIDTH: f64 = 215.0; // KEEP IN SYNC WITH MENU_WIDTH BELOW
Expand Down Expand Up @@ -247,10 +248,10 @@ bitflags! {
}
}
impl MessageAbilities {
pub fn from_user_power_and_event(
pub fn from_user_power_and_event<T: MessageDisplay, M: ContextMenuFromEvent>(
user_power_levels: &UserPowerLevels,
event_tl_item: &EventTimelineItem,
_message: &MessageOrSticker,
event_tl_item: &T,
_message: &MessageOrSticker<M>,
has_html: bool,
) -> Self {
let mut abilities = Self::empty();
Expand All @@ -269,7 +270,6 @@ impl MessageAbilities {
abilities.set(Self::HasHtml, has_html);
abilities
}

}

/// Details about the message that define its context menu content.
Expand Down Expand Up @@ -620,3 +620,9 @@ impl NewMessageContextMenuRef {
inner.show(cx, details)
}
}
pub trait ContextMenuFromEvent {
fn msgtype(&self) -> &MessageType;
fn body(&self) -> &str;
fn in_reply_to(&self) -> Option<&InReplyToDetails>;
fn is_searched_result(&self) -> bool;
}
21 changes: 12 additions & 9 deletions src/home/room_read_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use crate::utils::human_readable_list;
use indexmap::IndexMap;
use makepad_widgets::*;
use matrix_sdk::ruma::{events::receipt::Receipt, EventId, OwnedUserId, RoomId};
use matrix_sdk_ui::timeline::EventTimelineItem;
use std::cmp;

use super::room_screen::MessageDisplay;


/// The maximum number of items to display in the read receipts AvatarRow
/// and its accompanying tooltip.
Expand Down Expand Up @@ -225,18 +226,20 @@ impl AvatarRowRef {
/// room ID, and an EventTimelineItem, this will populate the avatar
/// row of the item with the read receipts of the event.
///
pub fn populate_read_receipts(
pub fn populate_read_receipts<T: MessageDisplay>(
item: &WidgetRef,
cx: &mut Cx,
room_id: &RoomId,
event_tl_item: &EventTimelineItem,
event_tl_item: &T,
) {
item.avatar_row(id!(avatar_row)).set_avatar_row(
cx,
room_id,
event_tl_item.event_id(),
event_tl_item.read_receipts(),
);
if let Some(read_receipts) = event_tl_item.read_receipts() {
item.avatar_row(id!(avatar_row)).set_avatar_row(
cx,
room_id,
event_tl_item.event_id(),
read_receipts,
);
}
}

/// Populate the tooltip text for a read receipts avatar row.
Expand Down
Loading