mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-21 23:02:18 +00:00
Now messages will not interfere between chats.
This commit is contained in:
parent
a0d50a3d1c
commit
74dabd3564
@ -1,5 +1,6 @@
|
||||
package io.github.chronosx88.influence.helpers;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ObservableUtils {
|
||||
@ -9,10 +10,14 @@ public class ObservableUtils {
|
||||
AppHelper.getObservable().notifyUIObservers(jsonObject);
|
||||
}
|
||||
|
||||
public static void notifyUI(int action, String additional) {
|
||||
public static void notifyUI(int action, String... additional) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("action", action);
|
||||
jsonObject.addProperty("additional", additional);
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for(String info : additional) {
|
||||
jsonArray.add(info);
|
||||
}
|
||||
jsonObject.add("additional", jsonArray);
|
||||
AppHelper.getObservable().notifyUIObservers(jsonObject);
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ public class ChatLogic implements IChatLogicContract {
|
||||
case NetworkActions.JOIN_CHAT: {
|
||||
JoinChatMessage joinChatMessage = gson.fromJson(json, JoinChatMessage.class);
|
||||
LocalDBWrapper.createMessageEntry(NetworkActions.JOIN_CHAT, joinChatMessage.getMessageID(), joinChatMessage.getChatID(), joinChatMessage.getUsername(), joinChatMessage.getSenderID(), joinChatMessage.getTimestamp(), null, true, false);
|
||||
ObservableUtils.notifyUI(UIActions.MESSAGE_RECEIVED, joinChatMessage.getMessageID());
|
||||
ObservableUtils.notifyUI(UIActions.MESSAGE_RECEIVED, chatID, joinChatMessage.getMessageID());
|
||||
break;
|
||||
}
|
||||
case NetworkActions.NEXT_CHUNK_REF: {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.chronosx88.influence.presenters;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -47,7 +48,11 @@ public class ChatPresenter implements IChatPresenterContract, IObserver {
|
||||
public void handleEvent(JsonObject object) {
|
||||
switch (object.get("action").getAsInt()) {
|
||||
case UIActions.MESSAGE_RECEIVED: {
|
||||
MessageEntity messageEntity = LocalDBWrapper.getMessageByID(object.get("additional").getAsString());
|
||||
JsonArray jsonArray = object.getAsJsonArray("additional");
|
||||
if(!jsonArray.get(0).getAsString().equals(chatID)) {
|
||||
return;
|
||||
}
|
||||
MessageEntity messageEntity = LocalDBWrapper.getMessageByID(jsonArray.get(1).getAsString());
|
||||
view.updateMessageList(messageEntity);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user