@@ -305,10 +305,12 @@ def read_message(self, index: int = -1) -> None:
305
305
self .model .mark_message_ids_as_read (read_msg_ids )
306
306
307
307
308
+
308
309
class RecentConversationsView (urwid .Frame ):
309
310
def __init__ (self , controller : Any ) -> None :
310
311
self .controller = controller
311
312
self .model = controller .model
313
+
312
314
self .conversations = self .model .group_recent_conversations ()
313
315
self .all_conversations = self .conversations .copy ()
314
316
self .search_lock = threading .Lock ()
@@ -327,9 +329,13 @@ def __init__(self, controller: Any) -> None:
327
329
list_box = urwid .ListBox (self .log )
328
330
329
331
super ().__init__ (list_box , header = search_header )
332
+
330
333
if len (self .log ) > 1 :
331
- self .body .set_focus_valign ("middle" ) # Fix: Call on self.body (the ListBox)
332
- self .log .set_focus (1 ) # Focus on first conversation row
334
+ self .log .set_focus (1 )
335
+ self .body .set_focus (1 )
336
+ self .set_focus ("body" )
337
+ self .body .set_focus_valign ("middle" )
338
+
333
339
334
340
def _build_body_contents (
335
341
self , conversations : List [Dict [str , Any ]]
@@ -343,6 +349,10 @@ def _build_body_contents(
343
349
contents .append (row )
344
350
345
351
return contents
352
+ def focus_restored (self ) -> None :
353
+ if self .focus_position is not None :
354
+ self .set_focus (self .focus_position )
355
+ self .controller .update_screen ()
346
356
347
357
def _build_header_row (self ) -> urwid .Widget :
348
358
columns = [
@@ -372,11 +382,11 @@ def _build_conversation_row(self, conv: Dict[str, Any], idx: int) -> urwid.Widge
372
382
("weight" , 1 , urwid .Text (time )),
373
383
]
374
384
row = urwid .Columns (columns , dividechars = 1 )
375
-
385
+ focus_style = "selected"
386
+ decorated_row = urwid .AttrMap (row , None , focus_style )
376
387
button = urwid .Button ("" , on_press = self ._on_row_click , user_data = conv )
377
- button ._label = row
378
- button ._w = urwid .AttrMap (row , None , "highlight" )
379
-
388
+ button ._label = f"#{ stream } / { topic } " # Fixed: Use a string
389
+ button ._w = decorated_row
380
390
return button
381
391
382
392
def _on_row_click (self , button : urwid .Button , conv : Dict [str , Any ]) -> None :
@@ -403,7 +413,6 @@ def update_conversations(self, search_box: Any, new_text: str) -> None:
403
413
]
404
414
405
415
self .empty_search = len (filtered_conversations ) == 0
406
-
407
416
self .log .clear ()
408
417
if not self .empty_search :
409
418
self .log .extend (self ._build_body_contents (filtered_conversations ))
@@ -412,11 +421,11 @@ def update_conversations(self, search_box: Any, new_text: str) -> None:
412
421
413
422
if len (self .log ) > 1 :
414
423
self .log .set_focus (1 )
415
- self . controller . update_screen ()
424
+
416
425
417
426
def mouse_event (
418
427
self ,
419
- size : tuple [int , int ],
428
+ size : Tuple [int , int ],
420
429
event : str ,
421
430
button : int ,
422
431
col : int ,
@@ -434,7 +443,7 @@ def mouse_event(
434
443
return True
435
444
return super ().mouse_event (size , event , button , col , row , focus )
436
445
437
- def keypress (self , size : tuple [int , int ], key : str ) -> Optional [str ]:
446
+ def keypress (self , size : Tuple [int , int ], key : str ) -> Optional [str ]:
438
447
if is_command_key ("SEARCH_RECENT_CONVERSATIONS" , key ):
439
448
self .set_focus ("header" )
440
449
self .search_box .set_caption (" " )
@@ -467,9 +476,20 @@ def keypress(self, size: tuple[int, int], key: str) -> Optional[str]:
467
476
elif is_command_key ("ALL_MESSAGES" , key ):
468
477
self .controller .view .middle_column .set_view ("messages" )
469
478
return None
479
+ elif is_command_key ("GO_RIGHT" , key ):
480
+ self .controller .view .show_right_panel (visible = True )
481
+ self .controller .view .body .set_focus (2 )
482
+ self .set_focus ("body" )
483
+ self .controller .update_screen ()
484
+ return None
485
+ elif is_command_key ("GO_LEFT" , key ):
486
+ self .controller .view .show_left_panel (visible = True )
487
+ self .controller .view .body .set_focus (0 )
488
+ self .set_focus ("body" )
489
+ self .controller .update_screen ()
490
+ return None
470
491
return super ().keypress (size , key )
471
492
472
-
473
493
class StreamsViewDivider (urwid .Divider ):
474
494
"""
475
495
A custom urwid.Divider to visually separate pinned and unpinned streams.
@@ -716,7 +736,6 @@ def mouse_event(
716
736
self .keypress (size , primary_key_for_command ("GO_DOWN" ))
717
737
return super ().mouse_event (size , event , button , col , row , focus )
718
738
719
-
720
739
class MiddleColumnView (urwid .Frame ):
721
740
def __init__ (self , view : Any , model : Any , write_box : Any , search_box : Any ) -> None :
722
741
self .model = model
@@ -733,6 +752,7 @@ def __init__(self, view: Any, model: Any, write_box: Any, search_box: Any) -> No
733
752
super ().__init__ (self .message_view , header = search_box , footer = write_box )
734
753
735
754
def set_view (self , view_name : str ) -> None :
755
+
736
756
if view_name == "recent" :
737
757
self .current_view = self .recent_convo_view
738
758
header = None
@@ -756,6 +776,7 @@ def check_narrow_and_switch_view(self) -> None:
756
776
"""
757
777
Check if the model's narrow has changed and switch to MessageView if necessary.
758
778
"""
779
+
759
780
current_narrow = self .model .narrow
760
781
if (
761
782
current_narrow != self .last_narrow
@@ -764,7 +785,7 @@ def check_narrow_and_switch_view(self) -> None:
764
785
self .set_view ("messages" )
765
786
self .last_narrow = current_narrow
766
787
767
- def keypress (self , size : tuple [int , int ], key : str ) -> Optional [str ]:
788
+ def keypress (self , size : Tuple [int , int ], key : str ) -> Optional [str ]:
768
789
self .check_narrow_and_switch_view ()
769
790
770
791
if self .focus_position in ["footer" , "header" ]:
@@ -807,11 +828,9 @@ def keypress(self, size: tuple[int, int], key: str) -> Optional[str]:
807
828
808
829
elif is_command_key ("GO_LEFT" , key ):
809
830
self .view .show_left_panel (visible = True )
810
- return None
811
831
812
832
elif is_command_key ("GO_RIGHT" , key ):
813
833
self .view .show_right_panel (visible = True )
814
- return None
815
834
816
835
elif is_command_key ("NEXT_UNREAD_TOPIC" , key ):
817
836
narrow = self .model .narrow
@@ -862,7 +881,7 @@ def keypress(self, size: tuple[int, int], key: str) -> Optional[str]:
862
881
): # 'r', 'enter', '@', '>', 'R'
863
882
if self .current_view != self .message_view :
864
883
self .set_view ("messages" )
865
- if self .message_view .log :
884
+ if len ( self .message_view .log ) > 0 :
866
885
self .message_view .set_focus (len (self .message_view .log ) - 1 )
867
886
self .current_view .keypress (size , key )
868
887
if self .footer .focus is not None :
@@ -871,20 +890,30 @@ def keypress(self, size: tuple[int, int], key: str) -> Optional[str]:
871
890
return None
872
891
873
892
elif is_command_key ("STREAM_MESSAGE" , key ):
893
+ if self .controller .is_in_editor_mode ():
894
+ self .controller .exit_editor_mode ()
874
895
if self .current_view != self .message_view :
875
896
self .set_view ("messages" )
876
897
self .current_view .keypress (size , key )
877
898
if self .footer .focus is None :
878
899
stream_id = self .model .stream_id
879
900
stream_dict = self .model .stream_dict
880
901
if stream_id is None :
881
- self .footer .stream_box_view (0 )
882
- else :
883
- self .footer .stream_box_view (caption = stream_dict [stream_id ]["name" ])
902
+ # Set to a default or the intended stream
903
+ default_stream_id = next (iter (stream_dict .keys ()), 0 )
904
+ self .model .stream_id = default_stream_id
905
+ stream_id = default_stream_id
906
+ try :
907
+ stream_data = stream_dict .get (stream_id , {})
908
+ if not stream_data :
909
+ raise KeyError (f"No data for stream_id { stream_id } " )
910
+ caption = stream_data .get ("name" , "Unknown Stream" )
911
+ self .footer .stream_box_view (stream_id , caption = caption )
912
+ except KeyError :
913
+ self .footer .stream_box_view (0 , caption = "Unknown Stream" ) # Fallback
884
914
self .set_focus ("footer" )
885
915
self .footer .focus_position = 0
886
916
return None
887
-
888
917
elif is_command_key ("STREAM_NARROW" , key ):
889
918
if (
890
919
self .current_view != self .message_view
0 commit comments