From 7f3b3e021cda95300b585d9fddd5f415ecb9cb4c Mon Sep 17 00:00:00 2001
From: Daniel Gerhardt <code@dgerhardt.net>
Date: Tue, 3 Feb 2015 12:18:40 +0100
Subject: [PATCH] Fix session leaving

A NotFoundException was mistakenly thrown when the Session was set to
null via Socket.IO. Additionally, the user count was sent before it
had been updated.
---
 src/main/java/de/thm/arsnova/services/SessionService.java   | 2 +-
 .../java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java   | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java
index e77c2b90..bf43823c 100644
--- a/src/main/java/de/thm/arsnova/services/SessionService.java
+++ b/src/main/java/de/thm/arsnova/services/SessionService.java
@@ -111,7 +111,7 @@ public class SessionService implements ISessionService {
 	public final Session joinSession(final String keyword, final UUID socketId) {
 		/* Socket.IO solution */
 
-		Session session = databaseDao.getSessionFromKeyword(keyword);
+		Session session = null != keyword ? databaseDao.getSessionFromKeyword(keyword) : null;
 
 		if (null == session) {
 			userService.removeUserFromSessionBySocketId(socketId);
diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java
index c925e80d..2cb748b7 100644
--- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java
+++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java
@@ -157,9 +157,6 @@ public class ARSnovaSocketIOServer implements ApplicationListener<NovaEvent>, No
 				if (session.getKeyword() == oldSessionKey) {
 					return;
 				}
-				if (null != oldSessionKey) {
-					reportActiveUserCountForSession(oldSessionKey);
-				}
 
 				if (null != sessionService.joinSession(session.getKeyword(), client.getSessionId())) {
 					/* active user count has to be sent to the client since the broadcast is
@@ -167,6 +164,9 @@ public class ARSnovaSocketIOServer implements ApplicationListener<NovaEvent>, No
 					reportActiveUserCountForSession(session.getKeyword());
 					reportSessionDataToClient(session.getKeyword(), u, client);
 				}
+				if (null != oldSessionKey) {
+					reportActiveUserCountForSession(oldSessionKey);
+				}
 			}
 		});
 
-- 
GitLab