11use crate :: {
2+ actionbar:: NotesOpenResult ,
23 args:: { ColumnsArgs , ColumnsFlag } ,
34 column:: Columns ,
45 decks:: { Decks , DecksCache } ,
@@ -9,7 +10,9 @@ use crate::{
910 storage,
1011 subscriptions:: { SubKind , Subscriptions } ,
1112 support:: Support ,
12- timeline:: { self , kind:: ListKind , thread:: Threads , TimelineCache , TimelineKind } ,
13+ timeline:: {
14+ self , kind:: ListKind , thread:: Threads , ThreadSelection , TimelineCache , TimelineKind ,
15+ } ,
1316 ui:: { self , DesktopSidePanel , ShowSourceClientOption , SidePanelAction } ,
1417 view_state:: ViewState ,
1518 Result ,
@@ -19,7 +22,7 @@ use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPo
1922use nostrdb:: Transaction ;
2023use notedeck:: {
2124 tr, ui:: is_narrow, Accounts , AppAction , AppContext , DataPath , DataPathType , FilterState ,
22- Images , JobsCache , Localization , NotedeckOptions , SettingsHandler , UnknownIds ,
25+ Images , JobsCache , Localization , NotedeckOptions , OpenColumnInfo , SettingsHandler , UnknownIds ,
2326} ;
2427use notedeck_ui:: {
2528 media:: { MediaViewer , MediaViewerFlags , MediaViewerState } ,
@@ -574,6 +577,102 @@ impl Damus {
574577 pub fn unrecognized_args ( & self ) -> & BTreeSet < String > {
575578 & self . unrecognized_args
576579 }
580+
581+ fn process_open_column (
582+ & mut self ,
583+ info : & OpenColumnInfo ,
584+ next_col : usize ,
585+ app_ctx : & mut AppContext ,
586+ ) {
587+ match info {
588+ OpenColumnInfo :: Profile ( _) | OpenColumnInfo :: Hashtag ( _) => {
589+ let kind = {
590+ if let OpenColumnInfo :: Hashtag ( htag) = info {
591+ Some ( TimelineKind :: Hashtag ( vec ! [ htag. clone( ) ] ) )
592+ } else if let OpenColumnInfo :: Profile ( pk) = info {
593+ Some ( TimelineKind :: Profile ( * pk) )
594+ } else {
595+ None
596+ }
597+ } ;
598+
599+ let kind = kind. expect ( "kind expected" ) ;
600+
601+ let txn = Transaction :: new ( app_ctx. ndb ) . unwrap ( ) ;
602+
603+ if let Some ( result) = self
604+ . timeline_cache
605+ . open ( app_ctx. ndb , app_ctx. note_cache , & txn, app_ctx. pool , & kind)
606+ . map ( NotesOpenResult :: Timeline )
607+ {
608+ result. process (
609+ & mut self . threads ,
610+ app_ctx. ndb ,
611+ app_ctx. note_cache ,
612+ & txn,
613+ & mut self . timeline_cache ,
614+ app_ctx. unknown_ids ,
615+ ) ;
616+ }
617+
618+ let route = Route :: Timeline ( kind. clone ( ) ) ;
619+
620+ let columns = self . columns_mut ( app_ctx. i18n , app_ctx. accounts ) ;
621+
622+ columns. new_column_at_with_route ( next_col, route) ;
623+ columns. select_column ( next_col as i32 ) ;
624+ }
625+ OpenColumnInfo :: Note { note_id } => ' ex: {
626+ let txn = Transaction :: new ( app_ctx. ndb ) . unwrap ( ) ;
627+ let Ok ( thread_selection) =
628+ ThreadSelection :: from_note_id ( app_ctx. ndb , app_ctx. note_cache , & txn, * note_id)
629+ else {
630+ tracing:: error!( "No thread selection for {}?" , hex:: encode( note_id. bytes( ) ) ) ;
631+ break ' ex;
632+ } ;
633+ let route = Route :: Thread ( thread_selection. clone ( ) ) ;
634+
635+ if let Some ( result) = self
636+ . threads
637+ . open (
638+ app_ctx. ndb ,
639+ & txn,
640+ app_ctx. pool ,
641+ & thread_selection,
642+ true ,
643+ next_col,
644+ )
645+ . map ( NotesOpenResult :: Thread )
646+ {
647+ result. process (
648+ & mut self . threads ,
649+ app_ctx. ndb ,
650+ app_ctx. note_cache ,
651+ & txn,
652+ & mut self . timeline_cache ,
653+ app_ctx. unknown_ids ,
654+ ) ;
655+ }
656+
657+ let columns = self . columns_mut ( app_ctx. i18n , app_ctx. accounts ) ;
658+
659+ columns. new_column_at_with_route ( next_col, route) ;
660+ columns. select_column ( next_col as i32 ) ;
661+ }
662+ OpenColumnInfo :: Quote ( note_id) => {
663+ let columns = self . columns_mut ( app_ctx. i18n , app_ctx. accounts ) ;
664+
665+ columns. new_column_at_with_route ( next_col, Route :: quote ( * note_id) ) ;
666+ columns. select_column ( next_col as i32 ) ;
667+ }
668+ OpenColumnInfo :: Reply ( note_id) => {
669+ let columns = self . columns_mut ( app_ctx. i18n , app_ctx. accounts ) ;
670+
671+ columns. new_column_at_with_route ( next_col, Route :: reply ( * note_id) ) ;
672+ columns. select_column ( next_col as i32 ) ;
673+ }
674+ }
675+ }
577676}
578677
579678fn get_note_options ( args : ColumnsArgs , settings_handler : & mut SettingsHandler ) -> NoteOptions {
@@ -651,6 +750,11 @@ fn render_damus_mobile(
651750 ProcessNavResult :: PfpClicked => {
652751 app_action = Some ( AppAction :: ToggleChrome ) ;
653752 }
753+
754+ ProcessNavResult :: OpenColumn ( ( col, info) ) => {
755+ let next_col = * col + 1 ;
756+ app. process_open_column ( info, next_col, app_ctx) ;
757+ }
654758 }
655759 }
656760 }
@@ -767,9 +871,9 @@ fn timelines_view(
767871 ui : & mut egui:: Ui ,
768872 sizes : Size ,
769873 app : & mut Damus ,
770- ctx : & mut AppContext < ' _ > ,
874+ app_ctx : & mut AppContext < ' _ > ,
771875) -> Option < AppAction > {
772- let num_cols = get_active_columns ( ctx . accounts , & app. decks_cache ) . num_columns ( ) ;
876+ let num_cols = get_active_columns ( app_ctx . accounts , & app. decks_cache ) . num_columns ( ) ;
773877 let mut side_panel_action: Option < nav:: SwitchingAction > = None ;
774878 let mut responses = Vec :: with_capacity ( num_cols) ;
775879
@@ -781,19 +885,19 @@ fn timelines_view(
781885 strip. cell ( |ui| {
782886 let rect = ui. available_rect_before_wrap ( ) ;
783887 let side_panel = DesktopSidePanel :: new (
784- ctx . accounts . get_selected_account ( ) ,
888+ app_ctx . accounts . get_selected_account ( ) ,
785889 & app. decks_cache ,
786- ctx . i18n ,
890+ app_ctx . i18n ,
787891 )
788892 . show ( ui) ;
789893
790894 if let Some ( side_panel) = side_panel {
791895 if side_panel. response . clicked ( ) || side_panel. response . secondary_clicked ( ) {
792896 if let Some ( action) = DesktopSidePanel :: perform_action (
793897 & mut app. decks_cache ,
794- ctx . accounts ,
898+ app_ctx . accounts ,
795899 side_panel. action ,
796- ctx . i18n ,
900+ app_ctx . i18n ,
797901 ) {
798902 side_panel_action = Some ( action) ;
799903 }
@@ -828,7 +932,7 @@ fn timelines_view(
828932 inner. set_right ( rect. right ( ) - v_line_stroke. width ) ;
829933 inner
830934 } ;
831- responses. push ( nav:: render_nav ( col_index, inner_rect, app, ctx , ui) ) ;
935+ responses. push ( nav:: render_nav ( col_index, inner_rect, app, app_ctx , ui) ) ;
832936
833937 // vertical line
834938 ui. painter ( )
@@ -849,13 +953,18 @@ fn timelines_view(
849953 let mut save_cols = false ;
850954 if let Some ( action) = side_panel_action {
851955 save_cols = save_cols
852- || action. process ( & mut app. timeline_cache , & mut app. decks_cache , ctx, ui. ctx ( ) ) ;
956+ || action. process (
957+ & mut app. timeline_cache ,
958+ & mut app. decks_cache ,
959+ app_ctx,
960+ ui. ctx ( ) ,
961+ ) ;
853962 }
854963
855964 let mut app_action: Option < AppAction > = None ;
856965
857966 for response in responses {
858- let nav_result = response. process_render_nav_response ( app, ctx , ui) ;
967+ let nav_result = response. process_render_nav_response ( app, app_ctx , ui) ;
859968
860969 if let Some ( nr) = & nav_result {
861970 match nr {
@@ -864,6 +973,13 @@ fn timelines_view(
864973 ProcessNavResult :: PfpClicked => {
865974 app_action = Some ( AppAction :: ToggleChrome ) ;
866975 }
976+
977+ ProcessNavResult :: OpenColumn ( ( col, info) ) => {
978+ let next_col = * col + 1 ;
979+ app. process_open_column ( info, next_col, app_ctx) ;
980+
981+ save_cols = true
982+ }
867983 }
868984 }
869985 }
@@ -873,7 +989,7 @@ fn timelines_view(
873989 }
874990
875991 if save_cols {
876- storage:: save_decks_cache ( ctx . path , & app. decks_cache ) ;
992+ storage:: save_decks_cache ( app_ctx . path , & app. decks_cache ) ;
877993 }
878994
879995 app_action
0 commit comments