diff --git a/app/src/main/java/io/github/chronosx88/influence/helpers/ObservableUtils.java b/app/src/main/java/io/github/chronosx88/influence/helpers/ObservableUtils.java index b3e0466..c2ef9ab 100644 --- a/app/src/main/java/io/github/chronosx88/influence/helpers/ObservableUtils.java +++ b/app/src/main/java/io/github/chronosx88/influence/helpers/ObservableUtils.java @@ -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); } diff --git a/app/src/main/java/io/github/chronosx88/influence/logic/ChatLogic.java b/app/src/main/java/io/github/chronosx88/influence/logic/ChatLogic.java index 4ccb7d3..687fcb8 100644 --- a/app/src/main/java/io/github/chronosx88/influence/logic/ChatLogic.java +++ b/app/src/main/java/io/github/chronosx88/influence/logic/ChatLogic.java @@ -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: { diff --git a/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.java b/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.java index 3d00d6a..9cd991c 100644 --- a/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.java +++ b/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.java @@ -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); } }