@@ -107,6 +107,10 @@ def switch_to_workspace(self, workspace_number):
107107 loop .create_task (self .animate_loading ())
108108 loop .create_task (self .component_did_mount ())
109109
110+ @property
111+ def is_chatbox_rendered (self ):
112+ return not self ._loading and self .chatbox and type (self .chatbox ) is ChatBox
113+
110114 @property
111115 def sidebar (self ):
112116 return self .columns .contents [0 ][0 ].original_widget
@@ -590,13 +594,13 @@ def scroll_messages(self, *args):
590594
591595 @asyncio .coroutine
592596 def mark_read_slack (self , index ):
593- if not self .chatbox . body or not self . chatbox . body . body :
597+ if not self .is_chatbox_rendered :
594598 return
595599
596600 if index is None or index == - 1 :
597601 index = len (self .chatbox .body .body ) - 1
598602
599- if self . chatbox . body . body and self . chatbox . body . body and len (self .chatbox .body .body ) > index :
603+ if len (self .chatbox .body .body ) > index :
600604 message = self .chatbox .body .body [index ]
601605
602606 # Only apply for message
@@ -628,11 +632,12 @@ def _go_to_channel(self, channel_id):
628632 messages = self .render_messages (self .store .state .messages , channel_id = channel_id )
629633
630634 header = self .render_chatbox_header ()
631- self .chatbox .body .body [:] = messages
632- self .chatbox .header = header
633- self .chatbox .message_box .is_read_only = self .store .state .channel .get ('is_read_only' , False )
634- self .sidebar .select_channel (channel_id )
635- self .urwid_loop .set_alarm_in (0 , self .scroll_messages )
635+ if self .is_chatbox_rendered :
636+ self .chatbox .body .body [:] = messages
637+ self .chatbox .header = header
638+ self .chatbox .message_box .is_read_only = self .store .state .channel .get ('is_read_only' , False )
639+ self .sidebar .select_channel (channel_id )
640+ self .urwid_loop .set_alarm_in (0 , self .scroll_messages )
636641
637642 if len (self .store .state .messages ) == 0 :
638643 self .go_to_sidebar ()
@@ -706,7 +711,7 @@ def start_real_time(self):
706711
707712 def stop_typing (* args ):
708713 # Prevent error while switching workspace
709- if self .chatbox is not None :
714+ if self .is_chatbox_rendered :
710715 self .chatbox .message_box .typing = None
711716
712717 alarm = None
@@ -737,6 +742,9 @@ def stop_typing(*args):
737742 )
738743
739744 if event .get ('channel' ) == self .store .state .channel ['id' ]:
745+ if not self .is_chatbox_rendered :
746+ return
747+
740748 if event .get ('subtype' ) == 'message_deleted' :
741749 for widget in self .chatbox .body .body :
742750 if hasattr (widget , 'ts' ) and getattr (widget , 'ts' ) == event ['deleted_ts' ]:
@@ -753,6 +761,9 @@ def stop_typing(*args):
753761 else :
754762 pass
755763 elif event ['type' ] == 'user_typing' :
764+ if not self .is_chatbox_rendered :
765+ return
766+
756767 if event .get ('channel' ) == self .store .state .channel ['id' ]:
757768 user = self .store .find_user_by_id (event ['user' ])
758769 name = user .get ('display_name' ) or user .get ('real_name' ) or user ['name' ]
@@ -767,6 +778,9 @@ def stop_typing(*args):
767778 self .store .is_snoozed = event ['dnd_status' ]['snooze_enabled' ]
768779 self .sidebar .profile .set_snooze (self .store .is_snoozed )
769780 elif event .get ('ok' , False ):
781+ if not self .is_chatbox_rendered :
782+ return
783+
770784 # Message was sent, Slack confirmed it.
771785 self .chatbox .body .body .extend (self .render_messages ([{
772786 'text' : event ['text' ],
@@ -853,11 +867,18 @@ def unhandled_input(self, key):
853867 elif key == keymap ['open_quick_switcher' ]:
854868 return self .open_quick_switcher ()
855869 elif key in ('1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' ) and len (self .workspaces ) >= int (key ):
856- if self .workspaces_line is not None :
857- self .workspaces_line .select (int (key ))
858- # Stop rtm to switch workspace
859- self .real_time_task .cancel ()
860- return self .switch_to_workspace (int (key ))
870+ # Loading or only 1 workspace
871+ if self ._loading or self .workspaces_line is None :
872+ return
873+
874+ # Workspace is selected
875+ if selected_workspace - 1 == self .workspaces_line .selected :
876+ return
877+
878+ self .workspaces_line .select (selected_workspace )
879+ # Stop rtm to switch workspace
880+ self .real_time_task .cancel ()
881+ return self .switch_to_workspace (selected_workspace )
861882 elif key == keymap ['set_snooze' ]:
862883 return self .open_set_snooze ()
863884
0 commit comments