diff --git a/src/main/java/org/myrobotlab/programab/Session.java b/src/main/java/org/myrobotlab/programab/Session.java index a76fb94bec..d7205ba2e4 100644 --- a/src/main/java/org/myrobotlab/programab/Session.java +++ b/src/main/java/org/myrobotlab/programab/Session.java @@ -95,7 +95,7 @@ private synchronized Chat getChat() { return chat; } - public void savePredicates() { + synchronized public void savePredicates() { StringBuilder sb = new StringBuilder(); TreeSet sort = new TreeSet<>(); sort.addAll(getChat().predicates.keySet()); @@ -122,7 +122,7 @@ public void savePredicates() { * Get all current predicate names and values * @return */ - public Map getPredicates() { + synchronized public Map getPredicates() { TreeMap sort = new TreeMap<>(); // copy keys, making this sort thread safe Set keys = new HashSet(getChat().predicates.keySet()); diff --git a/src/main/java/org/myrobotlab/service/ProgramAB.java b/src/main/java/org/myrobotlab/service/ProgramAB.java index c32a0ab437..4d8b547004 100644 --- a/src/main/java/org/myrobotlab/service/ProgramAB.java +++ b/src/main/java/org/myrobotlab/service/ProgramAB.java @@ -271,8 +271,15 @@ public Response getResponse(String userName, String botName, String text, boolea // update the current session if we want to change which bot is at // attention. if (updateCurrentSession) { + + boolean sessionChanged = (!userName.equals(config.currentUserName) || !botName.equals(config.currentBotName)); + setCurrentUserName(userName); setCurrentBotName(botName); + + if (sessionChanged) { + invoke("publishSession", getSessionKey(userName, botName)); + } } // Get the actual bots aiml based response for this session