Skip to content

Commit

Permalink
Mark messages as read after someone talked about it in a relay group
Browse files Browse the repository at this point in the history
fix #15
  • Loading branch information
missytake committed Aug 20, 2024
1 parent 9c40e5f commit 7c403fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/team_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def ac_incoming_message(self, message: deltachat.Message):
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:
Expand Down Expand Up @@ -277,3 +278,12 @@ def offboard(self, ex_admin: deltachat.Contact) -> None:
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()
2 changes: 2 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7c403fa

Please sign in to comment.