Compare commits

...

3 commits
1.2.0 ... main

2 changed files with 55 additions and 7 deletions

View file

@ -156,6 +156,7 @@ class RelayPlugin:
else: else:
logging.debug("Ignoring message, just the crew chatting") logging.debug("Ignoring message, just the crew chatting")
else: else:
self.mark_last_messages_read(message.chat)
logging.debug("Ignoring message, just the crew chatting") logging.debug("Ignoring message, just the crew chatting")
else: else:
@ -268,6 +269,21 @@ class RelayPlugin:
return self.account.get_chat_by_id(mapping[1]) return self.account.get_chat_by_id(mapping[1])
return None return None
def offboard(self, ex_admin): def offboard(self, ex_admin: deltachat.Contact) -> None:
"""Remove a former crew member from all relay groups they are part of.
:param ex_admin: a contact which just got removed from the crew.
"""
for mapping in self.kvstore.get("relays"): for mapping in self.kvstore.get("relays"):
self.account.get_chat_by_id(mapping[1]).remove_contact(ex_admin) 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()

View file

@ -9,7 +9,7 @@ from deltachat.capi import lib as dclib
TIMEOUT = 40 TIMEOUT = 40
def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat: def get_user_crew(crewuser: deltachat.Account, id=11) -> deltachat.Chat:
"""Get the Team chat from the team member's point of view. """Get the Team chat from the team member's point of view.
:param crewuser: the account object of the team member :param crewuser: the account object of the team member
@ -17,7 +17,7 @@ def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat:
""" """
for chat in crewuser.get_chats(): for chat in crewuser.get_chats():
print(chat.id, chat.get_name()) print(chat.id, chat.get_name())
user_crew = crewuser.get_chat_by_id(11) user_crew = crewuser.get_chat_by_id(id)
assert user_crew.get_name().startswith("Team") assert user_crew.get_name().startswith("Team")
return user_crew return user_crew
@ -103,6 +103,7 @@ def test_relay_group_forwarding(relaycrew, outsider):
message_from_outsider = bot._evtracker.wait_next_incoming_message() message_from_outsider = bot._evtracker.wait_next_incoming_message()
bot_outside_chat = message_from_outsider.chat bot_outside_chat = message_from_outsider.chat
assert not bot.relayplugin.is_relay_group(bot_outside_chat) assert not bot.relayplugin.is_relay_group(bot_outside_chat)
assert message_from_outsider.is_in_fresh()
# get relay group # get relay group
user_forwarded_message_from_outsider = user._evtracker.wait_next_incoming_message() 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 user._dc_context, user_relay_group.id, user_direct_reply._dc_msg
) )
assert sent_id == user_direct_reply.id assert sent_id == user_direct_reply.id
assert message_from_outsider.is_in_seen()
# check that direct reply was forwarded to outsider # check that direct reply was forwarded to outsider
outsider_direct_reply = outsider._evtracker.wait_next_incoming_message() outsider_direct_reply = outsider._evtracker.wait_next_incoming_message()
@ -156,12 +158,42 @@ def test_relay_group_forwarding(relaycrew, outsider):
for msg in chat.get_messages(): for msg in chat.get_messages():
assert "This is the relay group for" not in msg.text assert "This is the relay group for" not in msg.text
@pytest.mark.timeout(TIMEOUT)
def test_offboarding(team_bot, relaycrew, outsider, team_user):
# outsider sends message, creates relay group
outsider_botcontact = outsider.create_contact(team_bot.get_config("addr"))
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
outsider_outside_chat.send_text("test 1:1 message to bot")
# get relay group
user_relay_group = team_user._evtracker.wait_next_incoming_message().chat
bot_relay_group = team_bot.get_chats()[-1]
# outsider gets added to crew
qr = relaycrew.get_join_qr()
outsider.qr_join_chat(qr)
outsider._evtracker.wait_securejoin_joiner_progress(1000)
# user kicks outsider from crew
user_crew = get_user_crew(team_user)
user_crew.remove_contact(team_user.create_contact(outsider))
team_bot._evtracker.wait_next_incoming_message()
# user leaves crew # user leaves crew
get_user_crew(user).remove_contact(user) user_crew.remove_contact(team_user)
# make sure they are also offboarded from relay group # make sure they are also offboarded from relay group
user._evtracker.wait_next_incoming_message() team_bot._evtracker.wait_next_incoming_message()
team_user._evtracker.wait_next_incoming_message()
team_user._evtracker.wait_next_incoming_message()
team_user._evtracker.wait_next_incoming_message()
for contact in bot_relay_group.get_contacts(): for contact in bot_relay_group.get_contacts():
assert user.get_config("addr") != contact.addr assert team_user.get_config("addr") != contact.addr
# make sure there is no message in relay group that outsider was kicked
for msg in user_relay_group.get_messages():
print(msg.text)
assert outsider.get_config("addr") + " removed by " not in msg.text
@pytest.mark.timeout(TIMEOUT) @pytest.mark.timeout(TIMEOUT)