@@ -0,0 +1,2047 @@
+package no.dusken.momus.controller;%0A%0Aimport no.dusken.momus.model.Person;%0Aimport no.dusken.momus.service.repository.PersonRepository;%0Aimport org.springframework.context.event.EventListener;%0Aimport org.springframework.data.util.Pair;%0Aimport org.springframework.messaging.simp.user.SimpUserRegistry;%0Aimport org.springframework.web.bind.annotation.*;%0Aimport org.springframework.web.socket.messaging.SessionDisconnectEvent;%0A%0Aimport java.security.Principal;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors;%0A%0A@RestController%0Apublic class WebSocketController %7B%0A%0A    private final SimpUserRegistry userRegistry;%0A%0A    private final Map%3CString, Pair%3CPerson, String%3E%3E sessionStates;%0A%0A    private final PersonRepository personRepository;%0A%0A    public WebSocketController(SimpUserRegistry userRegistry, PersonRepository personRepository) %7B%0A        this.personRepository = personRepository;%0A        this.userRegistry = userRegistry;%0A        sessionStates = new HashMap%3C%3E();%0A    %7D%0A%0A    @GetMapping(%22/users%22)%0A    public @ResponseBody Set%3CPerson%3E getLoggedInUsers(@RequestParam String state) %7B%0A        return userRegistry.findSubscriptions(sub -%3E true)%0A                .stream()%0A                .filter(s -%3E sessionStates.get(s.getSession().getId()).getSecond().equals(state))%0A                .map(s -%3E sessionStates.get(s.getSession().getId()).getFirst())%0A                .collect(Collectors.toSet());%0A    %7D%0A%0A    @PutMapping(%22/users/%7Bsessid%7D%22)%0A    public void setMyState(@PathVariable(%22sessid%22) String sessid, @RequestParam String state, Principal principal) %7B%0A        if(sessionStates.containsKey(sessid)) %7B%0A            sessionStates.put(sessid, Pair.of(sessionStates.get(sessid).getFirst(), state));%0A        %7Delse %7B%0A            sessionStates.put(sessid, Pair.of(personRepository.findByUsername(principal.getName()), state));%0A        %7D%0A    %7D%0A%0A    @EventListener%0A    public void handleSessionEnd(SessionDisconnectEvent disconnectEvent) %7B%0A        sessionStates.remove(disconnectEvent.getSessionId());%0A    %7D%0A%7D

Add websocket controller with user state