mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-23 11:14:19 +01:00
hashtags: click hashtags to open them
Fixes: https://github.com/damus-io/notedeck/issues/695 Fixes: https://github.com/damus-io/notedeck/issues/713 Changelog-Added: Add ability to click hashtags Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,20 +1,19 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
column::Columns,
|
column::Columns,
|
||||||
route::{Route, Router},
|
route::{Route, Router},
|
||||||
timeline::{ThreadSelection, TimelineCache, TimelineKind},
|
timeline::{TimelineCache, TimelineKind},
|
||||||
};
|
};
|
||||||
|
|
||||||
use enostr::{NoteId, Pubkey, RelayPool};
|
use enostr::{NoteId, RelayPool};
|
||||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||||
use notedeck::{note::root_note_id_from_selected_id, NoteCache, RootIdError, UnknownIds};
|
use notedeck::{NoteCache, UnknownIds};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum NoteAction {
|
pub enum NoteAction {
|
||||||
Reply(NoteId),
|
Reply(NoteId),
|
||||||
Quote(NoteId),
|
Quote(NoteId),
|
||||||
OpenThread(NoteId),
|
OpenTimeline(TimelineKind),
|
||||||
OpenProfile(Pubkey),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NewNotes {
|
pub struct NewNotes {
|
||||||
@@ -26,52 +25,6 @@ pub enum TimelineOpenResult {
|
|||||||
NewNotes(NewNotes),
|
NewNotes(NewNotes),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// open_thread is called when a note is selected and we need to navigate
|
|
||||||
/// to a thread It is responsible for managing the subscription and
|
|
||||||
/// making sure the thread is up to date. In a sense, it's a model for
|
|
||||||
/// the thread view. We don't have a concept of model/view/controller etc
|
|
||||||
/// in egui, but this is the closest thing to that.
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn open_thread(
|
|
||||||
ndb: &Ndb,
|
|
||||||
txn: &Transaction,
|
|
||||||
router: &mut Router<Route>,
|
|
||||||
note_cache: &mut NoteCache,
|
|
||||||
pool: &mut RelayPool,
|
|
||||||
timeline_cache: &mut TimelineCache,
|
|
||||||
selected_note: &[u8; 32],
|
|
||||||
) -> Option<TimelineOpenResult> {
|
|
||||||
router.route_to(Route::thread(
|
|
||||||
ThreadSelection::from_note_id(ndb, note_cache, txn, NoteId::new(*selected_note)).ok()?,
|
|
||||||
));
|
|
||||||
|
|
||||||
match root_note_id_from_selected_id(ndb, note_cache, txn, selected_note) {
|
|
||||||
Ok(root_id) => timeline_cache.open(
|
|
||||||
ndb,
|
|
||||||
note_cache,
|
|
||||||
txn,
|
|
||||||
pool,
|
|
||||||
&TimelineKind::Thread(ThreadSelection::from_root_id(root_id.to_owned())),
|
|
||||||
),
|
|
||||||
|
|
||||||
Err(RootIdError::NoteNotFound) => {
|
|
||||||
error!(
|
|
||||||
"open_thread: note not found: {}",
|
|
||||||
hex::encode(selected_note)
|
|
||||||
);
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(RootIdError::NoRootId) => {
|
|
||||||
error!(
|
|
||||||
"open_thread: note has no root id: {}",
|
|
||||||
hex::encode(selected_note)
|
|
||||||
);
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NoteAction {
|
impl NoteAction {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn execute(
|
pub fn execute(
|
||||||
@@ -89,19 +42,9 @@ impl NoteAction {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
NoteAction::OpenThread(note_id) => open_thread(
|
NoteAction::OpenTimeline(kind) => {
|
||||||
ndb,
|
router.route_to(Route::Timeline(kind.to_owned()));
|
||||||
txn,
|
timeline_cache.open(ndb, note_cache, txn, pool, kind)
|
||||||
router,
|
|
||||||
note_cache,
|
|
||||||
pool,
|
|
||||||
timeline_cache,
|
|
||||||
note_id.bytes(),
|
|
||||||
),
|
|
||||||
|
|
||||||
NoteAction::OpenProfile(pubkey) => {
|
|
||||||
router.route_to(Route::profile(*pubkey));
|
|
||||||
timeline_cache.open(ndb, note_cache, txn, pool, &TimelineKind::Profile(*pubkey))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NoteAction::Quote(note_id) => {
|
NoteAction::Quote(note_id) => {
|
||||||
@@ -114,7 +57,7 @@ impl NoteAction {
|
|||||||
/// Execute the NoteAction and process the TimelineOpenResult
|
/// Execute the NoteAction and process the TimelineOpenResult
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn execute_and_process_result(
|
pub fn execute_and_process_result(
|
||||||
self,
|
&self,
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
columns: &mut Columns,
|
columns: &mut Columns,
|
||||||
col: usize,
|
col: usize,
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ impl TimelineKind {
|
|||||||
TimelineKind::Hashtag(hashtag) => FilterState::ready(vec![Filter::new()
|
TimelineKind::Hashtag(hashtag) => FilterState::ready(vec![Filter::new()
|
||||||
.kinds([1])
|
.kinds([1])
|
||||||
.limit(filter::default_limit())
|
.limit(filter::default_limit())
|
||||||
.tags([hashtag.clone()], 't')
|
.tags([hashtag.to_lowercase()], 't')
|
||||||
.build()]),
|
.build()]),
|
||||||
|
|
||||||
TimelineKind::Algo(algo_timeline) => match algo_timeline {
|
TimelineKind::Algo(algo_timeline) => match algo_timeline {
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ impl Timeline {
|
|||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
.kinds([1])
|
.kinds([1])
|
||||||
.limit(filter::default_limit())
|
.limit(filter::default_limit())
|
||||||
.tags([hashtag.clone()], 't')
|
.tags([hashtag.to_lowercase()], 't')
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Timeline::new(
|
Timeline::new(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::ui;
|
use crate::ui;
|
||||||
use crate::{actionbar::NoteAction, profile::get_display_name};
|
use crate::{actionbar::NoteAction, profile::get_display_name, timeline::TimelineKind};
|
||||||
use egui::Sense;
|
use egui::Sense;
|
||||||
use enostr::Pubkey;
|
use enostr::Pubkey;
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
@@ -89,7 +89,9 @@ fn mention_ui(
|
|||||||
|
|
||||||
let note_action = if resp.clicked() {
|
let note_action = if resp.clicked() {
|
||||||
ui::show_pointer(ui);
|
ui::show_pointer(ui);
|
||||||
Some(NoteAction::OpenProfile(Pubkey::new(*pk)))
|
Some(NoteAction::OpenTimeline(TimelineKind::profile(
|
||||||
|
Pubkey::new(*pk),
|
||||||
|
)))
|
||||||
} else if resp.hovered() {
|
} else if resp.hovered() {
|
||||||
ui::show_pointer(ui);
|
ui::show_pointer(ui);
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use crate::actionbar::NoteAction;
|
|
||||||
use crate::images::ImageType;
|
|
||||||
use crate::ui::{
|
use crate::ui::{
|
||||||
self,
|
self,
|
||||||
note::{NoteOptions, NoteResponse},
|
note::{NoteOptions, NoteResponse},
|
||||||
ProfilePic,
|
ProfilePic,
|
||||||
};
|
};
|
||||||
|
use crate::{actionbar::NoteAction, images::ImageType, timeline::TimelineKind};
|
||||||
use egui::{Color32, Hyperlink, Image, RichText};
|
use egui::{Color32, Hyperlink, Image, RichText};
|
||||||
use nostrdb::{BlockType, Mention, Ndb, Note, NoteKey, Transaction};
|
use nostrdb::{BlockType, Mention, Ndb, Note, NoteKey, Transaction};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
@@ -198,7 +197,15 @@ fn render_note_contents(
|
|||||||
BlockType::Hashtag => {
|
BlockType::Hashtag => {
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_scope!("hashtag contents");
|
puffin::profile_scope!("hashtag contents");
|
||||||
ui.colored_label(link_color, format!("#{}", block.as_str()));
|
let resp = ui.colored_label(link_color, format!("#{}", block.as_str()));
|
||||||
|
|
||||||
|
if resp.clicked() {
|
||||||
|
note_action = Some(NoteAction::OpenTimeline(TimelineKind::Hashtag(
|
||||||
|
block.as_str().to_string(),
|
||||||
|
)));
|
||||||
|
} else if resp.hovered() {
|
||||||
|
ui::show_pointer(ui);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockType::Url => {
|
BlockType::Url => {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub use reply_description::reply_desc;
|
|||||||
use crate::{
|
use crate::{
|
||||||
actionbar::NoteAction,
|
actionbar::NoteAction,
|
||||||
profile::get_display_name,
|
profile::get_display_name,
|
||||||
|
timeline::{ThreadSelection, TimelineKind},
|
||||||
ui::{self, View},
|
ui::{self, View},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -354,8 +355,9 @@ impl<'a> NoteView<'a> {
|
|||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if self.pfp(note_key, &profile, ui).clicked() {
|
if self.pfp(note_key, &profile, ui).clicked() {
|
||||||
note_action =
|
note_action = Some(NoteAction::OpenTimeline(TimelineKind::profile(
|
||||||
Some(NoteAction::OpenProfile(Pubkey::new(*self.note.pubkey())));
|
Pubkey::new(*self.note.pubkey()),
|
||||||
|
)));
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = ui.available_size();
|
let size = ui.available_size();
|
||||||
@@ -415,7 +417,7 @@ impl<'a> NoteView<'a> {
|
|||||||
ui.add(&mut contents);
|
ui.add(&mut contents);
|
||||||
|
|
||||||
if let Some(action) = contents.action() {
|
if let Some(action) = contents.action() {
|
||||||
note_action = Some(*action);
|
note_action = Some(action.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options().has_actionbar() {
|
if self.options().has_actionbar() {
|
||||||
@@ -430,7 +432,9 @@ impl<'a> NoteView<'a> {
|
|||||||
// main design
|
// main design
|
||||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||||
if self.pfp(note_key, &profile, ui).clicked() {
|
if self.pfp(note_key, &profile, ui).clicked() {
|
||||||
note_action = Some(NoteAction::OpenProfile(Pubkey::new(*self.note.pubkey())));
|
note_action = Some(NoteAction::OpenTimeline(TimelineKind::Profile(
|
||||||
|
Pubkey::new(*self.note.pubkey()),
|
||||||
|
)));
|
||||||
};
|
};
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||||
@@ -480,7 +484,7 @@ impl<'a> NoteView<'a> {
|
|||||||
ui.add(&mut contents);
|
ui.add(&mut contents);
|
||||||
|
|
||||||
if let Some(action) = contents.action() {
|
if let Some(action) = contents.action() {
|
||||||
note_action = Some(*action);
|
note_action = Some(action.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options().has_actionbar() {
|
if self.options().has_actionbar() {
|
||||||
@@ -496,7 +500,16 @@ impl<'a> NoteView<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
||||||
Some(NoteAction::OpenThread(NoteId::new(*self.note.id())))
|
if let Ok(selection) = ThreadSelection::from_note_id(
|
||||||
|
self.ndb,
|
||||||
|
self.note_cache,
|
||||||
|
self.note.txn().unwrap(),
|
||||||
|
NoteId::new(*self.note.id()),
|
||||||
|
) {
|
||||||
|
Some(NoteAction::OpenTimeline(TimelineKind::Thread(selection)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
note_action
|
note_action
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user