Clear unidentified access mode when profile key changes.
parent
455974cb05
commit
23e55ac5f7
|
@ -799,25 +799,30 @@ public class RecipientDatabase extends Database {
|
|||
/**
|
||||
* Updates the profile key.
|
||||
* <p>
|
||||
* If it changes, it clears out the profile key credential.
|
||||
* If it changes, it clears out the profile key credential and resets the unidentified access mode.
|
||||
* @return true iff changed.
|
||||
*/
|
||||
public void setProfileKey(@NonNull RecipientId id, @Nullable ProfileKey profileKey) {
|
||||
public boolean setProfileKey(@NonNull RecipientId id, @NonNull ProfileKey profileKey) {
|
||||
String selection = ID + " = ?";
|
||||
String[] args = new String[]{id.serialize()};
|
||||
ContentValues valuesToCompare = new ContentValues(1);
|
||||
ContentValues valuesToSet = new ContentValues(2);
|
||||
String encodedProfileKey = profileKey == null ? null : Base64.encodeBytes(profileKey.serialize());
|
||||
ContentValues valuesToSet = new ContentValues(3);
|
||||
String encodedProfileKey = Base64.encodeBytes(profileKey.serialize());
|
||||
|
||||
valuesToCompare.put(PROFILE_KEY, encodedProfileKey);
|
||||
|
||||
valuesToSet.put(PROFILE_KEY, encodedProfileKey);
|
||||
valuesToSet.putNull(PROFILE_KEY_CREDENTIAL);
|
||||
valuesToSet.put(UNIDENTIFIED_ACCESS_MODE, UnidentifiedAccessMode.UNKNOWN.getMode());
|
||||
|
||||
SqlUtil.UpdateQuery updateQuery = SqlUtil.buildTrueUpdateQuery(selection, args, valuesToCompare);
|
||||
|
||||
if (update(updateQuery, valuesToSet)) {
|
||||
markDirty(id, DirtyState.UPDATE);
|
||||
Recipient.live(id).refresh();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1180,13 +1180,14 @@ public final class PushProcessMessageJob extends BaseJob {
|
|||
{
|
||||
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
|
||||
Recipient recipient = Recipient.externalPush(context, content.getSender());
|
||||
ProfileKey currentProfileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
|
||||
ProfileKey messageProfileKey = ProfileKeyUtil.profileKeyOrNull(messageProfileKeyBytes);
|
||||
|
||||
if (messageProfileKey != null && !messageProfileKey.equals(currentProfileKey)) {
|
||||
database.setProfileKey(recipient.getId(), messageProfileKey);
|
||||
database.setUnidentifiedAccessMode(recipient.getId(), RecipientDatabase.UnidentifiedAccessMode.UNKNOWN);
|
||||
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
|
||||
if (messageProfileKey != null) {
|
||||
if (database.setProfileKey(recipient.getId(), messageProfileKey)) {
|
||||
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "Ignored invalid profile key seen in message");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue