Render links as links

This commit is contained in:
Mike Dilger 2023-01-02 07:22:55 +13:00
parent 7a830ec89f
commit 8424f889e8
3 changed files with 23 additions and 1 deletions

10
Cargo.lock generated
View File

@ -1695,6 +1695,7 @@ dependencies = [
"http", "http",
"image", "image",
"lazy_static", "lazy_static",
"linkify",
"nostr-types", "nostr-types",
"rand 0.8.5", "rand 0.8.5",
"reqwest", "reqwest",
@ -2087,6 +2088,15 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "linkify"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96dd5884008358112bc66093362197c7248ece00d46624e2cf71e50029f8cff5"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.9" version = "0.4.9"

View File

@ -22,6 +22,7 @@ hex = "0.4"
http = "0.2" http = "0.2"
image = "0.24" image = "0.24"
lazy_static = "1.4" lazy_static = "1.4"
linkify = "0.9"
nostr-types = { git = "https://github.com/mikedilger/nostr-types" } nostr-types = { git = "https://github.com/mikedilger/nostr-types" }
rand = "0.8" rand = "0.8"
reqwest = { version = "0.11", features = ["json"] } reqwest = { version = "0.11", features = ["json"] }

View File

@ -7,6 +7,7 @@ use egui::{
Align, Color32, Context, Frame, Image, Label, Layout, RichText, ScrollArea, Sense, TextEdit, Align, Color32, Context, Frame, Image, Label, Layout, RichText, ScrollArea, Sense, TextEdit,
Ui, Vec2, Ui, Vec2,
}; };
use linkify::{LinkFinder, LinkKind};
use nostr_types::{EventKind, Id, PublicKeyHex}; use nostr_types::{EventKind, Id, PublicKeyHex};
struct FeedPostParams { struct FeedPostParams {
@ -413,7 +414,7 @@ fn render_post_actual(
} }
}); });
ui.label(&event.content); render_content(ui, &event.content);
// Under row // Under row
if !as_reply_to { if !as_reply_to {
@ -454,6 +455,16 @@ fn render_post_actual(
} }
} }
fn render_content(ui: &mut Ui, content: &str) {
for span in LinkFinder::new().kinds(&[LinkKind::Url]).spans(content) {
if span.kind().is_some() {
ui.hyperlink_to(span.as_str(), span.as_str());
} else {
ui.label(span.as_str());
}
}
}
fn set_person_view(app: &mut GossipUi, pubkeyhex: &PublicKeyHex) { fn set_person_view(app: &mut GossipUi, pubkeyhex: &PublicKeyHex) {
if let Some(dbperson) = GLOBALS.people.blocking_write().get(pubkeyhex) { if let Some(dbperson) = GLOBALS.people.blocking_write().get(pubkeyhex) {
app.person_view_name = if let Some(name) = &dbperson.name { app.person_view_name = if let Some(name) = &dbperson.name {