@@ -140,34 +140,71 @@ def mount_sidebar(self, executor):
140140 yield from asyncio .gather (
141141 loop .run_in_executor (executor , self .store .load_auth ),
142142 loop .run_in_executor (executor , self .store .load_channels ),
143+ loop .run_in_executor (executor , self .store .load_stars ),
143144 loop .run_in_executor (executor , self .store .load_groups ),
144145 loop .run_in_executor (executor , self .store .load_users ),
145146 loop .run_in_executor (executor , self .store .load_user_dnd ),
146147 )
147148 profile = Profile (name = self .store .state .auth ['user' ], is_snoozed = self .store .state .is_snoozed )
148- channels = [
149- Channel (
149+
150+ channels = []
151+ dms = []
152+ stars = []
153+ star_user_tmp = [] # To contain user, channel should be on top of list
154+ stars_user_id = [] # To ignore item in DMs list
155+ stars_channel_id = [] # To ignore item in channels list
156+ max_users_sidebar = self .store .config ['sidebar' ]['max_users' ]
157+
158+ # Prepare list of Star users and channels
159+ for dm in self .store .state .stars :
160+ # Group chat is not supported, prefer to https://github.com/haskellcamargo/sclack/issues/67
161+ if self .store .is_dm (dm ['channel' ]):
162+ detail = self .store .get_channel_info (dm ['channel' ])
163+ user = self .store .find_user_by_id (detail ['user' ])
164+ if user :
165+ stars_user_id .append (user ['id' ])
166+ star_user_tmp .append (Dm (
167+ dm ['channel' ],
168+ name = self .store .get_user_display_name (user ),
169+ user = dm ['channel' ],
170+ you = False
171+ ))
172+ elif self .store .is_channel (dm ['channel' ]):
173+ channel = self .store .get_channel_info (dm ['channel' ])
174+ if channel :
175+ stars_channel_id .append (channel ['id' ])
176+ stars .append (Channel (
177+ id = channel ['id' ],
178+ name = channel ['name' ],
179+ is_private = channel ['is_private' ]
180+ ))
181+ stars .extend (star_user_tmp )
182+
183+ # Prepare list of Channels
184+ for channel in self .store .state .channels :
185+ if channel ['id' ] in stars_channel_id :
186+ continue
187+ channels .append (Channel (
150188 id = channel ['id' ],
151189 name = channel ['name' ],
152190 is_private = channel ['is_private' ]
153- )
154- for channel in self .store .state .channels
155- ]
156- dms = []
157- max_users_sidebar = self .store .config ['sidebar' ]['max_users' ]
158- dm_users = self .store .state .dms [:max_users_sidebar ]
191+ ))
159192
193+ # Prepare list of DM
194+ dm_users = self .store .state .dms [:max_users_sidebar ]
160195 for dm in dm_users :
196+ if dm ['user' ] in stars_user_id :
197+ continue
161198 user = self .store .find_user_by_id (dm ['user' ])
162199 if user :
163200 dms .append (Dm (
164201 dm ['id' ],
165- name = user . get ( 'display_name' ) or user . get ( 'real_name' ) or user [ 'name' ] ,
202+ name = self . store . get_user_display_name ( user ) ,
166203 user = dm ['user' ],
167204 you = user ['id' ] == self .store .state .auth ['user_id' ]
168205 ))
169206
170- self .sidebar = SideBar (profile , channels , dms , title = self .store .state .auth ['team' ])
207+ self .sidebar = SideBar (profile , channels , dms , stars = stars , title = self .store .state .auth ['team' ])
171208 urwid .connect_signal (self .sidebar , 'go_to_channel' , self .go_to_channel )
172209 loop .create_task (self .get_channels_info (executor , channels ))
173210 loop .create_task (self .get_presences (executor , dms ))
0 commit comments