Fix message duplicates on history load

This commit is contained in:
Arnaud Vergnet 2021-01-06 09:17:47 +01:00
parent 46cf6f40aa
commit 97c0d34159

View file

@ -87,7 +87,13 @@ public class ChatHistory {
* @param message The message to add * @param message The message to add
*/ */
public void addMessage(Message message, ErrorCallback errorCallback) { public void addMessage(Message message, ErrorCallback errorCallback) {
db.addMessage(message, () -> Platform.runLater(() -> history.add(message)), errorCallback); db.addMessage(message, () -> {
// Add message to active history only if we already fetched it from db
// This prevents duplicates when loading the db
if (historyLoaded) {
Platform.runLater(() -> history.add(message));
}
}, errorCallback);
} }
public interface HistoryLoadedCallback { public interface HistoryLoadedCallback {