diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-16 00:05:17 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 6eac18fb0080132e42285b0976205d2bb6d36848 (patch) | |
tree | 1dd2e776588727ba06bc462dbb9a3babca0bc027 /slack | |
parent | fdc62f23df3eb715e921fc6f32d3a39aaf210a4e (diff) | |
download | wee-slack-6eac18fb0080132e42285b0976205d2bb6d36848.tar.gz |
Check if closed IMs/MPIMs have unread messages on start
Sometimes an IM/MPIM can have unread messages even when is_open is
false, so we have to check the history if there are any unread messages.
Diffstat (limited to 'slack')
-rw-r--r-- | slack/slack_workspace.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index eb26b8e..bde1b4d 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -270,9 +270,21 @@ class SlackWorkspace: 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 + if not conversation.should_open(): + if conversation.type != "im" and conversation.type != "mpim": + return + + if conversation.last_read == SlackTs("0.0"): + history = await self.api.fetch_conversations_history(conversation) + else: + history = await self.api.fetch_conversations_history_after( + conversation, conversation.last_read + ) + if not history["messages"]: + return + + sort_key = await conversation.sort_key() + return sort_key, conversation async def _connect_ws(self, url: str): proxy = Proxy() |