From b4ba7da53bcc79e3b20131abeefd8260686a03e2 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Tue, 15 Aug 2023 19:53:21 +0200 Subject: Fix regression with messages not being shown as deleted The commit 74da303 introduced a regression with messages not being shown as deleted anymore because deleting only changed the text field, and that's not being used anymore with that commit. Fixes #897 --- _pytest/test_process_message.py | 4 +++- wee_slack.py | 16 +++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/_pytest/test_process_message.py b/_pytest/test_process_message.py index 5017c10..d4e6a6d 100644 --- a/_pytest/test_process_message.py +++ b/_pytest/test_process_message.py @@ -74,6 +74,8 @@ def test_process_message(realish_eventrouter, team, user_alice): assert list(deleted_message_channel.messages.keys()) == [deleted_message_ts] deleted_str = "<[color red]>(deleted)<[color reset]>" assert ( - deleted_message_channel.messages[deleted_message_ts].message_json["text"] + deleted_message_channel.messages[deleted_message_ts].message_json[ + "_rendered_text" + ] == deleted_str ) diff --git a/wee_slack.py b/wee_slack.py index f65849c..7c6c0e7 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2101,15 +2101,13 @@ class SlackChannelCommon(object): message = self.message_from_index(index, message_filter, reverse) return message - def change_message(self, ts, message_json=None, text=None): + def change_message(self, ts, message_json=None): ts = SlackTS(ts) m = self.messages.get(ts) if not m: return if message_json: m.message_json.update(message_json) - if text: - m.change_text(text) if ( not isinstance(m, SlackThreadMessage) @@ -3394,6 +3392,11 @@ class SlackMessage(object): if not force and self.message_json.get("_rendered_text"): return self.message_json["_rendered_text"] + if self.message_json.get("deleted"): + text = colorize_string(config.color_deleted, "(deleted)") + self.message_json["_rendered_text"] = text + return text + blocks = self.message_json.get("blocks", []) blocks_rendered = "\n".join(unfurl_blocks(blocks)) if blocks_rendered: @@ -3445,10 +3448,6 @@ class SlackMessage(object): self.message_json["_rendered_text"] = text return text - def change_text(self, new_text): - self.message_json["text"] = new_text - dbg(self.message_json) - def get_sender(self, plain): user = self.team.users.get(self.user_identifier) if user: @@ -4302,8 +4301,7 @@ def subprocess_message_changed( def subprocess_message_deleted( message_json, eventrouter, team, channel, history_message ): - message = colorize_string(config.color_deleted, "(deleted)") - channel.change_message(message_json["deleted_ts"], text=message) + channel.change_message(message_json["deleted_ts"], {"deleted": True}) def process_reply(message_json, eventrouter, team, channel, metadata): -- cgit