Skip to content
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
16 changes: 12 additions & 4 deletions deltachat-rpc-client/src/deltachat_rpc_client/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,25 @@ def mark_noticed(self) -> None:
"""Mark all messages in this chat as noticed."""
self._rpc.marknoticed_chat(self.account.id, self.id)

def add_contact(self, *contact: Union[int, str, Contact]) -> None:
def add_contact(self, *contact: Union[int, str, Contact, "Account"]) -> None:
"""Add contacts to this group."""
from .account import Account

for cnt in contact:
if isinstance(cnt, str):
if isinstance(cnt, (str, Account)):
contact_id = self.account.create_contact(cnt).id
elif not isinstance(cnt, int):
contact_id = cnt.id
else:
contact_id = cnt
self._rpc.add_contact_to_chat(self.account.id, self.id, contact_id)

def remove_contact(self, *contact: Union[int, str, Contact]) -> None:
def remove_contact(self, *contact: Union[int, str, Contact, "Account"]) -> None:
"""Remove members from this group."""
from .account import Account

for cnt in contact:
if isinstance(cnt, str):
if isinstance(cnt, (str, Account)):
contact_id = self.account.create_contact(cnt).id
elif not isinstance(cnt, int):
contact_id = cnt.id
Expand All @@ -249,6 +253,10 @@ def get_contacts(self) -> list[Contact]:
contacts = self._rpc.get_chat_contacts(self.account.id, self.id)
return [Contact(self.account, contact_id) for contact_id in contacts]

def num_contacts(self) -> int:
"""Return number of contacts in this chat."""
return len(self.get_contacts())

def get_past_contacts(self) -> list[Contact]:
"""Get past contacts for this chat."""
past_contacts = self._rpc.get_past_chat_contacts(self.account.id, self.id)
Expand Down
44 changes: 44 additions & 0 deletions deltachat-rpc-client/tests/test_something.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,47 @@ def test_message_exists(acfactory):
ac1.remove()
assert not message1.exists()
assert not message2.exists()


def test_synchronize_member_list_on_group_rejoin(acfactory, log):
"""
Test that user recreates group member list when it joins the group again.
ac1 creates a group with two other accounts: ac2 and ac3
Then it removes ac2, removes ac3 and adds ac2 back.
ac2 did not see that ac3 is removed, so it should rebuild member list from scratch.
"""
log.section("setting up accounts, accepted with each other")
ac1, ac2, ac3 = accounts = acfactory.get_online_accounts(3)

log.section("ac1: creating group chat with 2 other members")
chat = ac1.create_group("title1")
chat.add_contact(ac2)
chat.add_contact(ac3)

log.section("ac1: send message to new group chat")
msg = chat.send_text("hello")
assert chat.num_contacts() == 3

log.section("checking that the chat arrived correctly")
for ac in accounts[1:]:
msg = ac.wait_for_incoming_msg().get_snapshot()
assert msg.text == "hello"
assert msg.chat.num_contacts() == 3
msg.chat.accept()

log.section("ac1: removing ac2")
chat.remove_contact(ac2)

log.section("ac2: wait for a message about removal from the chat")
ac2.wait_for_incoming_msg()
log.section("ac1: removing ac3")
chat.remove_contact(ac3)

log.section("ac1: adding ac2 back")
chat.add_contact(ac2)

log.section("ac2: check that ac3 is removed")
msg = ac2.wait_for_incoming_msg()

assert chat.num_contacts() == 2
assert msg.get_snapshot().chat.num_contacts() == 2
51 changes: 0 additions & 51 deletions python/tests/test_0_complex_or_slow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import time

import deltachat as dc
Expand Down Expand Up @@ -63,56 +62,6 @@ def test_group_many_members_add_leave_remove(self, acfactory, lp):
# Message should be encrypted because keys of other members are gossiped
assert msg.is_encrypted()

def test_synchronize_member_list_on_group_rejoin(self, acfactory, lp):
"""
Test that user recreates group member list when it joins the group again.
ac1 creates a group with two other accounts: ac2 and ac3
Then it removes ac2, removes ac3 and adds ac2 back.
ac2 did not see that ac3 is removed, so it should rebuild member list from scratch.
"""
lp.sec("setting up accounts, accepted with each other")
accounts = acfactory.get_online_accounts(3)
acfactory.introduce_each_other(accounts)
ac1, ac2, ac3 = accounts

lp.sec("ac1: creating group chat with 2 other members")
chat = ac1.create_group_chat("title1", contacts=[ac2, ac3])
assert not chat.is_promoted()

lp.sec("ac1: send message to new group chat")
msg = chat.send_text("hello")
assert chat.is_promoted() and msg.is_encrypted()

assert chat.num_contacts() == 3

lp.sec("checking that the chat arrived correctly")
for ac in accounts[1:]:
msg = ac._evtracker.wait_next_incoming_message()
assert msg.text == "hello"
print("chat is", msg.chat)
assert msg.chat.num_contacts() == 3

lp.sec("ac1: removing ac2")
chat.remove_contact(ac2)

lp.sec("ac2: wait for a message about removal from the chat")
msg = ac2._evtracker.wait_next_incoming_message()

lp.sec("ac1: removing ac3")
chat.remove_contact(ac3)

lp.sec("ac1: adding ac2 back")
# Group is promoted, message is sent automatically
assert chat.is_promoted()
chat.add_contact(ac2)

lp.sec("ac2: check that ac3 is removed")
msg = ac2._evtracker.wait_next_incoming_message()

assert chat.num_contacts() == 2
assert msg.chat.num_contacts() == 2
acfactory.dump_imap_summary(sys.stdout)


def test_qr_verified_group_and_chatting(acfactory, lp):
ac1, ac2, ac3 = acfactory.get_online_accounts(3)
Expand Down