diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-09-28 01:14:52 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | afb77699997cdba0d3b88acf89cfcd29b34b9e6f (patch) | |
tree | 0aaa7d3cea478cfdc6b26e1d561a928483fc677d /slack/slack_workspace.py | |
parent | 11d10577ea2f15d9940b37a1b36e11ee2a547bfa (diff) | |
download | wee-slack-afb77699997cdba0d3b88acf89cfcd29b34b9e6f.tar.gz |
Open conversations in sorted order by name
Diffstat (limited to 'slack/slack_workspace.py')
-rw-r--r-- | slack/slack_workspace.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 4ad5d73..dcf0279 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -47,6 +47,7 @@ if TYPE_CHECKING: from slack_api.slack_bots_info import SlackBotInfo from slack_api.slack_conversations_info import SlackConversationsInfo from slack_api.slack_usergroups_info import SlackUsergroupInfo + from slack_api.slack_users_conversations import SlackUsersConversations from slack_api.slack_users_info import SlackUserInfo from slack_rtm.slack_rtm_message import SlackRtmMessage else: @@ -242,12 +243,25 @@ class SlackWorkspace: ) channels = users_conversations_response["channels"] self.conversations.initialize_items(channel["id"] for channel in channels) - for channel in channels: - conversation = await self.conversations[channel["id"]] - run_async(conversation.open_if_open()) + + conversations_if_should_open = await gather( + *(self._conversation_if_should_open(channel) for channel in channels) + ) + conversations_to_open = [ + c for c in conversations_if_should_open if c is not None + ] + + for _, conversation in sorted(conversations_to_open): + await conversation.open_buffer() self.is_connected = True + async def _conversation_if_should_open(self, info: SlackUsersConversations): + conversation = await self.conversations[info["id"]] + if conversation.should_open(): + sort_key = await conversation.sort_key() + return sort_key, conversation + async def _connect_ws(self, url: str): proxy = Proxy() # TODO: Handle errors |