Fixed threading issue when receiving unread messages

This commit is contained in:
2020-02-08 11:43:02 +01:00
parent f76d0cdeb4
commit e6c4139b4d
2 changed files with 14 additions and 18 deletions

View File

@ -106,11 +106,11 @@ public class Startup {
// Acquire the client user (with ID) either from the server or from the local
// database, which triggers offline mode
Client client = new Client();
Cache<Message> cache = null;
Cache<Message> cache = new Cache<>();
try {
// Try entering online mode first
localDb.loadIdGenerator();
cache = client.onlineInit(credentials, localDb);
client.onlineInit(credentials, localDb, cache);
} catch (Exception e1) {
logger.warning("Could not connect to server. Trying offline mode...");
e1.printStackTrace();
@ -162,6 +162,9 @@ public class Startup {
try {
chatWindow.initContent(client, localDb, writeProxy);
// Relay unread messages from cache
if (cache != null) cache.relay();
try {
new StatusTrayIcon(chatWindow).show();
@ -180,9 +183,6 @@ public class Startup {
}
});
// Relay unread messages from cache
if (cache != null) cache.relay();
// Save Settings and PersistentLocalDb on shutdown
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {