Check for network connectivity before making any substantial username alteration request.
This commit is contained in:
parent
7e00d50078
commit
ce9a8f62d4
2 changed files with 22 additions and 0 deletions
|
@ -14,9 +14,11 @@ import io.reactivex.rxjava3.subjects.PublishSubject
|
|||
import org.signal.core.util.Result
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.libsignal.usernames.Username
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.profiles.manage.UsernameRepository.UsernameDeleteResult
|
||||
import org.thoughtcrime.securesms.profiles.manage.UsernameRepository.UsernameSetResult
|
||||
import org.thoughtcrime.securesms.util.NetworkUtil
|
||||
import org.thoughtcrime.securesms.util.UsernameUtil.InvalidReason
|
||||
import org.thoughtcrime.securesms.util.UsernameUtil.checkDiscriminator
|
||||
import org.thoughtcrime.securesms.util.UsernameUtil.checkUsername
|
||||
|
@ -123,6 +125,11 @@ internal class UsernameEditViewModel private constructor(private val isInRegistr
|
|||
}
|
||||
|
||||
fun onUsernameSubmitted() {
|
||||
if (!NetworkUtil.isConnected(ApplicationDependencies.getApplication())) {
|
||||
events.onNext(Event.NETWORK_FAILURE)
|
||||
return
|
||||
}
|
||||
|
||||
val editState = stateMachineStore.state
|
||||
val usernameState = uiState.state.usernameState
|
||||
val isCaseChange = isCaseChange(editState)
|
||||
|
|
|
@ -389,6 +389,11 @@ object UsernameRepository {
|
|||
private fun updateUsernameDisplayForCurrentLinkInternal(updatedUsername: Username): UsernameSetResult {
|
||||
Log.i(TAG, "[updateUsernameDisplayForCurrentLink] Beginning username update...")
|
||||
|
||||
if (!NetworkUtil.isConnected(ApplicationDependencies.getApplication())) {
|
||||
Log.w(TAG, "[deleteUsernameInternal] No network connection! Not attempting the request.")
|
||||
return UsernameSetResult.NETWORK_ERROR
|
||||
}
|
||||
|
||||
return try {
|
||||
val oldUsernameLink = SignalStore.account().usernameLink ?: return UsernameSetResult.USERNAME_INVALID
|
||||
val newUsernameLink = updatedUsername.generateLink(oldUsernameLink.entropy)
|
||||
|
@ -415,6 +420,11 @@ object UsernameRepository {
|
|||
private fun confirmUsernameAndCreateNewLinkInternal(username: Username): UsernameSetResult {
|
||||
Log.i(TAG, "[confirmUsernameAndCreateNewLink] Beginning username confirmation...")
|
||||
|
||||
if (!NetworkUtil.isConnected(ApplicationDependencies.getApplication())) {
|
||||
Log.w(TAG, "[confirmUsernameAndCreateNewLink] No network connection! Not attempting the request.")
|
||||
return UsernameSetResult.NETWORK_ERROR
|
||||
}
|
||||
|
||||
return try {
|
||||
val linkComponents: UsernameLinkComponents = accountManager.confirmUsernameAndCreateNewLink(username)
|
||||
|
||||
|
@ -446,6 +456,11 @@ object UsernameRepository {
|
|||
|
||||
@WorkerThread
|
||||
private fun deleteUsernameInternal(): UsernameDeleteResult {
|
||||
if (!NetworkUtil.isConnected(ApplicationDependencies.getApplication())) {
|
||||
Log.w(TAG, "[deleteUsernameInternal] No network connection! Not attempting the request.")
|
||||
return UsernameDeleteResult.NETWORK_ERROR
|
||||
}
|
||||
|
||||
return try {
|
||||
accountManager.deleteUsername()
|
||||
SignalDatabase.recipients.setUsername(Recipient.self().id, null)
|
||||
|
|
Loading…
Add table
Reference in a new issue