Commit ec88f4441e
ec88f4441ec0cf24a30bc1a310d6f398b3bb4ac6
parent: 34d3b844af
Unregistered key
vaw <git@nlih.de> · 2025-07-23 00:05 UTC
committer: <noreply@github.com>
Recognise URLs in plain text message bodies (#476)
Layout: unified · split
Cargo.lock
+10
| @@ -2274,6 +2274,7 @@ dependencies = [ |
| 2274 | "image", |
2274 | "image", |
| 2275 | "lazy_static 1.5.0", |
2275 | "lazy_static 1.5.0", |
| 2276 | "libc", |
2276 | "libc", |
| |
2277 | "linkify", |
| 2277 | "markup5ever_rcdom", |
2278 | "markup5ever_rcdom", |
| 2278 | "matrix-sdk", |
2279 | "matrix-sdk", |
| 2279 | "mime", |
2280 | "mime", |
| @@ -2831,6 +2832,15 @@ dependencies = [ |
| 2831 | "vcpkg", |
2832 | "vcpkg", |
| 2832 | ] |
2833 | ] |
| 2833 | |
2834 | |
| |
2835 | [[package]] |
| |
2836 | name = "linkify" |
| |
2837 | version = "0.10.0" |
| |
2838 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
2839 | checksum = "f1dfa36d52c581e9ec783a7ce2a5e0143da6237be5811a0b3153fedfdbe9f780" |
| |
2840 | dependencies = [ |
| |
2841 | "memchr", |
| |
2842 | ] |
| |
2843 | |
| 2834 | [[package]] |
2844 | [[package]] |
| 2835 | name = "linux-raw-sys" |
2845 | name = "linux-raw-sys" |
| 2836 | version = "0.3.8" |
2846 | version = "0.3.8" |
Cargo.toml
+1
| @@ -64,6 +64,7 @@ unicode-width = "0.1.10" |
| 64 | url = {version = "^2.2.2", features = ["serde"]} |
64 | url = {version = "^2.2.2", features = ["serde"]} |
| 65 | edit = "0.1.4" |
65 | edit = "0.1.4" |
| 66 | humansize = "2.0.0" |
66 | humansize = "2.0.0" |
| |
67 | linkify = "0.10.0" |
| 67 | |
68 | |
| 68 | [dependencies.comrak] |
69 | [dependencies.comrak] |
| 69 | version = "0.22.0" |
70 | version = "0.22.0" |
src/message/html.rs
+2 −2
| @@ -524,11 +524,11 @@ impl StyleTree { |
| 524 | } |
524 | } |
| 525 | |
525 | |
| 526 | pub struct TreeGenState { |
526 | pub struct TreeGenState { |
| 527 | link_num: u8, |
527 | pub link_num: u8, |
| 528 | } |
528 | } |
| 529 | |
529 | |
| 530 | impl TreeGenState { |
530 | impl TreeGenState { |
| 531 | fn next_link_char(&mut self) -> Option<char> { |
531 | pub fn next_link_char(&mut self) -> Option<char> { |
| 532 | let num = self.link_num; |
532 | let num = self.link_num; |
| 533 | |
533 | |
| 534 | if num < 62 { |
534 | if num < 62 { |
src/message/mod.rs
+1
| @@ -72,6 +72,7 @@ mod state; |
| 72 | |
72 | |
| 73 | pub use self::compose::text_to_message; |
73 | pub use self::compose::text_to_message; |
| 74 | use self::state::{body_cow_state, html_state}; |
74 | use self::state::{body_cow_state, html_state}; |
| |
75 | pub use html::TreeGenState; |
| 75 | |
76 | |
| 76 | type ProtocolPreview<'a> = (&'a Protocol, u16, u16); |
77 | type ProtocolPreview<'a> = (&'a Protocol, u16, u16); |
| 77 | |
78 | |
src/windows/room/chat.rs
+15 −4
| @@ -86,7 +86,14 @@ use crate::base::{ |
| 86 | SendAction, |
86 | SendAction, |
| 87 | }; |
87 | }; |
| 88 | |
88 | |
| 89 | use crate::message::{text_to_message, Message, MessageEvent, MessageKey, MessageTimeStamp}; |
89 | use crate::message::{ |
| |
90 | text_to_message, |
| |
91 | Message, |
| |
92 | MessageEvent, |
| |
93 | MessageKey, |
| |
94 | MessageTimeStamp, |
| |
95 | TreeGenState, |
| |
96 | }; |
| 90 | use crate::worker::Requester; |
97 | use crate::worker::Requester; |
| 91 | |
98 | |
| 92 | use super::scrollback::{Scrollback, ScrollbackState}; |
99 | use super::scrollback::{Scrollback, ScrollbackState}; |
| @@ -226,10 +233,14 @@ impl ChatState { |
| 226 | |
233 | |
| 227 | let links = if let Some(html) = &msg.html { |
234 | let links = if let Some(html) = &msg.html { |
| 228 | html.get_links() |
235 | html.get_links() |
| 229 | } else if let Ok(url) = Url::parse(&msg.event.body()) { |
| |
| 230 | vec![('0', url)] |
| |
| 231 | } else { |
236 | } else { |
| 232 | vec![] |
237 | linkify::LinkFinder::new() |
| |
238 | .links(&msg.event.body()) |
| |
239 | .filter_map(|u| Url::parse(u.as_str()).ok()) |
| |
240 | .scan(TreeGenState { link_num: 0 }, |state, u| { |
| |
241 | state.next_link_char().map(|c| (c, u)) |
| |
242 | }) |
| |
243 | .collect() |
| 233 | }; |
244 | }; |
| 234 | |
245 | |
| 235 | if links.is_empty() { |
246 | if links.is_empty() { |