diff --git a/CHANGELOG.md b/CHANGELOG.md index d131e4b..683662d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,12 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - Other people's myTeamSpeak badges: up to three pictures after their name in the channel tree and the members panel, and their names on the member card (what each is for on hover). +- Links in chat open in the browser; one whose text is not its address + first shows where it goes. A right-click on a link opens or copies it; + TeamSpeak links are copied for now. +- Every message can be quoted into the composer (`> ` lines) and its text + copied, from the actions on hover or a right-click menu, also on servers + without a gateway. ### Changed diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index c842fcd..ff312ee 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -865,6 +865,13 @@ impl App { } } + /// Open a page on the web in the browser. Pages open through here, so + /// a platform without a desktop opener (Android) can open them its own + /// way. + pub(crate) fn open_url(&self, url: &str) -> std::io::Result<()> { + open_target(std::ffi::OsStr::new(url)) + } + /// Nav.copy put text on the clipboard: one toast says so. pub fn copied(&mut self) { let text = self.copy_note.take().unwrap_or_else(|| "Copied".to_owned()); diff --git a/crates/voelin-ui/src/bind/chat.rs b/crates/voelin-ui/src/bind/chat.rs index ed9a7dc..23a9d8a 100644 --- a/crates/voelin-ui/src/bind/chat.rs +++ b/crates/voelin-ui/src/bind/chat.rs @@ -55,6 +55,10 @@ pub(super) fn wire(ui: &MainWindow) { bridge.on_create_topic(|key, title| { with_app(|app| app.create_topic(key, title.to_string())); }); + bridge.on_open_link(|link, masked| { + with_app(|app| app.open_link_text(&link, masked)).unwrap_or_default().into() + }); + bridge.on_quote_text(|author, text| crate::vm::chat::quote(&author, &text).into()); bridge.on_open_member(|id| { with_app(|app| app.open_member(id)); }); diff --git a/crates/voelin-ui/src/chat.rs b/crates/voelin-ui/src/chat.rs index 5b9bdab..7a2ef12 100644 --- a/crates/voelin-ui/src/chat.rs +++ b/crates/voelin-ui/src/chat.rs @@ -21,9 +21,10 @@ use voelin_core::{ use voelin_gateway_proto::{ErrorCode, TopicInfo, feature}; use voelin_model::{ChatMessage, ChatTarget, HostMessageMode, ServerDetails}; -use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, PinItem, SessionView, Tab}; +use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, Nav, PinItem, SessionView, Tab}; use crate::settings::UI_IMAGE_PREVIEW_KB; use crate::vm; +use crate::vm::bbcode::LinkKind; use crate::vm::chat::{LineCache, LineCtx, Previous}; /// Where the server's welcome and host message keep what their lines were @@ -350,7 +351,8 @@ impl App { } /// What the server says to everyone who connects ([`server_texts`]) as - /// the first lines of the server chat: by the server, without actions. + /// the first lines of the server chat: by the server, without reactions + /// or pins. fn server_lines( view: &SessionView, pictures: Option<&HashMap>, @@ -545,6 +547,37 @@ impl App { vm::list::sync(&self.models.topic_messages, &self.lines_of(view, tab, false)); } + /// A link in a message was clicked (`masked`: its text shows something + /// else, [`vm::bbcode::is_masked`]). A page on the web opens in the + /// browser, a masked one once the user saw where it goes (Nav.link-open); + /// a TeamSpeak link is copied until Voelin opens them. Returns what to + /// copy ("": nothing). + pub(crate) fn open_link_text(&mut self, link: &str, masked: bool) -> String { + match vm::bbcode::classify_link(link) { + LinkKind::Web(url) if masked => { + if let Some(ui) = self.ui.upgrade() { + let nav = ui.global::