From 3f09be5b25367cf41dce2e2fc244bed74d5a4329 Mon Sep 17 00:00:00 2001 From: missytake Date: Tue, 20 Aug 2024 13:42:49 +0200 Subject: [PATCH] Mark messages as read after someone talked about it in a relay group fix #15 --- src/team_bot/bot.py | 10 ++++++++++ tests/test_bot.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/team_bot/bot.py b/src/team_bot/bot.py index ae34960..cca6aa9 100644 --- a/src/team_bot/bot.py +++ b/src/team_bot/bot.py @@ -156,6 +156,7 @@ class RelayPlugin: else: logging.debug("Ignoring message, just the crew chatting") else: + self.mark_last_messages_read(message.chat) logging.debug("Ignoring message, just the crew chatting") else: @@ -277,3 +278,12 @@ class RelayPlugin: relay_group = self.account.get_chat_by_id(mapping[1]) if ex_admin in relay_group.get_contacts(): relay_group.remove_contact(ex_admin) + + def mark_last_messages_read(self, relay_group: deltachat.Chat) -> None: + """Mark the last incoming messages as read for a corresponding relay group. + + :param relay_group: the relay group in which the messages which should marked read were forwarded. + """ + outside_chat = self.get_outside_chat(relay_group.id) + for msg in outside_chat.get_messages(): + msg.mark_seen() diff --git a/tests/test_bot.py b/tests/test_bot.py index b185962..03d3704 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -103,6 +103,7 @@ def test_relay_group_forwarding(relaycrew, outsider): message_from_outsider = bot._evtracker.wait_next_incoming_message() bot_outside_chat = message_from_outsider.chat assert not bot.relayplugin.is_relay_group(bot_outside_chat) + assert message_from_outsider.is_in_fresh() # get relay group user_forwarded_message_from_outsider = user._evtracker.wait_next_incoming_message() @@ -132,6 +133,7 @@ def test_relay_group_forwarding(relaycrew, outsider): user._dc_context, user_relay_group.id, user_direct_reply._dc_msg ) assert sent_id == user_direct_reply.id + assert message_from_outsider.is_in_seen() # check that direct reply was forwarded to outsider outsider_direct_reply = outsider._evtracker.wait_next_incoming_message()