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::{
|
||||
column::Columns,
|
||||
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 notedeck::{note::root_note_id_from_selected_id, NoteCache, RootIdError, UnknownIds};
|
||||
use notedeck::{NoteCache, UnknownIds};
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub enum NoteAction {
|
||||
Reply(NoteId),
|
||||
Quote(NoteId),
|
||||
OpenThread(NoteId),
|
||||
OpenProfile(Pubkey),
|
||||
OpenTimeline(TimelineKind),
|
||||
}
|
||||
|
||||
pub struct NewNotes {
|
||||
@@ -26,52 +25,6 @@ pub enum TimelineOpenResult {
|
||||
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 {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn execute(
|
||||
@@ -89,19 +42,9 @@ impl NoteAction {
|
||||
None
|
||||
}
|
||||
|
||||
NoteAction::OpenThread(note_id) => open_thread(
|
||||
ndb,
|
||||
txn,
|
||||
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::OpenTimeline(kind) => {
|
||||
router.route_to(Route::Timeline(kind.to_owned()));
|
||||
timeline_cache.open(ndb, note_cache, txn, pool, kind)
|
||||
}
|
||||
|
||||
NoteAction::Quote(note_id) => {
|
||||
@@ -114,7 +57,7 @@ impl NoteAction {
|
||||
/// Execute the NoteAction and process the TimelineOpenResult
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn execute_and_process_result(
|
||||
self,
|
||||
&self,
|
||||
ndb: &Ndb,
|
||||
columns: &mut Columns,
|
||||
col: usize,
|
||||
|
||||
Reference in New Issue
Block a user