mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Update username consistency error handling.
This commit is contained in:
@@ -157,6 +157,6 @@ public class EditSelfProfileRepository implements EditProfileRepository {
|
||||
|
||||
@Override
|
||||
public void getCurrentUsername(@NonNull Consumer<Optional<String>> callback) {
|
||||
callback.accept(Recipient.self().getUsername());
|
||||
callback.accept(Optional.ofNullable(SignalStore.account().getUsername()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.badges.models.Badge
|
||||
import org.thoughtcrime.securesms.badges.self.none.BecomeASustainerFragment.Companion.show
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiUtil
|
||||
import org.thoughtcrime.securesms.databinding.EditProfileFragmentBinding
|
||||
import org.thoughtcrime.securesms.keyvalue.AccountValues
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.mediasend.Media
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||
@@ -41,6 +42,7 @@ import org.thoughtcrime.securesms.util.NameUtil.getAbbreviation
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil
|
||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog
|
||||
import org.thoughtcrime.securesms.util.visible
|
||||
import java.util.Arrays
|
||||
import java.util.Optional
|
||||
|
||||
@@ -131,11 +133,17 @@ class EditProfileFragment : LoggingFragment() {
|
||||
)
|
||||
}
|
||||
|
||||
if (FeatureFlags.usernames() && SignalStore.account().username != null) {
|
||||
if (FeatureFlags.usernames() && SignalStore.account().username != null && SignalStore.account().usernameSyncState != AccountValues.UsernameSyncState.USERNAME_AND_LINK_CORRUPTED) {
|
||||
binding.usernameLinkContainer.setOnClickListener {
|
||||
findNavController().safeNavigate(EditProfileFragmentDirections.actionManageProfileFragmentToUsernameLinkFragment())
|
||||
}
|
||||
|
||||
if (SignalStore.account().usernameSyncState == AccountValues.UsernameSyncState.LINK_CORRUPTED) {
|
||||
binding.linkErrorIndicator.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.linkErrorIndicator.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (SignalStore.tooltips().showProfileSettingsQrCodeTooltop()) {
|
||||
binding.usernameLinkTooltip.visibility = View.VISIBLE
|
||||
binding.linkTooltipCloseButton.setOnClickListener {
|
||||
@@ -238,6 +246,12 @@ class EditProfileFragment : LoggingFragment() {
|
||||
} else {
|
||||
binding.manageProfileUsername.text = username
|
||||
}
|
||||
|
||||
if (SignalStore.account().usernameSyncState == AccountValues.UsernameSyncState.USERNAME_AND_LINK_CORRUPTED) {
|
||||
binding.usernameErrorIndicator.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.usernameErrorIndicator.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun presentAbout(about: String?) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.badges.models.Badge;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||
@@ -163,7 +164,7 @@ class EditProfileViewModel extends ViewModel {
|
||||
|
||||
private void onRecipientChanged(@NonNull Recipient recipient) {
|
||||
profileName.postValue(recipient.getProfileName());
|
||||
username.postValue(recipient.getUsername().orElse(null));
|
||||
username.postValue(SignalStore.account().getUsername());
|
||||
about.postValue(recipient.getAbout());
|
||||
aboutEmoji.postValue(recipient.getAboutEmoji());
|
||||
badge.postValue(Optional.ofNullable(recipient.getFeaturedBadge()));
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.thoughtcrime.securesms.PassphraseRequiredActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
|
||||
import org.thoughtcrime.securesms.databinding.UsernameEditFragmentBinding;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.FragmentResultContract;
|
||||
import org.signal.core.util.concurrent.LifecycleDisposable;
|
||||
@@ -104,7 +105,9 @@ public class UsernameEditFragment extends LoggingFragment {
|
||||
binding.usernameDoneButton.setOnClickListener(v -> viewModel.onUsernameSubmitted());
|
||||
binding.usernameSkipButton.setOnClickListener(v -> viewModel.onUsernameSkipped());
|
||||
|
||||
UsernameState usernameState = Recipient.self().getUsername().<UsernameState>map(UsernameState.Set::new).orElse(UsernameState.NoUsername.INSTANCE);
|
||||
String username = SignalStore.account().getUsername();
|
||||
UsernameState usernameState = username != null ? new UsernameState.Set(username) : UsernameState.NoUsername.INSTANCE;
|
||||
|
||||
binding.usernameText.setText(usernameState.getNickname());
|
||||
binding.usernameText.addTextChangedListener(new SimpleTextWatcher() {
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.signal.libsignal.usernames.Username
|
||||
import org.thoughtcrime.securesms.components.settings.app.usernamelinks.main.UsernameLinkResetResult
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.AccountValues
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
@@ -95,6 +96,11 @@ class UsernameRepository {
|
||||
Log.d(TAG, "[createOrRotateUsernameLink] Creating username link...")
|
||||
val components = accountManager.createUsernameLink(username)
|
||||
SignalStore.account().usernameLink = components
|
||||
|
||||
if (SignalStore.account().usernameSyncState == AccountValues.UsernameSyncState.LINK_CORRUPTED) {
|
||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||
}
|
||||
|
||||
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
Log.d(TAG, "[createOrRotateUsernameLink] Username link created.")
|
||||
@@ -188,7 +194,7 @@ class UsernameRepository {
|
||||
SignalStore.account().username = username.username
|
||||
SignalStore.account().usernameLink = null
|
||||
SignalDatabase.recipients.setUsername(Recipient.self().id, reserved.username)
|
||||
SignalStore.account().usernameOutOfSync = false
|
||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||
Log.i(TAG, "[confirmUsername] Successfully confirmed username.")
|
||||
|
||||
if (tryToSetUsernameLink(username)) {
|
||||
@@ -234,7 +240,7 @@ class UsernameRepository {
|
||||
SignalDatabase.recipients.setUsername(Recipient.self().id, null)
|
||||
SignalStore.account().username = null
|
||||
SignalStore.account().usernameLink = null
|
||||
SignalStore.account().usernameOutOfSync = false
|
||||
SignalStore.account().usernameSyncState = AccountValues.UsernameSyncState.IN_SYNC
|
||||
Log.i(TAG, "[deleteUsername] Successfully deleted the username.")
|
||||
UsernameDeleteResult.SUCCESS
|
||||
} catch (e: IOException) {
|
||||
|
||||
Reference in New Issue
Block a user