mirror of
https://github.com/mikedilger/gossip.git
synced 2024-10-01 09:21:53 +00:00
Render links as links
This commit is contained in:
parent
7a830ec89f
commit
8424f889e8
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1695,6 +1695,7 @@ dependencies = [
|
||||
"http",
|
||||
"image",
|
||||
"lazy_static",
|
||||
"linkify",
|
||||
"nostr-types",
|
||||
"rand 0.8.5",
|
||||
"reqwest",
|
||||
@ -2087,6 +2088,15 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linkify"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96dd5884008358112bc66093362197c7248ece00d46624e2cf71e50029f8cff5"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.9"
|
||||
|
@ -22,6 +22,7 @@ hex = "0.4"
|
||||
http = "0.2"
|
||||
image = "0.24"
|
||||
lazy_static = "1.4"
|
||||
linkify = "0.9"
|
||||
nostr-types = { git = "https://github.com/mikedilger/nostr-types" }
|
||||
rand = "0.8"
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
|
@ -7,6 +7,7 @@ use egui::{
|
||||
Align, Color32, Context, Frame, Image, Label, Layout, RichText, ScrollArea, Sense, TextEdit,
|
||||
Ui, Vec2,
|
||||
};
|
||||
use linkify::{LinkFinder, LinkKind};
|
||||
use nostr_types::{EventKind, Id, PublicKeyHex};
|
||||
|
||||
struct FeedPostParams {
|
||||
@ -413,7 +414,7 @@ fn render_post_actual(
|
||||
}
|
||||
});
|
||||
|
||||
ui.label(&event.content);
|
||||
render_content(ui, &event.content);
|
||||
|
||||
// Under row
|
||||
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) {
|
||||
if let Some(dbperson) = GLOBALS.people.blocking_write().get(pubkeyhex) {
|
||||
app.person_view_name = if let Some(name) = &dbperson.name {
|
||||
|
Loading…
Reference in New Issue
Block a user