aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-16 00:05:17 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit6eac18fb0080132e42285b0976205d2bb6d36848 (patch)
tree1dd2e776588727ba06bc462dbb9a3babca0bc027 /slack
parentfdc62f23df3eb715e921fc6f32d3a39aaf210a4e (diff)
downloadwee-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.py18
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()