Fix Bug resetting user status on login
This commit is contained in:
		@@ -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()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user