Skip to content

SES-3674 - Contact deletion sync #1080

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

Merged
merged 1 commit into from
Apr 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,29 @@ public List<Recipient> getBlockedContacts() {
return returnList;
}

/**
* Returns a list of all recipients in the database.
*
* @return A list of all recipients
*/
public List<Recipient> getAllRecipients() {
SQLiteDatabase database = databaseHelper.getReadableDatabase();

Cursor cursor = database.query(TABLE_NAME, new String[] {ID, ADDRESS}, null,
null, null, null, null, null);

RecipientReader reader = new RecipientReader(context, cursor);
List<Recipient> returnList = new ArrayList<>();
Recipient current;

while ((current = reader.getNext()) != null) {
returnList.add(current);
}

reader.close();
return returnList;
}

public void setDisappearingState(@NonNull Recipient recipient, @NonNull Recipient.DisappearingState disappearingState) {
ContentValues values = new ContentValues();
values.put(DISAPPEARING_STATE, disappearingState.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
val database = databaseHelper.readableDatabase
return database.getAll(sessionContactTable, null, null) { cursor ->
contactFromCursor(cursor)
}.filter { contact ->
contact.accountID.let(::AccountId).prefix == IdPrefix.STANDARD
}.toSet()
}

Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1351,12 +1351,16 @@ open class Storage @Inject constructor(

// if we have contacts locally but that are missing from the config, remove their corresponding thread
val currentUserKey = getUserPublicKey()
val removedContacts = getAllContacts().filter { localContact ->
localContact.accountID != currentUserKey && // we don't want to remove ourselves (ie, our Note to Self)
moreContacts.none { it.id == localContact.accountID } // we don't want to remove contacts that are present in the config

//NOTE: I used to cycle through all Contact here instead or all Recipients, but turns out a Contact isn't saved until we have a name, nickname or avatar
// which in the case of contacts we are messaging for the first time and who haven't yet approved us, it won't be the case
// But that person is saved in the Recipient db. We might need to investigate how to clean the relationship between Recipients, Contacts and config Contacts.
val removedContacts = recipientDatabase.allRecipients.filter { localContact ->
localContact.address.toString() != currentUserKey && // we don't want to remove ourselves (ie, our Note to Self)
moreContacts.none { it.id == localContact.address.toString() } // we don't want to remove contacts that are present in the config
}
removedContacts.forEach {
deleteContact(it.accountID)
deleteContact(it.address.toString())
}
}

Expand Down