Fixed issue when changing username when node is offline.

This commit is contained in:
ChronosX88 2019-05-12 18:41:14 +04:00
parent 58ed8aef78
commit 8c95351b03

View File

@ -4,7 +4,9 @@ import android.util.Log
import io.github.chronosx88.influence.contracts.CoreContracts
import io.github.chronosx88.influence.helpers.AppHelper
import io.github.chronosx88.influence.helpers.KeyPairManager
import io.github.chronosx88.influence.helpers.ObservableUtils
import io.github.chronosx88.influence.helpers.P2PUtils
import io.github.chronosx88.influence.helpers.actions.UIActions
import net.tomp2p.peers.Number640
import net.tomp2p.storage.Data
import java.io.IOException
@ -12,6 +14,10 @@ import java.io.IOException
class SettingsLogic : CoreContracts.ISettingsLogic {
override fun checkUsernameExists(username: String) : Boolean {
if (AppHelper.getPeerDHT() == null) {
ObservableUtils.notifyUI(UIActions.NODE_IS_OFFLINE)
return false
}
val usernameMap: MutableMap<Number640, Data>? = P2PUtils.get(username)
usernameMap ?: return false
return true
@ -22,6 +28,10 @@ class SettingsLogic : CoreContracts.ISettingsLogic {
private val keyPairManager = KeyPairManager()
fun publishUsername(oldUsername: String?, username: String?) {
if (AppHelper.getPeerDHT() == null) {
ObservableUtils.notifyUI(UIActions.NODE_IS_OFFLINE)
return
}
val mainKeyPair = keyPairManager.openMainKeyPair()
oldUsername?.let {
if(!oldUsername.equals("")) {