mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-21 11:38:36 +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
|
SignalStore.account().username = random
|
||||||
SignalDatabase.recipients.setUsername(Recipient.self().id, random)
|
SignalDatabase.recipients.setUsername(Recipient.self().id, random)
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange()
|
||||||
|
|
||||||
Toast.makeText(context, "Done", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "Done", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
@@ -724,6 +725,7 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
|
|||||||
entropy = Util.getSecretBytes(32),
|
entropy = Util.getSecretBytes(32),
|
||||||
serverId = SignalStore.account().usernameLink?.serverId ?: UUID.randomUUID()
|
serverId = SignalStore.account().usernameLink?.serverId ?: UUID.randomUUID()
|
||||||
)
|
)
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange()
|
||||||
Toast.makeText(context, "Done", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "Done", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
|
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
|
||||||
|
|||||||
@@ -206,9 +206,11 @@ object ContactDiscoveryRefreshV2 {
|
|||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private fun Set<RecipientId>.removePossiblyRegisteredButUnlisted(): Set<RecipientId> {
|
private fun Set<RecipientId>.removePossiblyRegisteredButUnlisted(): Set<RecipientId> {
|
||||||
|
val selfId = Recipient.self().id
|
||||||
return this - Recipient.resolvedList(this)
|
return this - Recipient.resolvedList(this)
|
||||||
.filter { it.hasServiceId() }
|
.filter {
|
||||||
.filter { hasCommunicatedWith(it) }
|
(it.hasServiceId() && hasCommunicatedWith(it)) || it.id == selfId
|
||||||
|
}
|
||||||
.map { it.id }
|
.map { it.id }
|
||||||
.toSet()
|
.toSet()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3640,13 +3640,18 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
|||||||
* users).
|
* users).
|
||||||
*/
|
*/
|
||||||
fun rotateStorageId(recipientId: RecipientId) {
|
fun rotateStorageId(recipientId: RecipientId) {
|
||||||
|
val selfId = Recipient.self().id
|
||||||
|
|
||||||
val values = ContentValues(1).apply {
|
val values = ContentValues(1).apply {
|
||||||
put(STORAGE_SERVICE_ID, Base64.encodeWithPadding(StorageSyncHelper.generateKey()))
|
put(STORAGE_SERVICE_ID, Base64.encodeWithPadding(StorageSyncHelper.generateKey()))
|
||||||
}
|
}
|
||||||
|
|
||||||
val query = "$ID = ? AND ($TYPE IN (?, ?, ?) OR $REGISTERED = ?)"
|
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)
|
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)
|
|
||||||
|
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.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||||
import org.thoughtcrime.securesms.subscription.Subscriber;
|
import org.thoughtcrime.securesms.subscription.Subscriber;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
import org.thoughtcrime.securesms.util.ProfileUtil;
|
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!");
|
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().setUsernameSyncState(AccountValues.UsernameSyncState.LINK_CORRUPTED);
|
||||||
SignalStore.account().setUsernameLink(null);
|
SignalStore.account().setUsernameLink(null);
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Username link validated.");
|
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);
|
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().setUsernameSyncState(AccountValues.UsernameSyncState.LINK_CORRUPTED);
|
||||||
SignalStore.account().setUsernameLink(null);
|
SignalStore.account().setUsernameLink(null);
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validated) {
|
if (validated) {
|
||||||
|
|||||||
@@ -293,6 +293,9 @@ object UsernameRepository {
|
|||||||
SignalStore.account().usernameLink = null
|
SignalStore.account().usernameLink = null
|
||||||
SignalDatabase.recipients.setUsername(Recipient.self().id, reserved.username)
|
SignalDatabase.recipients.setUsername(Recipient.self().id, reserved.username)
|
||||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||||
|
|
||||||
|
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange()
|
||||||
Log.i(TAG, "[confirmUsername] Successfully confirmed username.")
|
Log.i(TAG, "[confirmUsername] Successfully confirmed username.")
|
||||||
|
|
||||||
if (tryToSetUsernameLink(username)) {
|
if (tryToSetUsernameLink(username)) {
|
||||||
@@ -322,6 +325,9 @@ object UsernameRepository {
|
|||||||
try {
|
try {
|
||||||
val linkComponents = accountManager.createUsernameLink(username)
|
val linkComponents = accountManager.createUsernameLink(username)
|
||||||
SignalStore.account().usernameLink = linkComponents
|
SignalStore.account().usernameLink = linkComponents
|
||||||
|
|
||||||
|
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange()
|
||||||
return true
|
return true
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.w(TAG, "[tryToSetUsernameLink] Failed with IOException on attempt " + (i + 1) + "/3", e)
|
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().username = null
|
||||||
SignalStore.account().usernameLink = null
|
SignalStore.account().usernameLink = null
|
||||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||||
|
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange()
|
||||||
Log.i(TAG, "[deleteUsername] Successfully deleted the username.")
|
Log.i(TAG, "[deleteUsername] Successfully deleted the username.")
|
||||||
UsernameDeleteResult.SUCCESS
|
UsernameDeleteResult.SUCCESS
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public final class StorageSyncHelper {
|
|||||||
.setStoryViewReceiptsState(storyViewReceiptsState)
|
.setStoryViewReceiptsState(storyViewReceiptsState)
|
||||||
.setHasReadOnboardingStory(hasReadOnboardingStory)
|
.setHasReadOnboardingStory(hasReadOnboardingStory)
|
||||||
.setHasSeenGroupStoryEducationSheet(SignalStore.storyValues().getUserHasSeenGroupStoryEducationSheet())
|
.setHasSeenGroupStoryEducationSheet(SignalStore.storyValues().getUserHasSeenGroupStoryEducationSheet())
|
||||||
.setUsername(self.getUsername().orElse(null));
|
.setUsername(SignalStore.account().getUsername());
|
||||||
|
|
||||||
if (!self.getPnpCapability().isSupported()) {
|
if (!self.getPnpCapability().isSupported()) {
|
||||||
account.setE164(self.requireE164());
|
account.setE164(self.requireE164());
|
||||||
@@ -211,6 +211,7 @@ public final class StorageSyncHelper {
|
|||||||
SignalStore.storyValues().setFeatureDisabled(update.getNew().isStoriesDisabled());
|
SignalStore.storyValues().setFeatureDisabled(update.getNew().isStoriesDisabled());
|
||||||
SignalStore.storyValues().setUserHasReadOnboardingStory(update.getNew().hasReadOnboardingStory());
|
SignalStore.storyValues().setUserHasReadOnboardingStory(update.getNew().hasReadOnboardingStory());
|
||||||
SignalStore.storyValues().setUserHasSeenGroupStoryEducationSheet(update.getNew().hasSeenGroupStoryEducationSheet());
|
SignalStore.storyValues().setUserHasSeenGroupStoryEducationSheet(update.getNew().hasSeenGroupStoryEducationSheet());
|
||||||
|
SignalStore.account().setUsername(update.getNew().getUsername());
|
||||||
|
|
||||||
if (update.getNew().getStoryViewReceiptsState() == OptionalBool.UNSET) {
|
if (update.getNew().getStoryViewReceiptsState() == OptionalBool.UNSET) {
|
||||||
SignalStore.storyValues().setViewedReceiptsEnabled(update.getNew().isReadReceiptsEnabled());
|
SignalStore.storyValues().setViewedReceiptsEnabled(update.getNew().isReadReceiptsEnabled());
|
||||||
|
|||||||
Reference in New Issue
Block a user