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
1 changed files with 13 additions and 3 deletions

View File

@ -113,9 +113,13 @@ public final class Startup extends Application {
cacheMap.put(GroupMessage.class, new Cache<GroupMessage>());
cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>());
cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>());
final var originalStatus = localDB.getUser().getStatus();
try {
client.performHandshake(credentials, cacheMap);
if (client.isOnline()) {
// Restore the original status as the server automatically returns status ONLINE
client.getSender().setStatus(originalStatus);
loadChatScene();
client.initReceiver(localDB, cacheMap);
return true;
@ -170,7 +174,8 @@ public final class Startup extends Application {
private static void loadChatScene() {
// Set client user in local database
localDB.setUser(client.getSender());
final var user = client.getSender();
localDB.setUser(user);
// Initialize chats in local database
try {
@ -184,8 +189,13 @@ public final class Startup extends Application {
context.initWriteProxy();
if (client.isOnline()) context.getWriteProxy().flushCache();
else
if (client.isOnline()) {
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
localDB.getChats()
.stream()