Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: offboarding: remove ex-admins from relay groups #14

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/team_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def ac_outgoing_message(self, message: deltachat.Message):
relay_group = self.get_relay_group(message.chat.id)
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
def ac_incoming_message(self, message: deltachat.Message):
"""This method is called on every incoming message and decides what to do with it."""
Expand Down Expand Up @@ -262,3 +267,7 @@ def get_relay_group(self, outside_id: int) -> deltachat.Chat:
if mapping[0] == outside_id:
return self.account.get_chat_by_id(mapping[1])
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)
7 changes: 7 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def test_relay_group_forwarding(relaycrew, outsider):
for msg in chat.get_messages():
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)
def test_default_outside_help(relaycrew, outsider):
Expand Down