mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 11:18:35 +00:00
Clear unidentified access mode when profile key changes.
This commit is contained in:
parent
455974cb05
commit
23e55ac5f7
@ -799,25 +799,30 @@ public class RecipientDatabase extends Database {
|
|||||||
/**
|
/**
|
||||||
* Updates the profile key.
|
* Updates the profile key.
|
||||||
* <p>
|
* <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 selection = ID + " = ?";
|
||||||
String[] args = new String[]{id.serialize()};
|
String[] args = new String[]{id.serialize()};
|
||||||
ContentValues valuesToCompare = new ContentValues(1);
|
ContentValues valuesToCompare = new ContentValues(1);
|
||||||
ContentValues valuesToSet = new ContentValues(2);
|
ContentValues valuesToSet = new ContentValues(3);
|
||||||
String encodedProfileKey = profileKey == null ? null : Base64.encodeBytes(profileKey.serialize());
|
String encodedProfileKey = Base64.encodeBytes(profileKey.serialize());
|
||||||
|
|
||||||
valuesToCompare.put(PROFILE_KEY, encodedProfileKey);
|
valuesToCompare.put(PROFILE_KEY, encodedProfileKey);
|
||||||
|
|
||||||
valuesToSet.put(PROFILE_KEY, encodedProfileKey);
|
valuesToSet.put(PROFILE_KEY, encodedProfileKey);
|
||||||
valuesToSet.putNull(PROFILE_KEY_CREDENTIAL);
|
valuesToSet.putNull(PROFILE_KEY_CREDENTIAL);
|
||||||
|
valuesToSet.put(UNIDENTIFIED_ACCESS_MODE, UnidentifiedAccessMode.UNKNOWN.getMode());
|
||||||
|
|
||||||
SqlUtil.UpdateQuery updateQuery = SqlUtil.buildTrueUpdateQuery(selection, args, valuesToCompare);
|
SqlUtil.UpdateQuery updateQuery = SqlUtil.buildTrueUpdateQuery(selection, args, valuesToCompare);
|
||||||
|
|
||||||
if (update(updateQuery, valuesToSet)) {
|
if (update(updateQuery, valuesToSet)) {
|
||||||
markDirty(id, DirtyState.UPDATE);
|
markDirty(id, DirtyState.UPDATE);
|
||||||
Recipient.live(id).refresh();
|
Recipient.live(id).refresh();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1180,14 +1180,15 @@ public final class PushProcessMessageJob extends BaseJob {
|
|||||||
{
|
{
|
||||||
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
|
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
|
||||||
Recipient recipient = Recipient.externalPush(context, content.getSender());
|
Recipient recipient = Recipient.externalPush(context, content.getSender());
|
||||||
ProfileKey currentProfileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
|
|
||||||
ProfileKey messageProfileKey = ProfileKeyUtil.profileKeyOrNull(messageProfileKeyBytes);
|
ProfileKey messageProfileKey = ProfileKeyUtil.profileKeyOrNull(messageProfileKeyBytes);
|
||||||
|
|
||||||
if (messageProfileKey != null && !messageProfileKey.equals(currentProfileKey)) {
|
if (messageProfileKey != null) {
|
||||||
database.setProfileKey(recipient.getId(), messageProfileKey);
|
if (database.setProfileKey(recipient.getId(), messageProfileKey)) {
|
||||||
database.setUnidentifiedAccessMode(recipient.getId(), RecipientDatabase.UnidentifiedAccessMode.UNKNOWN);
|
|
||||||
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
|
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Ignored invalid profile key seen in message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNeedsDeliveryReceipt(@NonNull SignalServiceContent content,
|
private void handleNeedsDeliveryReceipt(@NonNull SignalServiceContent content,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user