Skip to content

Commit

Permalink
feat: Sync Config::DeleteServerAfter across devices
Browse files Browse the repository at this point in the history
  • Loading branch information
iequidoo committed Aug 13, 2024
1 parent b83d5b0 commit bb421f4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions python/tests/test_0_complex_or_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,38 @@ def test_deleted_msgs_dont_reappear(acfactory):
ac1._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
time.sleep(5)
assert len(chat.get_messages()) == 0


def test_sync_delete_server_after(acfactory, tmp_path):
"""Tests that if delete_server_after is changed, the corresponding sync message isn't deleted by
another device using the previous delete_server_after value so that the sync message always has
chance to be executed on all devices.
"""
ac1 = acfactory.new_online_configuring_account(bcc_self=True, sync_msgs=True, delete_server_after=1)
ac2 = acfactory.new_online_configuring_account(cloned_from=ac1, sync_msgs=True, delete_server_after=1)
acfactory.bring_accounts_online()
dir = tmp_path / "keydir"
dir.mkdir()
ac1.export_self_keys(str(dir))
ac2.import_self_keys(str(dir))

ac2._evtracker.consume_events()
ac1.set_config("delete_server_after", "0")
try:
ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED", timeout=5)
except Exception:
pass
else:
pytest.fail("Sync message deleted by ac2")
assert ac2.get_config("delete_server_after") == "0"

# Now check that the sync message is applied correctly and the next message is deleted by the
# second device.
ac1._evtracker.consume_events()
ac1.set_config("delete_server_after", "5")
ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
ac1.set_config("displayname", "Alice")
ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
ac1.stop_io()
ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
assert ac2.get_config("delete_server_after") == "5"
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl Config {
matches!(
self,
Self::Displayname
| Self::DeleteServerAfter
| Self::MdnsEnabled
| Self::MvboxMove
| Self::ShowEmails
Expand Down Expand Up @@ -1048,6 +1049,7 @@ mod tests {
}
test_config_str(&alice0, &alice1, Config::Displayname, "Alice Sync").await?;
test_config_str(&alice0, &alice1, Config::Selfstatus, "My status").await?;
test_config_str(&alice0, &alice1, Config::DeleteServerAfter, "3600").await?;

assert!(alice0.get_config(Config::Selfavatar).await?.is_none());
let file = alice0.dir.path().join("avatar.png");
Expand Down

0 comments on commit bb421f4

Please sign in to comment.