From 4de39f91d9d8942816b8967a115010c466b8f252 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Fri, 3 Feb 2023 01:27:31 +0100 Subject: Add messages received over rtm to channels --- slack/slack_conversation.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'slack/slack_conversation.py') diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index b65ad98..e72e293 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -1,6 +1,7 @@ from __future__ import annotations import time +from collections import OrderedDict from contextlib import contextmanager from typing import TYPE_CHECKING, List, Optional @@ -38,6 +39,7 @@ class SlackConversation: self.workspace = workspace self._info = info self._members: Optional[List[str]] = None + self._messages: OrderedDict[str, SlackMessage] = OrderedDict() # TODO: buffer_pointer may be accessed by buffer_switch before it's initialized self.buffer_pointer: str = "" self.is_loading = False @@ -150,6 +152,8 @@ class SlackConversation: start = time.time() messages = [SlackMessage(self, message) for message in history["messages"]] + for message in messages: + self._messages[message.ts] = message sender_user_ids = [m.sender_user_id for m in messages if m.sender_user_id] await self.workspace.users.initialize_items(sender_user_ids) @@ -165,6 +169,11 @@ class SlackConversation: self.history_filled = True self.history_pending = False + async def add_message(self, message: SlackMessage): + self._messages[message.ts] = message + message_rendered = await message.render_message() + weechat.prnt(self.buffer_pointer, message_rendered) + def _buffer_input_cb(self, data: str, buffer: str, input_data: str) -> int: weechat.prnt(buffer, "Text: %s" % input_data) return weechat.WEECHAT_RC_OK -- cgit