diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2024-03-10 13:28:41 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-03-29 00:00:15 +0100 |
commit | ae1461cedc245a2c85fa7afb84b53e310f945eb9 (patch) | |
tree | 040e6d2e18616d65d31054b2aeda4e8f33797922 /slack/slack_thread.py | |
parent | b8acf7d21c67f7dc95aaeec7d9855bdc9b13ed91 (diff) | |
download | wee-slack-ae1461cedc245a2c85fa7afb84b53e310f945eb9.tar.gz |
Fix parent message not being included in SlackThread.messages
Diffstat (limited to 'slack/slack_thread.py')
-rw-r--r-- | slack/slack_thread.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/slack/slack_thread.py b/slack/slack_thread.py index 47a00c2..fe86b23 100644 --- a/slack/slack_thread.py +++ b/slack/slack_thread.py @@ -15,10 +15,29 @@ if TYPE_CHECKING: from slack.slack_workspace import SlackWorkspace +class SlackThreadMessages(Mapping[SlackTs, SlackMessage]): + def __init__(self, parent: SlackMessage): + super().__init__() + self._parent = parent + + def __getitem__(self, key: SlackTs) -> SlackMessage: + if key == self._parent.ts: + return self._parent + return self._parent.replies[key] + + def __iter__(self) -> Generator[SlackTs, None, None]: + yield self._parent.ts + yield from self._parent.replies + + def __len__(self) -> int: + return 1 + len(self._parent.replies) + + class SlackThread(SlackBuffer): def __init__(self, parent: SlackMessage) -> None: super().__init__() self.parent = parent + self._messages = SlackThreadMessages(parent) self._reply_nicks: Set[Nick] = set() @property @@ -41,7 +60,7 @@ class SlackThread(SlackBuffer): @property def messages(self) -> Mapping[SlackTs, SlackMessage]: - return self.parent.replies + return self._messages @property def last_read(self) -> Optional[SlackTs]: |