feat: offboarding: remove ex-admins from relay groups

fix #6
This commit is contained in:
missytake 2024-08-20 12:24:12 +02:00
parent c1ccfcb546
commit db8ff5caec
2 changed files with 16 additions and 0 deletions

View file

@ -66,6 +66,11 @@ class RelayPlugin:
relay_group = self.get_relay_group(message.chat.id) relay_group = self.get_relay_group(message.chat.id)
relay_group.send_text(f"Sending Message failed:\n\n{error}") relay_group.send_text(f"Sending Message failed:\n\n{error}")
@account_hookimpl
def ac_member_removed(self, chat, contact, actor, message):
if chat == self.crew:
self.offboard(contact)
@account_hookimpl @account_hookimpl
def ac_incoming_message(self, message: deltachat.Message): def ac_incoming_message(self, message: deltachat.Message):
"""This method is called on every incoming message and decides what to do with it.""" """This method is called on every incoming message and decides what to do with it."""
@ -262,3 +267,7 @@ class RelayPlugin:
if mapping[0] == outside_id: if mapping[0] == outside_id:
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):
for mapping in self.kvstore.get("relays"):
self.account.get_chat_by_id(mapping[1]).remove_contact(ex_admin)

View file

@ -156,6 +156,13 @@ 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
# user leaves crew
get_user_crew(user).remove_contact(user)
# make sure they are also offboarded from relay group
user._evtracker.wait_next_incoming_message()
for contact in bot_relay_group.get_contacts():
assert user.get_config("addr") != contact.addr
@pytest.mark.timeout(TIMEOUT) @pytest.mark.timeout(TIMEOUT)
def test_default_outside_help(relaycrew, outsider): def test_default_outside_help(relaycrew, outsider):