@@ -136,34 +136,71 @@ def mount_sidebar(self, executor):
136136 yield from asyncio .gather (
137137 loop .run_in_executor (executor , self .store .load_auth ),
138138 loop .run_in_executor (executor , self .store .load_channels ),
139+ loop .run_in_executor (executor , self .store .load_stars ),
139140 loop .run_in_executor (executor , self .store .load_groups ),
140141 loop .run_in_executor (executor , self .store .load_users ),
141142 loop .run_in_executor (executor , self .store .load_user_dnd ),
142143 )
143144 profile = Profile (name = self .store .state .auth ['user' ], is_snoozed = self .store .state .is_snoozed )
144- channels = [
145- Channel (
145+
146+ channels = []
147+ dms = []
148+ stars = []
149+ star_user_tmp = [] # To contain user, channel should be on top of list
150+ stars_user_id = [] # To ignore item in DMs list
151+ stars_channel_id = [] # To ignore item in channels list
152+ max_users_sidebar = self .store .config ['sidebar' ]['max_users' ]
153+
154+ # Prepare list of Star users and channels
155+ for dm in self .store .state .stars :
156+ # Group chat is not supported, prefer to https://github.com/haskellcamargo/sclack/issues/67
157+ if self .store .is_dm (dm ['channel' ]):
158+ detail = self .store .get_channel_info (dm ['channel' ])
159+ user = self .store .find_user_by_id (detail ['user' ])
160+ if user :
161+ stars_user_id .append (user ['id' ])
162+ star_user_tmp .append (Dm (
163+ dm ['channel' ],
164+ name = self .store .get_user_display_name (user ),
165+ user = dm ['channel' ],
166+ you = False
167+ ))
168+ elif self .store .is_channel (dm ['channel' ]):
169+ channel = self .store .get_channel_info (dm ['channel' ])
170+ if channel :
171+ stars_channel_id .append (channel ['id' ])
172+ stars .append (Channel (
173+ id = channel ['id' ],
174+ name = channel ['name' ],
175+ is_private = channel ['is_private' ]
176+ ))
177+ stars .extend (star_user_tmp )
178+
179+ # Prepare list of Channels
180+ for channel in self .store .state .channels :
181+ if channel ['id' ] in stars_channel_id :
182+ continue
183+ channels .append (Channel (
146184 id = channel ['id' ],
147185 name = channel ['name' ],
148186 is_private = channel ['is_private' ]
149- )
150- for channel in self .store .state .channels
151- ]
152- dms = []
153- max_users_sidebar = self .store .config ['sidebar' ]['max_users' ]
154- dm_users = self .store .state .dms [:max_users_sidebar ]
187+ ))
155188
189+ # Prepare list of DM
190+ dm_users = self .store .state .dms [:max_users_sidebar ]
156191 for dm in dm_users :
192+ if dm ['user' ] in stars_user_id :
193+ continue
157194 user = self .store .find_user_by_id (dm ['user' ])
158195 if user :
159196 dms .append (Dm (
160197 dm ['id' ],
161- name = user . get ( 'display_name' ) or user . get ( 'real_name' ) or user [ 'name' ] ,
198+ name = self . store . get_user_display_name ( user ) ,
162199 user = dm ['user' ],
163200 you = user ['id' ] == self .store .state .auth ['user_id' ]
164201 ))
165202
166- self .sidebar = SideBar (profile , channels , dms , title = self .store .state .auth ['team' ])
203+ self .sidebar = SideBar (profile , channels , dms , stars = stars , title = self .store .state .auth ['team' ])
167204 urwid .connect_signal (self .sidebar , 'go_to_channel' , self .go_to_channel )
168205 loop .create_task (self .get_channels_info (executor , channels ))
169206 loop .create_task (self .get_presences (executor , dms ))
@@ -716,8 +753,10 @@ def go_to_sidebar(self):
716753 if len (self .columns .contents ) > 2 :
717754 self .columns .contents .pop ()
718755 self .columns .focus_position = 0
756+
719757 if self .store .state .editing_widget :
720758 self .leave_edit_mode ()
759+
721760 if self .quick_switcher :
722761 urwid .disconnect_signal (self .quick_switcher , 'go_to_channel' , self .go_to_channel )
723762 self .urwid_loop .widget = self ._body
@@ -743,6 +782,11 @@ def go_to_last_message(self):
743782 self .chatbox .body .go_to_last_message ()
744783
745784 def unhandled_input (self , key ):
785+ """
786+ Handle shortcut key press
787+ :param key:
788+ :return:
789+ """
746790 keymap = self .store .config ['keymap' ]
747791
748792 if key == keymap ['go_to_chatbox' ] or key == keymap ['cursor_right' ] and self .message_box :
0 commit comments