Skip to content

Commit

Permalink
Allow zaps even when no seen_on relays are known for a note, because …
Browse files Browse the repository at this point in the history
…we only need the author profile
  • Loading branch information
bu5hm4nn committed Mar 22, 2024
1 parent d8bd605 commit 8aa0d39
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 70 deletions.
124 changes: 60 additions & 64 deletions gossip-bin/src/ui/feed/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,6 @@ pub fn render_note_inner(
let content_margin_left = AVATAR_SIZE_F32 + inner_margin.left;
let footer_margin_left = content_margin_left;

let relays = match GLOBALS.storage.get_event_seen_on_relay(note.event.id) {
Ok(vec) => vec
.iter()
.map(|(url, _)| url.to_unchecked_url())
.take(3)
.collect(),
Err(_) => vec![],
};

ui.vertical(|ui| {
// First row

Expand Down Expand Up @@ -429,6 +420,13 @@ pub fn render_note_inner(

ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
widgets::MoreMenu::simple(ui, app).show(ui, |ui, keep_open| {
let relays: Vec<UncheckedUrl> = note
.seen_on
.iter()
.map(|(url, _)| url.to_unchecked_url())
.take(3)
.collect();

if !render_data.is_main_event {
if note.event.kind.is_direct_message_related() {
if ui.button("View DM Channel").clicked() {
Expand Down Expand Up @@ -639,10 +637,8 @@ pub fn render_note_inner(
.show(ui.ctx(), |ui| {
ui.set_min_width(200.0);
egui::Frame::popup(&app.theme.get_style()).show(ui, |ui| {
if let Ok(seen_on) =
GLOBALS.storage.get_event_seen_on_relay(note.event.id)
{
for (url, _) in seen_on.iter() {
if !note.seen_on.is_empty() {
for (url, _) in note.seen_on.iter() {
ui.label(url.as_str());
}
} else {
Expand Down Expand Up @@ -775,6 +771,7 @@ pub fn render_note_inner(
// Button to Repost
if widgets::clickable_label(
ui,
true,
RichText::new("↻").size(18.0),
)
.on_hover_text("Repost")
Expand All @@ -790,11 +787,19 @@ pub fn render_note_inner(
// Button to quote note
if widgets::clickable_label(
ui,
true,
RichText::new("“…”").size(18.0),
)
.on_hover_text("Quote")
.clicked()
{
let relays: Vec<UncheckedUrl> = note
.seen_on
.iter()
.map(|(url, _)| url.to_unchecked_url())
.take(3)
.collect();

if !app.draft_data.draft.ends_with(' ')
&& !app.draft_data.draft.is_empty()
{
Expand Down Expand Up @@ -844,6 +849,7 @@ pub fn render_note_inner(

if widgets::clickable_label(
ui,
true,
RichText::new(reply_icon).size(18.0),
)
.on_hover_text("Reply")
Expand Down Expand Up @@ -877,9 +883,13 @@ pub fn render_note_inner(
}

// Button to render raw
if widgets::clickable_label(ui, RichText::new("🥩").size(13.0))
.on_hover_text("Raw")
.clicked()
if widgets::clickable_label(
ui,
true,
RichText::new("🥩").size(13.0),
)
.on_hover_text("Raw")
.clicked()
{
if app.render_raw != Some(note.event.id) {
app.render_raw = Some(note.event.id);
Expand All @@ -892,7 +902,7 @@ pub fn render_note_inner(
ui.add_space(24.0);

// Button to render QR code
if widgets::clickable_label(ui, RichText::new("⚃").size(16.0))
if widgets::clickable_label(ui, true, RichText::new("⚃").size(16.0))
.on_hover_text("QR Code")
.clicked()
{
Expand All @@ -918,51 +928,37 @@ pub fn render_note_inner(
}
}

let mut has_seen_on_relays = false;
if let Ok(seen_on) =
GLOBALS.storage.get_event_seen_on_relay(note.event.id)
{
if !seen_on.is_empty() {
has_seen_on_relays = true;
}
}

if let Some(lnurl) = zap_lnurl {
if has_seen_on_relays {
if widgets::clickable_label(
ui,
RichText::new("⚡").size(18.0),
)
.on_hover_text("ZAP")
.clicked()
{
if GLOBALS.identity.is_unlocked() {
let _ = GLOBALS.to_overlord.send(
ToOverlordMessage::ZapStart(
note.event.id,
note.event.pubkey,
UncheckedUrl(lnurl),
),
);
} else {
GLOBALS.status_queue.write().write(
"Your key is not setup.".to_string(),
);
}
if widgets::clickable_label(
ui,
true,
RichText::new("⚡").size(18.0),
)
.on_hover_text("ZAP")
.clicked()
{
if GLOBALS.identity.is_unlocked() {
let _ = GLOBALS.to_overlord.send(
ToOverlordMessage::ZapStart(
note.event.id,
note.event.pubkey,
UncheckedUrl(lnurl),
),
);
} else {
GLOBALS
.status_queue
.write()
.write("Your key is not setup.".to_string());
}
} else {
widgets::clickable_label(
ui,
RichText::new("⚡").weak().size(18.0),
)
.on_hover_text("Note is not zappable (no relays)");
}
} else {
widgets::clickable_label(
ui,
RichText::new("⚡").weak().size(18.0),
false,
RichText::new("⚡").size(18.0),
)
.on_hover_text("Note is not zappable (no lnurl)");
.on_disabled_hover_text("Note is not zappable (no lnurl)");
}

// Show the zap total
Expand All @@ -978,15 +974,15 @@ pub fn render_note_inner(
true => "♥",
false => "♡",
};
if ui
.add(
Label::new(
RichText::new(default_reaction_icon).size(20.0),
)
.sense(Sense::click()),
)
.on_hover_cursor(egui::CursorIcon::Default)
.clicked()
if widgets::clickable_label(
ui,
true,
RichText::new(default_reaction_icon).size(20.0),
)
.on_disabled_hover_text(
"Can't react to note (no known relays for note)",
)
.clicked()
{
if !GLOBALS.identity.is_unlocked() {
GLOBALS
Expand Down
21 changes: 19 additions & 2 deletions gossip-bin/src/ui/feed/notedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

use nostr_types::{
ContentSegment, Event, EventDelegation, EventKind, Id, MilliSatoshi, NostrBech32, PublicKey,
ShatteredContent,
RelayUrl, ShatteredContent, Unixtime,
};

#[derive(PartialEq)]
Expand Down Expand Up @@ -54,6 +54,9 @@ pub(crate) struct NoteData {
/// The total amount of MilliSatoshi zapped to this note
pub zaptotal: MilliSatoshi,

/// Relays this event was seen on and when, if any
pub seen_on: Vec<(RelayUrl, Unixtime)>,

/// Has the current user reacted to this post?
pub self_already_reacted: bool,

Expand Down Expand Up @@ -243,6 +246,11 @@ impl NoteData {
_ => HashMap::new(),
};

let seen_on = GLOBALS
.storage
.get_event_seen_on_relay(event.id)
.unwrap_or_default();

NoteData {
event,
delegation,
Expand All @@ -254,6 +262,7 @@ impl NoteData {
mentions,
reactions,
zaptotal,
seen_on,
self_already_reacted,
shattered_content,
error_content,
Expand All @@ -262,7 +271,7 @@ impl NoteData {
}
}

pub(super) fn update_reactions(&mut self) {
pub(super) fn update(&mut self) {
let (mut reactions, self_already_reacted) = GLOBALS
.storage
.get_reactions(self.event.id)
Expand All @@ -272,6 +281,14 @@ impl NoteData {
self.reactions.append(&mut reactions);

self.self_already_reacted = self_already_reacted;

let mut seen_on = GLOBALS
.storage
.get_event_seen_on_relay(self.event.id)
.unwrap_or_default();

self.seen_on.clear();
self.seen_on.append(&mut seen_on);
}

#[allow(dead_code)]
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/feed/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Notes {
// get a mutable reference to update reactions, then give it back
if let Some(pair) = self.notes.get(id) {
if let Ok(mut mut_ref) = pair.try_borrow_mut() {
mut_ref.update_reactions();
mut_ref.update();
}
}
// return from cache
Expand Down
8 changes: 5 additions & 3 deletions gossip-bin/src/ui/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ pub fn truncated_label(ui: &mut Ui, text: impl Into<WidgetText>, max_width: f32)
}

/// Create a clickable label
pub fn clickable_label(ui: &mut Ui, text: impl Into<WidgetText>) -> Response {
let label = egui::Label::new(text).sense(Sense::click());
ui.add(label).on_hover_cursor(egui::CursorIcon::Default)
pub fn clickable_label(ui: &mut Ui, enabled: bool, text: impl Into<WidgetText>) -> Response {
let label = egui::Label::new(text)
.selectable(false)
.sense(Sense::click());
ui.add_enabled(enabled, label)
}

pub fn break_anywhere_hyperlink_to(ui: &mut Ui, text: impl Into<WidgetText>, url: impl ToString) {
Expand Down

0 comments on commit 8aa0d39

Please sign in to comment.