mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 19:18:37 +00:00
Fix storage sync issues with usernames.
This commit is contained in:
@@ -704,6 +704,7 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
|
||||
|
||||
SignalStore.account().username = random
|
||||
SignalDatabase.recipients.setUsername(Recipient.self().id, random)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
|
||||
Toast.makeText(context, "Done", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
@@ -724,6 +725,7 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
|
||||
entropy = Util.getSecretBytes(32),
|
||||
serverId = SignalStore.account().usernameLink?.serverId ?: UUID.randomUUID()
|
||||
)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
Toast.makeText(context, "Done", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
|
||||
|
||||
@@ -206,9 +206,11 @@ object ContactDiscoveryRefreshV2 {
|
||||
*/
|
||||
@WorkerThread
|
||||
private fun Set<RecipientId>.removePossiblyRegisteredButUnlisted(): Set<RecipientId> {
|
||||
val selfId = Recipient.self().id
|
||||
return this - Recipient.resolvedList(this)
|
||||
.filter { it.hasServiceId() }
|
||||
.filter { hasCommunicatedWith(it) }
|
||||
.filter {
|
||||
(it.hasServiceId() && hasCommunicatedWith(it)) || it.id == selfId
|
||||
}
|
||||
.map { it.id }
|
||||
.toSet()
|
||||
}
|
||||
|
||||
@@ -3640,13 +3640,18 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
* users).
|
||||
*/
|
||||
fun rotateStorageId(recipientId: RecipientId) {
|
||||
val selfId = Recipient.self().id
|
||||
|
||||
val values = ContentValues(1).apply {
|
||||
put(STORAGE_SERVICE_ID, Base64.encodeWithPadding(StorageSyncHelper.generateKey()))
|
||||
}
|
||||
|
||||
val query = "$ID = ? AND ($TYPE IN (?, ?, ?) OR $REGISTERED = ?)"
|
||||
val args = SqlUtil.buildArgs(recipientId, RecipientType.GV1.id, RecipientType.GV2.id, RecipientType.DISTRIBUTION_LIST.id, RegisteredState.REGISTERED.id)
|
||||
writableDatabase.update(TABLE_NAME, values, query, args)
|
||||
val query = "$ID = ? AND ($TYPE IN (?, ?, ?) OR $REGISTERED = ? OR $ID = ?)"
|
||||
val args = SqlUtil.buildArgs(recipientId, RecipientType.GV1.id, RecipientType.GV2.id, RecipientType.DISTRIBUTION_LIST.id, RegisteredState.REGISTERED.id, selfId.toLong())
|
||||
|
||||
writableDatabase.update(TABLE_NAME, values, query, args).also { updateCount ->
|
||||
Log.d(TAG, "[rotateStorageId] updateCount: $updateCount")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.keyvalue.AccountValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||
import org.thoughtcrime.securesms.subscription.Subscriber;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.ProfileUtil;
|
||||
@@ -292,6 +293,7 @@ public class RefreshOwnProfileJob extends BaseJob {
|
||||
Log.w(TAG, "The remote username decrypted ok, but the decrypted username did not match our local username!");
|
||||
SignalStore.account().setUsernameSyncState(AccountValues.UsernameSyncState.LINK_CORRUPTED);
|
||||
SignalStore.account().setUsernameLink(null);
|
||||
StorageSyncHelper.scheduleSyncForDataChange();
|
||||
} else {
|
||||
Log.d(TAG, "Username link validated.");
|
||||
}
|
||||
@@ -304,6 +306,7 @@ public class RefreshOwnProfileJob extends BaseJob {
|
||||
Log.w(TAG, "Failed to decrypt username link using the remote encrypted username and our local entropy!", e);
|
||||
SignalStore.account().setUsernameSyncState(AccountValues.UsernameSyncState.LINK_CORRUPTED);
|
||||
SignalStore.account().setUsernameLink(null);
|
||||
StorageSyncHelper.scheduleSyncForDataChange();
|
||||
}
|
||||
|
||||
if (validated) {
|
||||
|
||||
@@ -293,6 +293,9 @@ object UsernameRepository {
|
||||
SignalStore.account().usernameLink = null
|
||||
SignalDatabase.recipients.setUsername(Recipient.self().id, reserved.username)
|
||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||
|
||||
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
Log.i(TAG, "[confirmUsername] Successfully confirmed username.")
|
||||
|
||||
if (tryToSetUsernameLink(username)) {
|
||||
@@ -322,6 +325,9 @@ object UsernameRepository {
|
||||
try {
|
||||
val linkComponents = accountManager.createUsernameLink(username)
|
||||
SignalStore.account().usernameLink = linkComponents
|
||||
|
||||
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
return true
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, "[tryToSetUsernameLink] Failed with IOException on attempt " + (i + 1) + "/3", e)
|
||||
@@ -339,6 +345,8 @@ object UsernameRepository {
|
||||
SignalStore.account().username = null
|
||||
SignalStore.account().usernameLink = null
|
||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
Log.i(TAG, "[deleteUsername] Successfully deleted the username.")
|
||||
UsernameDeleteResult.SUCCESS
|
||||
} catch (e: IOException) {
|
||||
|
||||
@@ -166,7 +166,7 @@ public final class StorageSyncHelper {
|
||||
.setStoryViewReceiptsState(storyViewReceiptsState)
|
||||
.setHasReadOnboardingStory(hasReadOnboardingStory)
|
||||
.setHasSeenGroupStoryEducationSheet(SignalStore.storyValues().getUserHasSeenGroupStoryEducationSheet())
|
||||
.setUsername(self.getUsername().orElse(null));
|
||||
.setUsername(SignalStore.account().getUsername());
|
||||
|
||||
if (!self.getPnpCapability().isSupported()) {
|
||||
account.setE164(self.requireE164());
|
||||
@@ -211,6 +211,7 @@ public final class StorageSyncHelper {
|
||||
SignalStore.storyValues().setFeatureDisabled(update.getNew().isStoriesDisabled());
|
||||
SignalStore.storyValues().setUserHasReadOnboardingStory(update.getNew().hasReadOnboardingStory());
|
||||
SignalStore.storyValues().setUserHasSeenGroupStoryEducationSheet(update.getNew().hasSeenGroupStoryEducationSheet());
|
||||
SignalStore.account().setUsername(update.getNew().getUsername());
|
||||
|
||||
if (update.getNew().getStoryViewReceiptsState() == OptionalBool.UNSET) {
|
||||
SignalStore.storyValues().setViewedReceiptsEnabled(update.getNew().isReadReceiptsEnabled());
|
||||
|
||||
Reference in New Issue
Block a user