Fixed crash when node is offline

This commit is contained in:
ChronosX88 2019-04-11 18:00:44 +04:00
parent 8a960b0b15
commit df0d48f291
6 changed files with 28 additions and 3 deletions

View File

@ -11,4 +11,5 @@ public class UIActions {
public static final int PEER_NOT_EXIST = 0x7;
public static final int SUCCESSFUL_CREATE_CHAT = 0x8;
public static final int MESSAGE_RECEIVED = 0x9;
public static final int NODE_IS_OFFLINE = 0x10;
}

View File

@ -46,12 +46,18 @@ public class ChatLogic implements IChatLogicContract {
}
};
this.timer = new Timer();
timer.schedule(timerTask, 1, 1000);
if(AppHelper.getPeerDHT() != null) {
timer.schedule(timerTask, 1, 1000);
}
this.keyPairManager = new KeyPairManager();
}
@Override
public void sendMessage(MessageEntity message) {
if(AppHelper.getPeerDHT() == null) {
ObservableUtils.notifyUI(UIActions.NODE_IS_OFFLINE);
return;
}
new Thread(() -> {
Data data = null;
try {

View File

@ -249,8 +249,7 @@ public class MainLogic implements IMainLogicContract {
Data serializedUserProfile = null;
try {
serializedUserProfile = new Data(gson.toJson(userProfile))
.protectEntry(mainKeyPair.getPrivate())
.sign(keyPairManager.getKeyPair("mainSigningKeyPair"));
.protectEntry(mainKeyPair.getPrivate());
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -38,6 +38,11 @@ public class StartChatLogic implements IStartChatLogicContract {
@Override
public void sendStartChatMessage(String peerID) {
if(peerDHT == null) {
ObservableUtils.notifyUI(UIActions.NODE_IS_OFFLINE);
return;
}
new Thread(() -> {
PublicUserProfile recipientPublicProfile = getPublicProfile(peerID);
if(recipientPublicProfile == null) {

View File

@ -1,5 +1,7 @@
package io.github.chronosx88.influence.presenters;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@ -54,6 +56,12 @@ public class ChatPresenter implements IChatPresenterContract, IObserver {
}
MessageEntity messageEntity = LocalDBWrapper.getMessageByID(jsonArray.get(1).getAsString());
view.updateMessageList(messageEntity);
break;
}
case UIActions.NODE_IS_OFFLINE: {
Toast.makeText(AppHelper.getContext(), "Нода не запущена!", Toast.LENGTH_SHORT).show();
break;
}
}
}

View File

@ -40,6 +40,12 @@ public class StartChatPresenter implements IStartChatPresenterContract, IObserve
view.showMessage("Чат успешно создан!");
break;
}
case UIActions.NODE_IS_OFFLINE: {
view.showProgressDialog(false);
view.showMessage("Нода не запущена!");
break;
}
}
}
}