diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-21 22:54:35 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 9e99c1d54eec2ab49a1a6a749bec1def8d182927 (patch) | |
tree | dd770a44568a0dff2ee7b5b005ff6b2fe3baa04a /slack/slack_thread.py | |
parent | a48c2ae60ea785a9c710833ed93f935ea5fdaff1 (diff) | |
download | wee-slack-9e99c1d54eec2ab49a1a6a749bec1def8d182927.tar.gz |
Support completing @nicks in current buffer
Adds all known nicks in the current buffer with an @ prefix to the
nicks completion.
Disables the API search based nick completion for now until it's working
properly. It currently doesn't have any context of which
conversation/thread you are in, so you often get other nicks than the
one you want to complete first. Additionally, it doesn't work with OAuth
tokens.
Diffstat (limited to 'slack/slack_thread.py')
-rw-r--r-- | slack/slack_thread.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/slack/slack_thread.py b/slack/slack_thread.py index 8033ff1..3a96789 100644 --- a/slack/slack_thread.py +++ b/slack/slack_thread.py @@ -1,10 +1,12 @@ from __future__ import annotations from itertools import chain -from typing import TYPE_CHECKING, Dict, Mapping, Optional, Tuple +from typing import TYPE_CHECKING, Dict, Generator, Mapping, Optional, Set, Tuple +from slack.log import print_exception_once from slack.slack_buffer import SlackBuffer from slack.slack_message import SlackMessage, SlackTs +from slack.slack_user import SlackUser from slack.task import gather if TYPE_CHECKING: @@ -18,6 +20,7 @@ class SlackThread(SlackBuffer): def __init__(self, parent: SlackMessage) -> None: super().__init__() self.parent = parent + self._reply_users: Set[SlackUser] = set() @property def workspace(self) -> SlackWorkspace: @@ -32,6 +35,11 @@ class SlackThread(SlackBuffer): return "thread" @property + def members(self) -> Generator[SlackUser, None, None]: + for user in self._reply_users: + yield user + + @property def messages(self) -> Mapping[SlackTs, SlackMessage]: return self.parent.replies @@ -107,6 +115,16 @@ class SlackThread(SlackBuffer): self.history_needs_refresh = False self.history_pending = False + async def print_message(self, message: SlackMessage): + await super().print_message(message) + sender_user_id = message.sender_user_id + if sender_user_id is not None: + try: + sender_user = await self.workspace.users[sender_user_id] + self._reply_users.add(sender_user) + except Exception as e: + print_exception_once(e) + async def mark_read(self): # subscriptions.thread.mark is only available for session tokens if self.workspace.token_type != "session": |