Implemented receiving unread messages using a message cache

Fixes #98
This commit is contained in:
2020-02-04 19:13:31 +01:00
parent 7e0ae2e831
commit 44541936d3
4 changed files with 84 additions and 10 deletions

View File

@ -17,6 +17,7 @@ import envoy.client.Settings;
import envoy.client.database.LocalDb;
import envoy.client.database.PersistentLocalDb;
import envoy.client.database.TransientLocalDb;
import envoy.client.net.MessageCache;
import envoy.client.util.EnvoyLog;
import envoy.data.LoginCredentials;
import envoy.data.User;
@ -106,11 +107,12 @@ 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();
Client client = new Client();
MessageCache cache = null;
try {
// Try entering online mode first
localDb.loadIdGenerator();
client.onlineInit(credentials, localDb);
cache = client.onlineInit(credentials, localDb);
} catch (Exception e1) {
logger.warning("Could not connect to server. Trying offline mode...");
e1.printStackTrace();
@ -151,6 +153,7 @@ public class Startup {
// Save all users to the local database
if (client.isOnline()) localDb.setUsers(client.getUsers());
// Display ChatWindow and StatusTrayIcon
EventQueue.invokeLater(() -> {
try {
chatWindow.setClient(client);
@ -174,6 +177,9 @@ public class Startup {
}
});
// Relay unread messages from cache
if (cache != null) cache.relayMessages();
// Save Settings and PersistentLocalDb on shutdown
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {