Example #1
0
    def get_all_channels(self):
        """
        List Channels including Starred items
        :return:
        """
        channels_starred = list(
            filter(lambda starred: is_channel(starred.id), self.stars))
        channels_starred.extend(self.channels)

        return channels_starred
Example #2
0
 def get_targets_by_id(self, channel_id):
     """
     For different channel_id we get different data from: Groups, DMs, Channels
     :param channel_id:
     :return:
     """
     targets = None
     if is_channel(channel_id):
         targets = self.get_all_channels()
     elif is_dm(channel_id):
         targets = self.get_all_dms()
     elif is_group(channel_id):
         targets = self.get_all_groups()
     return targets
Example #3
0
    def mount_sidebar(self, executor):
        yield from asyncio.gather(
            loop.run_in_executor(executor, self.store.load_auth),
            loop.run_in_executor(executor, self.store.load_channels),
            loop.run_in_executor(executor, self.store.load_stars),
            loop.run_in_executor(executor, self.store.load_groups),
            loop.run_in_executor(executor, self.store.load_users),
            loop.run_in_executor(executor, self.store.load_user_dnd),
        )
        profile = Profile(name=self.store.state.auth['user'], is_snoozed=self.store.state.is_snoozed)

        channels = []
        dms = []
        stars = []
        star_user_tmp = []  # To contain user, channel should be on top of list
        stars_user_id = []  # To ignore item in DMs list
        stars_channel_id = []  # To ignore item in channels list
        max_users_sidebar = self.store.config['sidebar']['max_users']

        # Prepare list of Star users and channels
        for dm in self.store.state.stars:
            if is_dm(dm['channel']):
                detail = self.store.get_channel_info(dm['channel'])
                user = self.store.find_user_by_id(detail['user'])

                if user:
                    stars_user_id.append(user['id'])
                    star_user_tmp.append(Dm(
                        dm['channel'],
                        name=self.store.get_user_display_name(user),
                        user=user['id'],
                        you=False
                    ))
            elif is_channel(dm['channel']) or is_group(dm['channel']):
                channel = self.store.get_channel_info(dm['channel'])
                # Group chat (is_mpim) is not supported, prefer to https://github.com/haskellcamargo/sclack/issues/67
                if channel and not channel.get('is_archived', False) and not channel.get('is_mpim', False):
                    stars_channel_id.append(channel['id'])
                    stars.append(Channel(
                        id=channel['id'],
                        name=channel['name'],
                        is_private=channel.get('is_private', True)
                    ))
        stars.extend(star_user_tmp)

        # Prepare list of Channels
        for channel in self.store.state.channels:
            if channel['id'] in stars_channel_id:
                continue
            channels.append(Channel(
                id=channel['id'],
                name=channel['name'],
                is_private=channel['is_private']
            ))

        # Prepare list of DM
        dm_users = self.store.state.dms[:max_users_sidebar]
        for dm in dm_users:
            if dm['user'] in stars_user_id:
                continue
            user = self.store.find_user_by_id(dm['user'])
            if user:
                dms.append(Dm(
                    dm['id'],
                    name=self.store.get_user_display_name(user),
                    user=dm['user'],
                    you=user['id'] == self.store.state.auth['user_id']
                ))

        self.sidebar = SideBar(profile, channels, dms, stars=stars, title=self.store.state.auth['team'])
        urwid.connect_signal(self.sidebar, 'go_to_channel', self.go_to_channel)
        loop.create_task(self.get_channels_info(executor, self.sidebar.get_all_channels()))
        loop.create_task(self.get_presences(executor, self.sidebar.get_all_dms()))
        loop.create_task(self.get_dms_unread(executor, self.sidebar.get_all_dms()))