Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 943feea

Browse files
committed
Using Recipients instead of Contact to sync config
1 parent 485a110 commit 943feea

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,29 @@ public List<Recipient> getBlockedContacts() {
488488
return returnList;
489489
}
490490

491+
/**
492+
* Returns a list of all recipients in the database.
493+
*
494+
* @return A list of all recipients
495+
*/
496+
public List<Recipient> getAllRecipients() {
497+
SQLiteDatabase database = databaseHelper.getReadableDatabase();
498+
499+
Cursor cursor = database.query(TABLE_NAME, new String[] {ID, ADDRESS}, null,
500+
null, null, null, null, null);
501+
502+
RecipientReader reader = new RecipientReader(context, cursor);
503+
List<Recipient> returnList = new ArrayList<>();
504+
Recipient current;
505+
506+
while ((current = reader.getNext()) != null) {
507+
returnList.add(current);
508+
}
509+
510+
reader.close();
511+
return returnList;
512+
}
513+
491514
public void setDisappearingState(@NonNull Recipient recipient, @NonNull Recipient.DisappearingState disappearingState) {
492515
ContentValues values = new ContentValues();
493516
values.put(DISAPPEARING_STATE, disappearingState.getId());

app/src/main/java/org/thoughtcrime/securesms/database/SessionContactDatabase.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
5555
val database = databaseHelper.readableDatabase
5656
return database.getAll(sessionContactTable, null, null) { cursor ->
5757
contactFromCursor(cursor)
58-
}.filter { contact ->
59-
contact.accountID.let(::AccountId).prefix == IdPrefix.STANDARD
6058
}.toSet()
6159
}
6260

app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,12 +1351,16 @@ open class Storage @Inject constructor(
13511351

13521352
// if we have contacts locally but that are missing from the config, remove their corresponding thread
13531353
val currentUserKey = getUserPublicKey()
1354-
val removedContacts = getAllContacts().filter { localContact ->
1355-
localContact.accountID != currentUserKey && // we don't want to remove ourselves (ie, our Note to Self)
1356-
moreContacts.none { it.id == localContact.accountID } // we don't want to remove contacts that are present in the config
1354+
1355+
//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
1356+
// 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
1357+
// 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.
1358+
val removedContacts = recipientDatabase.allRecipients.filter { localContact ->
1359+
localContact.address.toString() != currentUserKey && // we don't want to remove ourselves (ie, our Note to Self)
1360+
moreContacts.none { it.id == localContact.address.toString() } // we don't want to remove contacts that are present in the config
13571361
}
13581362
removedContacts.forEach {
1359-
deleteContact(it.accountID)
1363+
deleteContact(it.address.toString())
13601364
}
13611365
}
13621366

0 commit comments

Comments
 (0)