@@ -106,6 +106,10 @@ def switch_to_workspace(self, workspace_number):
106106 loop .create_task (self .animate_loading ())
107107 loop .create_task (self .component_did_mount ())
108108
109+ @property
110+ def is_chatbox_rendered (self ):
111+ return not self ._loading and self .chatbox and type (self .chatbox ) is ChatBox
112+
109113 @property
110114 def sidebar (self ):
111115 return self .columns .contents [0 ][0 ].original_widget
@@ -578,13 +582,13 @@ def scroll_messages(self, *args):
578582
579583 @asyncio .coroutine
580584 def mark_read_slack (self , index ):
581- if not self .chatbox . body or not self . chatbox . body . body :
585+ if not self .is_chatbox_rendered :
582586 return
583587
584588 if index is None or index == - 1 :
585589 index = len (self .chatbox .body .body ) - 1
586590
587- if self . chatbox . body . body and self . chatbox . body . body and len (self .chatbox .body .body ) > index :
591+ if len (self .chatbox .body .body ) > index :
588592 message = self .chatbox .body .body [index ]
589593
590594 # Only apply for message
@@ -616,11 +620,12 @@ def _go_to_channel(self, channel_id):
616620 messages = self .render_messages (self .store .state .messages , channel_id = channel_id )
617621
618622 header = self .render_chatbox_header ()
619- self .chatbox .body .body [:] = messages
620- self .chatbox .header = header
621- self .chatbox .message_box .is_read_only = self .store .state .channel .get ('is_read_only' , False )
622- self .sidebar .select_channel (channel_id )
623- self .urwid_loop .set_alarm_in (0 , self .scroll_messages )
623+ if self .is_chatbox_rendered :
624+ self .chatbox .body .body [:] = messages
625+ self .chatbox .header = header
626+ self .chatbox .message_box .is_read_only = self .store .state .channel .get ('is_read_only' , False )
627+ self .sidebar .select_channel (channel_id )
628+ self .urwid_loop .set_alarm_in (0 , self .scroll_messages )
624629
625630 if len (self .store .state .messages ) == 0 :
626631 self .go_to_sidebar ()
@@ -694,7 +699,7 @@ def start_real_time(self):
694699
695700 def stop_typing (* args ):
696701 # Prevent error while switching workspace
697- if self .chatbox is not None :
702+ if self .is_chatbox_rendered :
698703 self .chatbox .message_box .typing = None
699704
700705 alarm = None
@@ -725,6 +730,9 @@ def stop_typing(*args):
725730 )
726731
727732 if event .get ('channel' ) == self .store .state .channel ['id' ]:
733+ if not self .is_chatbox_rendered :
734+ return
735+
728736 if event .get ('subtype' ) == 'message_deleted' :
729737 for widget in self .chatbox .body .body :
730738 if hasattr (widget , 'ts' ) and getattr (widget , 'ts' ) == event ['deleted_ts' ]:
@@ -741,6 +749,9 @@ def stop_typing(*args):
741749 else :
742750 pass
743751 elif event ['type' ] == 'user_typing' :
752+ if not self .is_chatbox_rendered :
753+ return
754+
744755 if event .get ('channel' ) == self .store .state .channel ['id' ]:
745756 user = self .store .find_user_by_id (event ['user' ])
746757 name = user .get ('display_name' ) or user .get ('real_name' ) or user ['name' ]
@@ -755,6 +766,9 @@ def stop_typing(*args):
755766 self .store .is_snoozed = event ['dnd_status' ]['snooze_enabled' ]
756767 self .sidebar .profile .set_snooze (self .store .is_snoozed )
757768 elif event .get ('ok' , False ):
769+ if not self .is_chatbox_rendered :
770+ return
771+
758772 # Message was sent, Slack confirmed it.
759773 self .chatbox .body .body .extend (self .render_messages ([{
760774 'text' : event ['text' ],
@@ -841,11 +855,18 @@ def unhandled_input(self, key):
841855 elif key == keymap ['open_quick_switcher' ]:
842856 return self .open_quick_switcher ()
843857 elif key in ('1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' ) and len (self .workspaces ) >= int (key ):
844- if self .workspaces_line is not None :
845- self .workspaces_line .select (int (key ))
846- # Stop rtm to switch workspace
847- self .real_time_task .cancel ()
848- return self .switch_to_workspace (int (key ))
858+ # Loading or only 1 workspace
859+ if self ._loading or self .workspaces_line is None :
860+ return
861+
862+ # Workspace is selected
863+ if selected_workspace - 1 == self .workspaces_line .selected :
864+ return
865+
866+ self .workspaces_line .select (selected_workspace )
867+ # Stop rtm to switch workspace
868+ self .real_time_task .cancel ()
869+ return self .switch_to_workspace (selected_workspace )
849870 elif key == keymap ['set_snooze' ]:
850871 return self .open_set_snooze ()
851872
0 commit comments