Skip to content
Snippets Groups Projects
Commit 13725103 authored by Julian Hochstetter's avatar Julian Hochstetter
Browse files

Task #3851: send feedback to a list of users

parent d29c3da0
Branches
Tags
No related merge requests found
...@@ -3,27 +3,24 @@ package de.thm.arsnova.socket; ...@@ -3,27 +3,24 @@ package de.thm.arsnova.socket;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang.NotImplementedException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required; import org.springframework.beans.factory.annotation.Required;
import com.corundumstudio.socketio.AckCallback;
import com.corundumstudio.socketio.ClientOperations;
import com.corundumstudio.socketio.Configuration; import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOClient; import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer; import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.ConnectListener; import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.listener.DataListener; import com.corundumstudio.socketio.listener.DataListener;
import com.corundumstudio.socketio.listener.DisconnectListener; import com.corundumstudio.socketio.listener.DisconnectListener;
import com.corundumstudio.socketio.parser.Packet;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import de.thm.arsnova.services.ISessionService; import de.thm.arsnova.services.ISessionService;
...@@ -36,7 +33,7 @@ public class ARSnovaSocketIOServer { ...@@ -36,7 +33,7 @@ public class ARSnovaSocketIOServer {
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<UUID, User> socketid2user = new ConcurrentHashMap<UUID, User>(); private final ConcurrentHashMap<UUID, User> socketid2user = new ConcurrentHashMap<UUID, User>();
private int portNumber; private int portNumber;
private boolean useSSL = false; private boolean useSSL = false;
...@@ -170,28 +167,27 @@ public class ARSnovaSocketIOServer { ...@@ -170,28 +167,27 @@ public class ARSnovaSocketIOServer {
} }
public void reportDeletedFeedback(String username, Set<String> arsSessions) { public void reportDeletedFeedback(String username, Set<String> arsSessions) {
UUID connectionId = findConnectionIdForUser(username); List<UUID> connectionIds = findConnectionIdForUser(username);
if (connectionId == null) { if (connectionIds.isEmpty()) {
return; return;
} }
for (SocketIOClient client : server.getAllClients()) { for (SocketIOClient client : server.getAllClients()) {
// Find the client whose feedback has been deleted and send a message. // Find the client whose feedback has been deleted and send a message.
if (client.getSessionId().compareTo(connectionId) == 0) { if(connectionIds.contains(client.getSessionId())) {
client.sendEvent("removedFeedback", arsSessions); client.sendEvent("removedFeedback", arsSessions);
break;
} }
} }
} }
private UUID findConnectionIdForUser(String username) { private List<UUID> findConnectionIdForUser(String username) {
for (Map.Entry<UUID, User> e : socketid2user.entrySet()) { List<UUID> result = new ArrayList<UUID>();
User u = e.getValue(); for (Entry<UUID, User> e : socketid2user.entrySet()) {
if (u.getUsername().equals(username)) { if (e.getValue().getUsername().equals(username)) {
return e.getKey(); result.add(e.getKey());
} }
} }
return null; return result;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment