Make identity record list immutable.
This commit is contained in:
parent
46f3d50a54
commit
16fdb9bf4c
3 changed files with 27 additions and 21 deletions
|
@ -355,7 +355,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||||
private boolean isMmsEnabled = true;
|
private boolean isMmsEnabled = true;
|
||||||
private boolean isSecurityInitialized = false;
|
private boolean isSecurityInitialized = false;
|
||||||
|
|
||||||
private final IdentityRecordList identityRecords = new IdentityRecordList();
|
private IdentityRecordList identityRecords = new IdentityRecordList(Collections.emptyList());
|
||||||
private final DynamicTheme dynamicTheme = new DynamicDarkToolbarTheme();
|
private final DynamicTheme dynamicTheme = new DynamicDarkToolbarTheme();
|
||||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||||
|
|
||||||
|
@ -1648,7 +1648,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
|
protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
|
||||||
Log.i(TAG, "Got identity records: " + result.first().isUnverified());
|
Log.i(TAG, "Got identity records: " + result.first().isUnverified());
|
||||||
identityRecords.replaceWith(result.first());
|
identityRecords = result.first();
|
||||||
|
|
||||||
if (result.second() != null) {
|
if (result.second() != null) {
|
||||||
Log.d(TAG, "Replacing banner...");
|
Log.d(TAG, "Replacing banner...");
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.whispersystems.libsignal.InvalidKeyException;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IdentityDatabase extends Database {
|
public class IdentityDatabase extends Database {
|
||||||
|
@ -115,9 +116,9 @@ public class IdentityDatabase extends Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull IdentityRecordList getIdentities(@NonNull List<Recipient> recipients) {
|
public @NonNull IdentityRecordList getIdentities(@NonNull List<Recipient> recipients) {
|
||||||
IdentityRecordList identityRecordList = new IdentityRecordList();
|
List<IdentityRecord> records = new LinkedList<>();
|
||||||
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||||
String[] selectionArgs = new String[1];
|
String[] selectionArgs = new String[1];
|
||||||
|
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
try {
|
try {
|
||||||
|
@ -126,7 +127,7 @@ public class IdentityDatabase extends Database {
|
||||||
|
|
||||||
try (Cursor cursor = database.query(TABLE_NAME, null, RECIPIENT_ID + " = ?", selectionArgs, null, null, null)) {
|
try (Cursor cursor = database.query(TABLE_NAME, null, RECIPIENT_ID + " = ?", selectionArgs, null, null, null)) {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
identityRecordList.add(getIdentityRecord(cursor));
|
records.add(getIdentityRecord(cursor));
|
||||||
}
|
}
|
||||||
} catch (InvalidKeyException | IOException e) {
|
} catch (InvalidKeyException | IOException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
@ -136,7 +137,7 @@ public class IdentityDatabase extends Database {
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
return identityRecordList;
|
return new IdentityRecordList(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveIdentity(@NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus,
|
public void saveIdentity(@NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus,
|
||||||
|
|
|
@ -1,30 +1,27 @@
|
||||||
package org.thoughtcrime.securesms.database.identity;
|
package org.thoughtcrime.securesms.database.identity;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
||||||
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
|
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class IdentityRecordList {
|
public final class IdentityRecordList {
|
||||||
|
|
||||||
private final List<IdentityRecord> identityRecords = new LinkedList<>();
|
private final List<IdentityRecord> identityRecords;
|
||||||
|
private final boolean isVerified;
|
||||||
|
private final boolean isUnverified;
|
||||||
|
|
||||||
public void add(@NonNull IdentityRecord identityRecord) {
|
public IdentityRecordList(@NonNull Collection<IdentityRecord> records) {
|
||||||
identityRecords.add(identityRecord);
|
identityRecords = new ArrayList<>(records);
|
||||||
}
|
isVerified = isVerified(identityRecords);
|
||||||
|
isUnverified = isUnverified(identityRecords);
|
||||||
public void replaceWith(@NonNull IdentityRecordList identityRecordList) {
|
|
||||||
identityRecords.clear();
|
|
||||||
identityRecords.addAll(identityRecordList.identityRecords);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IdentityRecord> getIdentityRecords() {
|
public List<IdentityRecord> getIdentityRecords() {
|
||||||
|
@ -32,6 +29,14 @@ public final class IdentityRecordList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVerified() {
|
public boolean isVerified() {
|
||||||
|
return isVerified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUnverified() {
|
||||||
|
return isUnverified;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isVerified(@NonNull Collection<IdentityRecord> identityRecords) {
|
||||||
for (IdentityRecord identityRecord : identityRecords) {
|
for (IdentityRecord identityRecord : identityRecords) {
|
||||||
if (identityRecord.getVerifiedStatus() != VerifiedStatus.VERIFIED) {
|
if (identityRecord.getVerifiedStatus() != VerifiedStatus.VERIFIED) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -41,7 +46,7 @@ public final class IdentityRecordList {
|
||||||
return identityRecords.size() > 0;
|
return identityRecords.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUnverified() {
|
private static boolean isUnverified(@NonNull Collection<IdentityRecord> identityRecords) {
|
||||||
for (IdentityRecord identityRecord : identityRecords) {
|
for (IdentityRecord identityRecord : identityRecords) {
|
||||||
if (identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
|
if (identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -85,7 +90,7 @@ public final class IdentityRecordList {
|
||||||
return untrusted;
|
return untrusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IdentityRecord> getUnverifiedRecords() {
|
public @NonNull List<IdentityRecord> getUnverifiedRecords() {
|
||||||
List<IdentityRecord> results = new ArrayList<>(identityRecords.size());
|
List<IdentityRecord> results = new ArrayList<>(identityRecords.size());
|
||||||
|
|
||||||
for (IdentityRecord identityRecord : identityRecords) {
|
for (IdentityRecord identityRecord : identityRecords) {
|
||||||
|
@ -97,7 +102,7 @@ public final class IdentityRecordList {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Recipient> getUnverifiedRecipients() {
|
public @NonNull List<Recipient> getUnverifiedRecipients() {
|
||||||
List<Recipient> unverified = new ArrayList<>(identityRecords.size());
|
List<Recipient> unverified = new ArrayList<>(identityRecords.size());
|
||||||
|
|
||||||
for (IdentityRecord identityRecord : identityRecords) {
|
for (IdentityRecord identityRecord : identityRecords) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue