Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/notedeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub use muted::{MuteFun, Muted};
pub use name::NostrName;
pub use note::{
BroadcastContext, ContextSelection, NoteAction, NoteContext, NoteContextSelection, NoteRef,
RootIdError, RootNoteId, RootNoteIdBuf, ScrollInfo, ZapAction,
OpenColumnInfo, RootIdError, RootNoteId, RootNoteIdBuf, ScrollInfo, ZapAction,
};
pub use notecache::{CachedNote, NoteCache};
pub use options::NotedeckOptions;
Expand Down
26 changes: 25 additions & 1 deletion crates/notedeck/src/note/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ pub struct ScrollInfo {
pub offset: Vec2,
}

#[derive(Debug, PartialEq)]
pub enum OpenColumnInfo {
/// User has clicked the quote reply action
Reply(NoteId),

/// User has clicked the quote repost action
Quote(NoteId),

/// User has clicked a hashtag
Hashtag(String),

/// User has clicked a profile
Profile(Pubkey),

Note {
note_id: NoteId,
},
}

#[derive(Debug)]
pub enum NoteAction {
/// User has clicked the quote reply action
Expand All @@ -24,7 +43,10 @@ pub enum NoteAction {
Profile(Pubkey),

/// User has clicked a note link
Note { note_id: NoteId, preview: bool },
Note {
note_id: NoteId,
preview: bool,
},

/// User has selected some context option
Context(ContextSelection),
Expand All @@ -37,6 +59,8 @@ pub enum NoteAction {

/// User scrolled the timeline
Scroll(ScrollInfo),

OpenColumn(OpenColumnInfo),
}

impl NoteAction {
Expand Down
2 changes: 1 addition & 1 deletion crates/notedeck/src/note/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod action;
mod context;

pub use action::{NoteAction, ScrollInfo, ZapAction, ZapTargetAmount};
pub use action::{NoteAction, OpenColumnInfo, ScrollInfo, ZapAction, ZapTargetAmount};
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};

use crate::Accounts;
Expand Down
10 changes: 8 additions & 2 deletions crates/notedeck_chrome/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ impl ChromePanelAction {
chrome.switch_to_columns();

if let Some(c) = chrome.get_columns_app().and_then(|columns| {
columns
.decks_cache
.active_columns_mut(ctx.i18n, ctx.accounts)
.unwrap()
.selected = 0;

columns
.decks_cache
.selected_column_mut(ctx.i18n, ctx.accounts)
Expand Down Expand Up @@ -847,7 +853,7 @@ fn chrome_handle_app_action(
if let Some(action) = m_action {
let col = cols.selected_mut();

action.process(&mut col.router, &mut col.sheet_router);
action.process(0, &mut col.router, &mut col.sheet_router);
}
}
}
Expand Down Expand Up @@ -903,7 +909,7 @@ fn columns_route_to_profile(
if let Some(action) = m_action {
let col = cols.selected_mut();

action.process(&mut col.router, &mut col.sheet_router);
action.process(0, &mut col.router, &mut col.sheet_router);
}
}

Expand Down
33 changes: 25 additions & 8 deletions crates/notedeck_columns/src/actionbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ pub enum NotesOpenResult {
Thread(NewThreadNotes),
}

impl NotesOpenResult {
pub fn process(
self,
threads: &mut Threads,
ndb: &Ndb,
note_cache: &mut NoteCache,
txn: &Transaction,
timeline_cache: &mut TimelineCache,
unknown_ids: &mut UnknownIds,
) {
match self {
NotesOpenResult::Timeline(timeline_open_result) => {
timeline_open_result.process(ndb, note_cache, txn, timeline_cache, unknown_ids);
}
NotesOpenResult::Thread(thread_open_result) => {
thread_open_result.process(threads, ndb, txn, unknown_ids, note_cache);
}
}
}
}

pub enum TimelineOpenResult {
NewNotes(NewNotes),
}
Expand Down Expand Up @@ -81,6 +102,9 @@ fn execute_note_action(
.open(ndb, note_cache, txn, pool, &kind)
.map(NotesOpenResult::Timeline);
}
NoteAction::OpenColumn(args) => {
router_action = Some(RouterAction::OpenColumn(args));
}
NoteAction::Note { note_id, preview } => 'ex: {
let Ok(thread_selection) = ThreadSelection::from_note_id(ndb, note_cache, txn, note_id)
else {
Expand Down Expand Up @@ -224,14 +248,7 @@ pub fn execute_and_process_note_action(
);

if let Some(br) = resp.timeline_res {
match br {
NotesOpenResult::Timeline(timeline_open_result) => {
timeline_open_result.process(ndb, note_cache, txn, timeline_cache, unknown_ids);
}
NotesOpenResult::Thread(thread_open_result) => {
thread_open_result.process(threads, ndb, txn, unknown_ids, note_cache);
}
}
br.process(threads, ndb, note_cache, txn, timeline_cache, unknown_ids);
}

resp.router_action
Expand Down
140 changes: 128 additions & 12 deletions crates/notedeck_columns/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
actionbar::NotesOpenResult,
args::{ColumnsArgs, ColumnsFlag},
column::Columns,
decks::{Decks, DecksCache},
Expand All @@ -9,7 +10,9 @@ use crate::{
storage,
subscriptions::{SubKind, Subscriptions},
support::Support,
timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind},
timeline::{
self, kind::ListKind, thread::Threads, ThreadSelection, TimelineCache, TimelineKind,
},
ui::{self, DesktopSidePanel, ShowSourceClientOption, SidePanelAction},
view_state::ViewState,
Result,
Expand All @@ -19,7 +22,7 @@ use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPo
use nostrdb::Transaction;
use notedeck::{
tr, ui::is_narrow, Accounts, AppAction, AppContext, DataPath, DataPathType, FilterState,
Images, JobsCache, Localization, NotedeckOptions, SettingsHandler, UnknownIds,
Images, JobsCache, Localization, NotedeckOptions, OpenColumnInfo, SettingsHandler, UnknownIds,
};
use notedeck_ui::{
media::{MediaViewer, MediaViewerFlags, MediaViewerState},
Expand Down Expand Up @@ -574,6 +577,102 @@ impl Damus {
pub fn unrecognized_args(&self) -> &BTreeSet<String> {
&self.unrecognized_args
}

fn process_open_column(
&mut self,
info: &OpenColumnInfo,
next_col: usize,
app_ctx: &mut AppContext,
) {
match info {
OpenColumnInfo::Profile(_) | OpenColumnInfo::Hashtag(_) => {
let kind = {
if let OpenColumnInfo::Hashtag(htag) = info {
Some(TimelineKind::Hashtag(vec![htag.clone()]))
} else if let OpenColumnInfo::Profile(pk) = info {
Some(TimelineKind::Profile(*pk))
} else {
None
}
};

let kind = kind.expect("kind expected");

let txn = Transaction::new(app_ctx.ndb).unwrap();

if let Some(result) = self
.timeline_cache
.open(app_ctx.ndb, app_ctx.note_cache, &txn, app_ctx.pool, &kind)
.map(NotesOpenResult::Timeline)
{
result.process(
&mut self.threads,
app_ctx.ndb,
app_ctx.note_cache,
&txn,
&mut self.timeline_cache,
app_ctx.unknown_ids,
);
}

let route = Route::Timeline(kind.clone());

let columns = self.columns_mut(app_ctx.i18n, app_ctx.accounts);

columns.new_column_at_with_route(next_col, route);
columns.select_column(next_col as i32);
}
OpenColumnInfo::Note { note_id } => 'ex: {
let txn = Transaction::new(app_ctx.ndb).unwrap();
let Ok(thread_selection) =
ThreadSelection::from_note_id(app_ctx.ndb, app_ctx.note_cache, &txn, *note_id)
else {
tracing::error!("No thread selection for {}?", hex::encode(note_id.bytes()));
break 'ex;
};
let route = Route::Thread(thread_selection.clone());

if let Some(result) = self
.threads
.open(
app_ctx.ndb,
&txn,
app_ctx.pool,
&thread_selection,
true,
next_col,
)
.map(NotesOpenResult::Thread)
{
result.process(
&mut self.threads,
app_ctx.ndb,
app_ctx.note_cache,
&txn,
&mut self.timeline_cache,
app_ctx.unknown_ids,
);
}

let columns = self.columns_mut(app_ctx.i18n, app_ctx.accounts);

columns.new_column_at_with_route(next_col, route);
columns.select_column(next_col as i32);
}
OpenColumnInfo::Quote(note_id) => {
let columns = self.columns_mut(app_ctx.i18n, app_ctx.accounts);

columns.new_column_at_with_route(next_col, Route::quote(*note_id));
columns.select_column(next_col as i32);
}
OpenColumnInfo::Reply(note_id) => {
let columns = self.columns_mut(app_ctx.i18n, app_ctx.accounts);

columns.new_column_at_with_route(next_col, Route::reply(*note_id));
columns.select_column(next_col as i32);
}
}
}
}

fn get_note_options(args: ColumnsArgs, settings_handler: &mut SettingsHandler) -> NoteOptions {
Expand Down Expand Up @@ -651,6 +750,11 @@ fn render_damus_mobile(
ProcessNavResult::PfpClicked => {
app_action = Some(AppAction::ToggleChrome);
}

ProcessNavResult::OpenColumn((col, info)) => {
let next_col = *col + 1;
app.process_open_column(info, next_col, app_ctx);
}
}
}
}
Expand Down Expand Up @@ -767,9 +871,9 @@ fn timelines_view(
ui: &mut egui::Ui,
sizes: Size,
app: &mut Damus,
ctx: &mut AppContext<'_>,
app_ctx: &mut AppContext<'_>,
) -> Option<AppAction> {
let num_cols = get_active_columns(ctx.accounts, &app.decks_cache).num_columns();
let num_cols = get_active_columns(app_ctx.accounts, &app.decks_cache).num_columns();
let mut side_panel_action: Option<nav::SwitchingAction> = None;
let mut responses = Vec::with_capacity(num_cols);

Expand All @@ -781,19 +885,19 @@ fn timelines_view(
strip.cell(|ui| {
let rect = ui.available_rect_before_wrap();
let side_panel = DesktopSidePanel::new(
ctx.accounts.get_selected_account(),
app_ctx.accounts.get_selected_account(),
&app.decks_cache,
ctx.i18n,
app_ctx.i18n,
)
.show(ui);

if let Some(side_panel) = side_panel {
if side_panel.response.clicked() || side_panel.response.secondary_clicked() {
if let Some(action) = DesktopSidePanel::perform_action(
&mut app.decks_cache,
ctx.accounts,
app_ctx.accounts,
side_panel.action,
ctx.i18n,
app_ctx.i18n,
) {
side_panel_action = Some(action);
}
Expand Down Expand Up @@ -828,7 +932,7 @@ fn timelines_view(
inner.set_right(rect.right() - v_line_stroke.width);
inner
};
responses.push(nav::render_nav(col_index, inner_rect, app, ctx, ui));
responses.push(nav::render_nav(col_index, inner_rect, app, app_ctx, ui));

// vertical line
ui.painter()
Expand All @@ -849,13 +953,18 @@ fn timelines_view(
let mut save_cols = false;
if let Some(action) = side_panel_action {
save_cols = save_cols
|| action.process(&mut app.timeline_cache, &mut app.decks_cache, ctx, ui.ctx());
|| action.process(
&mut app.timeline_cache,
&mut app.decks_cache,
app_ctx,
ui.ctx(),
);
}

let mut app_action: Option<AppAction> = None;

for response in responses {
let nav_result = response.process_render_nav_response(app, ctx, ui);
let nav_result = response.process_render_nav_response(app, app_ctx, ui);

if let Some(nr) = &nav_result {
match nr {
Expand All @@ -864,6 +973,13 @@ fn timelines_view(
ProcessNavResult::PfpClicked => {
app_action = Some(AppAction::ToggleChrome);
}

ProcessNavResult::OpenColumn((col, info)) => {
let next_col = *col + 1;
app.process_open_column(info, next_col, app_ctx);

save_cols = true
}
}
}
}
Expand All @@ -873,7 +989,7 @@ fn timelines_view(
}

if save_cols {
storage::save_decks_cache(ctx.path, &app.decks_cache);
storage::save_decks_cache(app_ctx.path, &app.decks_cache);
}

app_action
Expand Down
Loading
Loading