Skip to content

Commit

Permalink
Merge pull request #76 from kevinaboos/linkify_plain_urls
Browse files Browse the repository at this point in the history
Linkify plaintext URLs into clickable HTML links
  • Loading branch information
kevinaboos authored Jul 8, 2024
2 parents 27761af + 7a1006e commit 90315e6
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 5 deletions.
10 changes: 10 additions & 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 @@ -30,6 +30,7 @@ eyeball-im = "0.4.2"
futures-util = "0.3"
imbl = { version = "2.0.0", features = ["serde"] } # same as matrix-sdk-ui
imghdr = "0.7.0"
linkify = "0.10.0"
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", default-features = false, features = [ "experimental-sliding-sync", "e2e-encryption", "automatic-room-key-forwarding", "markdown", "sqlite", "rustls-tls", "bundled-sqlite" ] }
matrix-sdk-ui = { git = "https://github.com/matrix-org/matrix-rust-sdk", default-features = false, features = [ "e2e-encryption", "rustls-tls" ] }
rangemap = "1.5.0"
Expand Down
12 changes: 8 additions & 4 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A room screen is the UI page that displays a single Room's timeline of events/messages
//! along with a message input bar at the bottom.
use std::{collections::BTreeMap, ops::{DerefMut, Range}, sync::{Arc, Mutex}};
use std::{borrow::Cow, collections::BTreeMap, ops::{DerefMut, Range}, sync::{Arc, Mutex}};

use imbl::Vector;
use makepad_widgets::*;
Expand Down Expand Up @@ -821,8 +821,8 @@ impl Widget for Timeline {

// Handle a link being clicked.
if let HtmlLinkAction::Clicked { url, .. } = action.as_widget_action().cast() {
log!("Timeline::handle_event(): link clicked: {:?}", url);
if url.starts_with("https://matrix.to/#/") {
log!("TODO: handle Matrix link internally: {url:?}");
// TODO: show a pop-up pane with the user's profile, or a room preview pane.
//
// There are four kinds of matrix.to schemes:
Expand Down Expand Up @@ -1106,13 +1106,17 @@ fn populate_message_view(
if existed && item_drawn_status.content_drawn {
(item, true)
} else {
let msg_body_field = item.html_or_plaintext(id!(content.message));
// Draw the message body, either as rich HTML or as plaintext.
if let Some(formatted_body) = text.formatted.as_ref()
.and_then(|fb| (fb.format == MessageFormat::Html).then(|| fb.body.clone()))
{
item.html_or_plaintext(id!(message)).show_html(formatted_body);
msg_body_field.show_html(utils::linkify(formatted_body.as_ref()));
} else {
item.html_or_plaintext(id!(message)).show_plaintext(&text.body);
match utils::linkify(&text.body) {
Cow::Owned(linkified_html) => msg_body_field.show_html(&linkified_html),
Cow::Borrowed(plaintext) => msg_body_field.show_plaintext(plaintext),
}
}
// Draw any reactions to the message.
draw_reactions(cx, &item, event_tl_item.reactions(), item_id - 1);
Expand Down
Loading

0 comments on commit 90315e6

Please sign in to comment.