Fix possible username conflict in storage update.

This commit is contained in:
Greyson Parrelli 2023-03-24 16:32:38 -04:00
parent ba2d005b2a
commit b9b6a57e2c
2 changed files with 11 additions and 2 deletions

View file

@ -981,6 +981,14 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
}
}
if (update.new.username != null) {
writableDatabase
.update(TABLE_NAME)
.values(USERNAME to null)
.where("$USERNAME = ?", update.new.username!!)
.run()
}
val updateCount = writableDatabase.update(TABLE_NAME, values, "$STORAGE_SERVICE_ID = ?", arrayOf(Base64.encodeBytes(update.old.id.raw)))
if (updateCount < 1) {
throw AssertionError("Account update didn't match any rows!")

View file

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.signal.core.util.StringUtil;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.recipients.Recipient;
@ -121,11 +122,11 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
boolean subscriptionManuallyCancelled = remote.isSubscriptionManuallyCancelled();
boolean keepMutedChatsArchived = remote.isKeepMutedChatsArchived();
boolean hasSetMyStoriesPrivacy = remote.hasSetMyStoriesPrivacy();
boolean hasViewedOnboardingStory = remote.hasViewedOnboardingStory();
boolean hasViewedOnboardingStory = remote.hasViewedOnboardingStory() || local.hasViewedOnboardingStory();
boolean storiesDisabled = remote.isStoriesDisabled();
boolean hasReadOnboardingStory = remote.hasReadOnboardingStory() || remote.hasViewedOnboardingStory() || local.hasReadOnboardingStory() || local.hasViewedOnboardingStory() ;
boolean hasSeenGroupStoryEducation = remote.hasSeenGroupStoryEducationSheet() || local.hasSeenGroupStoryEducationSheet();
String username = remote.getUsername();
String username = !StringUtil.isEmpty(remote.getUsername()) ? remote.getUsername() : local.getUsername();
boolean matchesRemote = doParamsMatch(remote, unknownFields, givenName, familyName, avatarUrlPath, profileKey, noteToSelfArchived, noteToSelfForcedUnread, readReceipts, typingIndicators, sealedSenderIndicators, linkPreviews, phoneNumberSharingMode, unlisted, pinnedConversations, preferContactAvatars, payments, universalExpireTimer, primarySendsSms, e164, defaultReactions, subscriber, displayBadgesOnProfile, subscriptionManuallyCancelled, keepMutedChatsArchived, hasSetMyStoriesPrivacy, hasViewedOnboardingStory, storiesDisabled, storyViewReceiptsState, hasReadOnboardingStory, username);
boolean matchesLocal = doParamsMatch(local, unknownFields, givenName, familyName, avatarUrlPath, profileKey, noteToSelfArchived, noteToSelfForcedUnread, readReceipts, typingIndicators, sealedSenderIndicators, linkPreviews, phoneNumberSharingMode, unlisted, pinnedConversations, preferContactAvatars, payments, universalExpireTimer, primarySendsSms, e164, defaultReactions, subscriber, displayBadgesOnProfile, subscriptionManuallyCancelled, keepMutedChatsArchived, hasSetMyStoriesPrivacy, hasViewedOnboardingStory, storiesDisabled, storyViewReceiptsState, hasReadOnboardingStory, username);