mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-22 07:12:19 +00:00
Fixed crash when node is offline
This commit is contained in:
parent
8a960b0b15
commit
df0d48f291
@ -11,4 +11,5 @@ public class UIActions {
|
|||||||
public static final int PEER_NOT_EXIST = 0x7;
|
public static final int PEER_NOT_EXIST = 0x7;
|
||||||
public static final int SUCCESSFUL_CREATE_CHAT = 0x8;
|
public static final int SUCCESSFUL_CREATE_CHAT = 0x8;
|
||||||
public static final int MESSAGE_RECEIVED = 0x9;
|
public static final int MESSAGE_RECEIVED = 0x9;
|
||||||
|
public static final int NODE_IS_OFFLINE = 0x10;
|
||||||
}
|
}
|
||||||
|
@ -46,12 +46,18 @@ public class ChatLogic implements IChatLogicContract {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.timer = new Timer();
|
this.timer = new Timer();
|
||||||
timer.schedule(timerTask, 1, 1000);
|
if(AppHelper.getPeerDHT() != null) {
|
||||||
|
timer.schedule(timerTask, 1, 1000);
|
||||||
|
}
|
||||||
this.keyPairManager = new KeyPairManager();
|
this.keyPairManager = new KeyPairManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(MessageEntity message) {
|
public void sendMessage(MessageEntity message) {
|
||||||
|
if(AppHelper.getPeerDHT() == null) {
|
||||||
|
ObservableUtils.notifyUI(UIActions.NODE_IS_OFFLINE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
Data data = null;
|
Data data = null;
|
||||||
try {
|
try {
|
||||||
|
@ -249,8 +249,7 @@ public class MainLogic implements IMainLogicContract {
|
|||||||
Data serializedUserProfile = null;
|
Data serializedUserProfile = null;
|
||||||
try {
|
try {
|
||||||
serializedUserProfile = new Data(gson.toJson(userProfile))
|
serializedUserProfile = new Data(gson.toJson(userProfile))
|
||||||
.protectEntry(mainKeyPair.getPrivate())
|
.protectEntry(mainKeyPair.getPrivate());
|
||||||
.sign(keyPairManager.getKeyPair("mainSigningKeyPair"));
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,11 @@ public class StartChatLogic implements IStartChatLogicContract {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendStartChatMessage(String peerID) {
|
public void sendStartChatMessage(String peerID) {
|
||||||
|
if(peerDHT == null) {
|
||||||
|
ObservableUtils.notifyUI(UIActions.NODE_IS_OFFLINE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
PublicUserProfile recipientPublicProfile = getPublicProfile(peerID);
|
PublicUserProfile recipientPublicProfile = getPublicProfile(peerID);
|
||||||
if(recipientPublicProfile == null) {
|
if(recipientPublicProfile == null) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.chronosx88.influence.presenters;
|
package io.github.chronosx88.influence.presenters;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@ -54,6 +56,12 @@ public class ChatPresenter implements IChatPresenterContract, IObserver {
|
|||||||
}
|
}
|
||||||
MessageEntity messageEntity = LocalDBWrapper.getMessageByID(jsonArray.get(1).getAsString());
|
MessageEntity messageEntity = LocalDBWrapper.getMessageByID(jsonArray.get(1).getAsString());
|
||||||
view.updateMessageList(messageEntity);
|
view.updateMessageList(messageEntity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case UIActions.NODE_IS_OFFLINE: {
|
||||||
|
Toast.makeText(AppHelper.getContext(), "Нода не запущена!", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,12 @@ public class StartChatPresenter implements IStartChatPresenterContract, IObserve
|
|||||||
view.showMessage("Чат успешно создан!");
|
view.showMessage("Чат успешно создан!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case UIActions.NODE_IS_OFFLINE: {
|
||||||
|
view.showProgressDialog(false);
|
||||||
|
view.showMessage("Нода не запущена!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user