Skip to content

[Enhance] Properly handle matrix.to links for Rooms base on PR#390 special pill. #466

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl MatchEvent for App {
match action.as_widget_action().cast() {
// A room has been selected, update the app state and navigate to the main content view.
RoomsListAction::Selected { room_id, room_index: _, room_name } => {
log!("Selected room: {:?}", room_id);
self.app_state.rooms_panel.selected_room = Some(SelectedRoom {
room_id: room_id.clone(),
room_name: room_name.clone(),
Expand Down
30 changes: 22 additions & 8 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use matrix_sdk::{room::RoomMember, ruma::{
AudioMessageEventContent, CustomEventContent, EmoteMessageEventContent, FileMessageEventContent, FormattedBody, ImageMessageEventContent, KeyVerificationRequestEventContent, LocationMessageEventContent, MessageFormat, MessageType, NoticeMessageEventContent, RoomMessageEventContent, ServerNoticeMessageEventContent, TextMessageEventContent, VideoMessageEventContent
}, ImageInfo, MediaSource
},
sticker::StickerEventContent, Mentions}, matrix_uri::MatrixId, uint, EventId, MatrixToUri, MatrixUri, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomId
sticker::StickerEventContent, Mentions}, matrix_uri::MatrixId, uint, EventId, MatrixToUri, MatrixUri, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedRoomOrAliasId
}, OwnedServerName};
use matrix_sdk_ui::timeline::{
self, EventTimelineItem, InReplyToDetails, MemberProfileChange, RepliedToInfo, RoomMembershipChange, TimelineDetails, TimelineEventItemId, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem
};
use robius_location::Coordinates;

use crate::{
avatar_cache, event_preview::{body_of_timeline_item, text_preview_of_member_profile_change, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, home::loading_pane::{LoadingPaneState, LoadingPaneWidgetExt}, location::{get_latest_location, init_location_subscriber, request_location_update, LocationAction, LocationRequest, LocationUpdate}, media_cache::{MediaCache, MediaCacheEntry}, profile::{
avatar_cache, event_preview::{body_of_timeline_item, text_preview_of_member_profile_change, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, home::{loading_pane::{LoadingPaneState, LoadingPaneWidgetExt}, rooms_list::{self, RoomsListAction}}, location::{get_latest_location, init_location_subscriber, request_location_update, LocationAction, LocationRequest, LocationUpdate}, media_cache::{MediaCache, MediaCacheEntry}, profile::{
user_profile::{AvatarState, ShowUserProfileAction, UserProfile, UserProfileAndRoomId, UserProfilePaneInfo, UserProfileSlidingPaneRef, UserProfileSlidingPaneWidgetExt},
user_profile_cache,
}, shared::{
Expand Down Expand Up @@ -1743,7 +1743,7 @@ impl RoomScreen {
) -> bool {
// A closure that handles both MatrixToUri and MatrixUri links,
// and returns whether the link was handled.
let mut handle_matrix_link = |id: &MatrixId, _via: &[OwnedServerName]| -> bool {
let mut handle_matrix_link = |id: &MatrixId, via: &[OwnedServerName]| -> bool {
match id {
MatrixId::User(user_id) => {
// There is no synchronous way to get the user's full profile info
Expand Down Expand Up @@ -1776,20 +1776,34 @@ impl RoomScreen {
enqueue_popup_notification("You are already viewing that room.".into());
return true;
}
if let Some(_known_room) = get_client().and_then(|c| c.get_room(room_id)) {
log!("TODO: jump to known room {}", room_id);
if let Some(known_room) = get_client().and_then(|c| c.get_room(room_id)) {
cx.widget_action(
self.widget_uid(),
&Scope::empty().path,
RoomsListAction::Selected {
room_index: 0,
room_id: known_room.room_id().to_owned(),
room_name: known_room.name()
}
);
} else {
let room_id: OwnedRoomOrAliasId = room_id.clone().into();
log!("TODO: fetch and display room preview for room {}", room_id);
}
false
true
}
MatrixId::RoomAlias(room_alias) => {
log!("TODO: open room alias {}", room_alias);
// TODO: open a room loading screen that shows a spinner
// while our background async task calls Client::resolve_room_alias()
// and then either jumps to the room if known, or fetches and displays
// a room preview for that room.
false
let room_alias: OwnedRoomOrAliasId = room_alias.clone().into();
log!("TODO: open room alias {}", room_alias);
submit_async_request(MatrixRequest::GetRoomPreview {
room_or_alias_id: room_alias,
via: via.to_vec()
});
true
}
MatrixId::Event(room_id, event_id) => {
log!("TODO: open event {} in room {}", event_id, room_id);
Expand Down
16 changes: 14 additions & 2 deletions src/shared/html_or_plaintext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A `HtmlOrPlaintext` view can display either plaintext or rich HTML content.

use makepad_widgets::{makepad_html::HtmlDoc, *};
use matrix_sdk::{ruma::{matrix_uri::MatrixId, OwnedMxcUri}, OwnedServerName};
use matrix_sdk::{ruma::{matrix_uri::MatrixId, MatrixToUri, MatrixUri, OwnedMxcUri}, OwnedServerName};

use crate::{avatar_cache::{self, AvatarCacheEntry}, profile::user_profile_cache, sliding_sync::{current_user_id, submit_async_request, MatrixRequest}, utils};

Expand Down Expand Up @@ -219,7 +219,14 @@ impl Widget for RobrixHtmlLink {
self.draw_html_link(cx);
}
*/
self.draw_html_link(cx);
// self.draw_html_link(cx);
if let Ok(matrix_to_uri) = MatrixToUri::parse(&self.url) {
self.draw_matrix_pill(cx, matrix_to_uri.id(), matrix_to_uri.via());
} else if let Ok(matrix_uri) = MatrixUri::parse(&self.url) {
self.draw_matrix_pill(cx, matrix_uri.id(), matrix_uri.via());
} else {
self.draw_html_link(cx);
}
self.view.draw_walk(cx, scope, walk)
}

Expand Down Expand Up @@ -264,6 +271,11 @@ pub enum MatrixLinkPillState {
None,
}

// #[derive(Debug, Clone, DefaultNone)]
// pub enum MatrixLinkPillAction {

// }

/// A pill-shaped widget that shows a Matrix link as an avatar and a title.
///
/// This can be a link to a user, a room, or a message in a room.
Expand Down
21 changes: 20 additions & 1 deletion src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use matrix_sdk::{
receipt::ReceiptThread, room::{
message::{ForwardThread, RoomMessageEventContent}, power_levels::RoomPowerLevels, MediaSource
}, FullStateEventContent, MessageLikeEventType, StateEventType
}, matrix_uri::MatrixId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomOrAliasId, UserId
}, matrix_uri::MatrixId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, RoomAliasId, RoomOrAliasId, UserId
}, sliding_sync::VersionBuilder, Client, ClientBuildError, Error, OwnedServerName, Room, RoomMemberships
};
use matrix_sdk_ui::{
Expand Down Expand Up @@ -373,6 +373,10 @@ pub enum MatrixRequest {
matrix_id: MatrixId,
via: Vec<OwnedServerName>
},
GetRoomPreview {
room_or_alias_id: OwnedRoomOrAliasId,
via: Vec<OwnedServerName>,
}
}

/// Submits a request to the worker thread to be executed asynchronously.
Expand Down Expand Up @@ -1039,6 +1043,21 @@ async fn async_worker(
}
});
}
MatrixRequest::GetRoomPreview { room_or_alias_id, via } => {
let Some(client) = CLIENT.get() else { continue };
let _fetch_room_preview_task = Handle::current().spawn(async move {
log!("Sending get room preview request for {room_or_alias_id:?}...");
match client.get_room_preview(&room_or_alias_id, via).await {
Ok(preview) => {
log!("Room id: {:?}", preview.room_id);
log!("Room name: {:?}", preview.name);
}
Err(e) => {
error!("Failed to fetch room preview for {room_or_alias_id:?}: {e:?}");
}
}
});
}
}
}

Expand Down