diff options
-rw-r--r-- | slack/slack_user.py | 4 | ||||
-rw-r--r-- | slack/slack_workspace.py | 23 | ||||
-rw-r--r-- | typings/slack_rtm/slack_rtm_message.pyi | 10 |
3 files changed, 31 insertions, 6 deletions
diff --git a/slack/slack_user.py b/slack/slack_user.py index 3eb00aa..b73d5d5 100644 --- a/slack/slack_user.py +++ b/slack/slack_user.py @@ -135,6 +135,10 @@ class SlackUser: self._rendered_message = None self._parsed_message = None + for conversation in self.workspace.open_conversations.values(): + if conversation.im_user_id == self.id: + conversation.update_buffer_props() + class SlackBot: def __init__(self, workspace: SlackWorkspace, info: SlackBotInfo): diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index a1289a0..17b62a4 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -308,7 +308,7 @@ class SlackWorkspace: self.muted_channels = set(user_boot["prefs"]["muted_channels"].split(",")) await self._connect_ws( - f"wss://wss-primary.slack.com/?token={self.config.api_token.value}&batch_presence_aware=1" + f"wss://wss-primary.slack.com/?token={self.config.api_token.value}&slack_client=desktop&batch_presence_aware=1" ) conversation_counts = ( @@ -480,11 +480,22 @@ class SlackWorkspace: channel.update_buffer_props() return elif data["type"] == "user_status_changed": - user = await self.users[data["user"]["id"]] - user.update_info_json(data["user"]) - for conversation in self.open_conversations.values(): - if conversation.im_user_id == user.id: - conversation.update_buffer_props() + user_id = data["user"]["id"] + if user_id in self.users: + user = await self.users[user_id] + user.update_info_json(data["user"]) + return + elif data["type"] == "user_invalidated": + user_id = data["user"]["id"] + if user_id in self.users: + has_dm_conversation = any( + conversation.im_user_id == user_id + for conversation in self.open_conversations.values() + ) + if has_dm_conversation: + user = await self.users[user_id] + user_info = await self.api.fetch_user_info(user_id) + user.update_info_json(user_info["user"]) return elif data["type"] == "channel_joined" or data["type"] == "group_joined": channel_id = data["channel"]["id"] diff --git a/typings/slack_rtm/slack_rtm_message.pyi b/typings/slack_rtm/slack_rtm_message.pyi index 5f78cbb..6310352 100644 --- a/typings/slack_rtm/slack_rtm_message.pyi +++ b/typings/slack_rtm/slack_rtm_message.pyi @@ -303,6 +303,15 @@ class SlackUserStatusChanged(TypedDict): cache_ts: str event_ts: str +class SlackUserInvalidatedUser(TypedDict): + id: str + +@final +class SlackUserInvalidated(TypedDict): + type: Literal["user_invalidated"] + user: SlackUserInvalidatedUser + event_ts: str + SlackMessageRtm = ( SlackMessageStandardRtm | SlackMessageMeRtm @@ -346,4 +355,5 @@ SlackRtmMessage = ( | SlackUserTyping | SlackPrefChange | SlackUserStatusChanged + | SlackUserInvalidated ) |