get relay group from pickle instead of guessing
This commit is contained in:
parent
18e5a67aa7
commit
f9186fe0c0
|
@ -234,21 +234,10 @@ class RelayPlugin:
|
|||
|
||||
def is_relay_group(self, chat: deltachat.Chat) -> bool:
|
||||
"""Check whether a chat is a relay group."""
|
||||
if not chat.get_name().startswith(
|
||||
"[%s] " % (self.account.get_config("addr").split("@")[0],)
|
||||
):
|
||||
return False # all relay groups' names begin with a [tag] with the localpart of the team-bot's address
|
||||
if (
|
||||
chat.get_messages()[0].get_sender_contact()
|
||||
!= self.account.get_self_contact()
|
||||
):
|
||||
return False # all relay groups were started by the team-bot
|
||||
if chat.is_protected():
|
||||
return False # relay groups don't need to be protected, so they are not
|
||||
for crew_member in self.crew.get_contacts():
|
||||
if crew_member not in chat.get_contacts():
|
||||
return False # all crew members have to be in any relay group
|
||||
return True
|
||||
for mapping in self.kvstore.get("relays"):
|
||||
if mapping[1] == chat.id:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_outside_chat(self, relay_group_id: int) -> deltachat.Chat:
|
||||
"""Get the corresponding outside chat for the ID of a relay group.
|
||||
|
|
|
@ -27,6 +27,12 @@ def test_not_relay_groups(relaycrew, outsider, lp):
|
|||
bot = relaycrew.bot
|
||||
user = relaycrew.user
|
||||
|
||||
def find_msg(ac, text):
|
||||
for chat in ac.get_chats():
|
||||
for msg in chat.get_messages():
|
||||
if msg.text == text:
|
||||
return msg
|
||||
|
||||
text = "outsider -> bot 1:1 chat"
|
||||
lp.sec(text)
|
||||
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
||||
|
@ -38,6 +44,14 @@ def test_not_relay_groups(relaycrew, outsider, lp):
|
|||
assert bot_message_from_outsider.text == text
|
||||
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
||||
|
||||
lp.sec("leave relay group with user")
|
||||
relayed_msg = find_msg(user, text)
|
||||
if not relayed_msg:
|
||||
relayed_msg = user._evtracker.wait_next_incoming_message()
|
||||
relayed_msg.chat.remove_contact(user.get_config("addr"))
|
||||
leave_msg = bot._evtracker.wait_next_incoming_message()
|
||||
assert bot.relayplugin.is_relay_group(leave_msg.chat)
|
||||
|
||||
text = "outsider -> bot group chat"
|
||||
lp.sec(text)
|
||||
outsider_bot_group = outsider.create_group_chat(
|
||||
|
@ -58,12 +72,6 @@ def test_not_relay_groups(relaycrew, outsider, lp):
|
|||
|
||||
# somehow the message doesn't trigger DC_EVENT_INCOMING_MSG
|
||||
# bot._evtracker.wait_next_incoming_message()
|
||||
def find_msg(ac, text):
|
||||
for chat in ac.get_chats():
|
||||
for msg in chat.get_messages():
|
||||
if msg.text == text:
|
||||
return msg
|
||||
|
||||
bot_message_from_user = find_msg(bot, text)
|
||||
while not bot_message_from_user:
|
||||
bot_message_from_user = find_msg(bot, text)
|
||||
|
|
Loading…
Reference in a new issue