示例#1
0
文件: app.py 项目: tuandm/sclack
    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_groups),
            loop.run_in_executor(executor, self.store.load_users))
        profile = Profile(name=self.store.state.auth['user'])
        channels = [
            Channel(id=channel['id'],
                    name=channel['name'],
                    is_private=channel['is_private'])
            for channel in self.store.state.channels
        ]
        dms = []
        max_users_sidebar = self.store.config['sidebar']['max_users']
        dm_users = self.store.state.dms[:max_users_sidebar]

        for dm in dm_users:
            user = self.store.find_user_by_id(dm['user'])
            if user:
                dms.append(
                    Dm(dm['id'],
                       name=user.get('display_name') or user.get('real_name')
                       or user['name'],
                       user=dm['user'],
                       you=user['id'] == self.store.state.auth['user_id']))

        self.sidebar = SideBar(profile,
                               channels,
                               dms,
                               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, channels))
        loop.create_task(self.get_presences(executor, dms))
示例#2
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()))