From ae1461cedc245a2c85fa7afb84b53e310f945eb9 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 10 Mar 2024 13:28:41 +0100 Subject: Fix parent message not being included in SlackThread.messages --- slack/slack_thread.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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]: -- cgit