Fix Bug resetting user status on login

This commit is contained in:
Leon Hofmeister 2020-10-09 18:23:00 +02:00
parent 1d191858fe
commit fa2a5d0b24
Signed by: delvh
GPG Key ID: 3DECE05F6D9A647C

View File

@ -113,9 +113,13 @@ public final class Startup extends Application {
cacheMap.put(GroupMessage.class, new Cache<GroupMessage>()); cacheMap.put(GroupMessage.class, new Cache<GroupMessage>());
cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>()); cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>());
cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>()); cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>());
final var originalStatus = localDB.getUser().getStatus();
try { try {
client.performHandshake(credentials, cacheMap); client.performHandshake(credentials, cacheMap);
if (client.isOnline()) { if (client.isOnline()) {
// Restore the original status as the server automatically returns status ONLINE
client.getSender().setStatus(originalStatus);
loadChatScene(); loadChatScene();
client.initReceiver(localDB, cacheMap); client.initReceiver(localDB, cacheMap);
return true; return true;
@ -170,7 +174,8 @@ public final class Startup extends Application {
private static void loadChatScene() { private static void loadChatScene() {
// Set client user in local database // Set client user in local database
localDB.setUser(client.getSender()); final var user = client.getSender();
localDB.setUser(user);
// Initialize chats in local database // Initialize chats in local database
try { try {
@ -184,8 +189,13 @@ public final class Startup extends Application {
context.initWriteProxy(); context.initWriteProxy();
if (client.isOnline()) context.getWriteProxy().flushCache(); if (client.isOnline()) {
else context.getWriteProxy().flushCache();
// Inform the server that this user has a different user status than expected
if (!user.getStatus().equals(UserStatus.ONLINE)) client.send(new UserStatusChange(user));
} else
// Set all contacts to offline mode // Set all contacts to offline mode
localDB.getChats() localDB.getChats()
.stream() .stream()