whatsapp: commit clear_device so --whatsapp-unlink really unlinks

clear_device deleted the device rows inside an implicit transaction and never committed,
so the delete was rolled back at process exit and --whatsapp-link answered "Already
linked". Test reopens the database and checks the device is gone and contacts are kept.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 21:40:52 +01:00
co-authored by Claude Sonnet 5.5
parent bad5ea72ab
commit 69542ab933
2 changed files with 12 additions and 0 deletions
+1
View File
@@ -277,6 +277,7 @@ void WaStore::clear_device() {
db_->execute("DELETE FROM wa_appstate_version");
db_->execute("DELETE FROM wa_appstate_mac");
db_->execute("DELETE FROM wa_appstate_keyreq");
db_->commit(); // without it the delete is rolled back when the process exits, and unlink silently does nothing
}
} // namespace detz::wa
+11
View File
@@ -647,6 +647,17 @@ static void test_contact_search() {
check(top("Nigel") != "Nigel Dokter", "contact search: removed contact is gone from the index");
WaStore reopened(home, "t");
check(reopened.search_contacts("Nina", 3, 0.3).size() >= 1, "contact search: index survives reopening the database");
// unlink must survive the process: clear_device without a commit was rolled back at exit ("Already linked")
{
WaDevice d = WaDevice::generate();
d.jid = "31612345002:5@s.whatsapp.net";
store.save_device(d);
check(store.has_device(), "a paired device is stored");
store.clear_device();
WaStore again(home, "t");
check(!again.has_device(), "clear_device persists across reopening the database");
check(again.search_contacts("Nina", 3, 0.3).size() >= 1, "clear_device keeps the contacts");
}
// send log: the floor under the rate caps
check(store.sends_since(60) == 0, "send log starts empty");
store.record_send("31612345002@s.whatsapp.net");